Skip to content

Commit

Permalink
add support of onEditingComplete (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryleunghk authored Jan 4, 2022
1 parent 70b891a commit d040706
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3.0

* add support of onEditingComplete

## 1.2.4

* fix focus action not working sometimes
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Hope you find it useful and happy coding! 🎉🎉🎉
| `textCapitalization` | TextCapitalization | Configures how the platform keyboard will select an uppercase or lowercase keyboard (https://api.flutter.dev/flutter/material/TextField/textCapitalization.html) | TextCapitalization.none |
| `textContentType` | TextContentType | To identify the semantic meaning expected for a text-entry area (https://developer.apple.com/documentation/uikit/uitextcontenttype) | null |
| `onChanged` | ValueChanged\<String> | Called when the user initiates a change to text entry (https://api.flutter.dev/flutter/material/TextField/onChanged.html) | null |
| `onEditingComplete` | VoidCallback? | Called when the user submits editable content (e.g., user presses the "done" button on the keyboard) (https://api.flutter.dev/flutter/material/TextField/onEditingComplete.html) | null |
| `onSubmitted` | ValueChanged\<String> | Called when the user indicates that they are done editing the text in the field (https://api.flutter.dev/flutter/material/TextField/onSubmitted.html) | null |

## More examples
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- Flutter (1.0.0)
- flutter_native_text_input (1.2.4):
- flutter_native_text_input (1.3.0):
- Flutter

DEPENDENCIES:
Expand All @@ -15,7 +15,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
flutter_native_text_input: 8d9586a82ca14b2bb437930b4041db9e9ff1a423
flutter_native_text_input: 820911157ee8bcd5be450dc7e36226dad0108e0b

PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d

Expand Down
2 changes: 0 additions & 2 deletions ios/Classes/NativeTextInputDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,6 @@ - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range r
) {
[_channel invokeMethod:@"inputFinished"
arguments:@{ @"text": textView.text }];

[textView resignFirstResponder];
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion ios/flutter_native_text_input.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'flutter_native_text_input'
s.version = '1.2.4'
s.version = '1.3.0'
s.summary = 'Native text input for Flutter'
s.description = <<-DESC
Native text input for Flutter
Expand Down
17 changes: 14 additions & 3 deletions lib/flutter_native_text_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ class NativeTextInput extends StatefulWidget {
this.minLines = 1,
this.placeholder,
this.placeholderStyle,
this.returnKeyType = ReturnKeyType.defaultAction,
this.returnKeyType = ReturnKeyType.done,
this.style,
this.textAlign = TextAlign.start,
this.textCapitalization = TextCapitalization.none,
this.textContentType,
this.onChanged,
this.onEditingComplete,
this.onSubmitted,
}) : super(key: key);

Expand Down Expand Up @@ -201,6 +202,12 @@ class NativeTextInput extends StatefulWidget {
/// Default: null
final ValueChanged<String>? onChanged;

/// Called when the user submits editable content (e.g., user presses the "done" button on the keyboard).
/// (https://api.flutter.dev/flutter/material/TextField/onEditingComplete.html)
///
/// Default: null
final VoidCallback? onEditingComplete;

/// Called when the user indicates that they are done editing the text in the field
/// (https://api.flutter.dev/flutter/material/TextField/onSubmitted.html)
///
Expand Down Expand Up @@ -412,8 +419,12 @@ class _NativeTextInputState extends State<NativeTextInput> {
}

void _inputFinished(String? text) {
_channel.invokeMethod("unfocus");
if (_effectiveFocusNode.hasFocus) FocusScope.of(context).unfocus();
if (widget.onEditingComplete != null) {
widget.onEditingComplete!();
} else {
_channel.invokeMethod("unfocus");
if (_effectiveFocusNode.hasFocus) FocusScope.of(context).unfocus();
}
if (widget.onSubmitted != null) {
Future.delayed(Duration(milliseconds: 100), () {
widget.onSubmitted!(text);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: flutter_native_text_input
description: Native text input for Flutter. Currently iOS-only with the use of UITextView.

version: 1.2.4
version: 1.3.0
homepage: https://github.com/henryleunghk/flutter-native-text-input

environment:
Expand Down

0 comments on commit d040706

Please sign in to comment.