From d040706758af8188dfb27d09e182cbdfe70cbaa9 Mon Sep 17 00:00:00 2001 From: Henry Leung Date: Tue, 4 Jan 2022 11:17:31 +0800 Subject: [PATCH] add support of onEditingComplete (#25) --- CHANGELOG.md | 4 ++++ README.md | 1 + example/ios/Podfile.lock | 4 ++-- ios/Classes/NativeTextInputDelegate.m | 2 -- ios/flutter_native_text_input.podspec | 2 +- lib/flutter_native_text_input.dart | 17 ++++++++++++++--- pubspec.yaml | 2 +- 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ce2a78..eb4802e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.3.0 + +* add support of onEditingComplete + ## 1.2.4 * fix focus action not working sometimes diff --git a/README.md b/README.md index 885cfe8..6a1969d 100644 --- a/README.md +++ b/README.md @@ -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\ | 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\ | 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 diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index ff15462..ca5abd6 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -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: @@ -15,7 +15,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a - flutter_native_text_input: 8d9586a82ca14b2bb437930b4041db9e9ff1a423 + flutter_native_text_input: 820911157ee8bcd5be450dc7e36226dad0108e0b PODFILE CHECKSUM: 8e679eca47255a8ca8067c4c67aab20e64cb974d diff --git a/ios/Classes/NativeTextInputDelegate.m b/ios/Classes/NativeTextInputDelegate.m index 69eed69..990cf25 100644 --- a/ios/Classes/NativeTextInputDelegate.m +++ b/ios/Classes/NativeTextInputDelegate.m @@ -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; diff --git a/ios/flutter_native_text_input.podspec b/ios/flutter_native_text_input.podspec index e3fe33d..75bf881 100644 --- a/ios/flutter_native_text_input.podspec +++ b/ios/flutter_native_text_input.podspec @@ -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 diff --git a/lib/flutter_native_text_input.dart b/lib/flutter_native_text_input.dart index d033e3f..8acab28 100644 --- a/lib/flutter_native_text_input.dart +++ b/lib/flutter_native_text_input.dart @@ -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); @@ -201,6 +202,12 @@ class NativeTextInput extends StatefulWidget { /// Default: null final ValueChanged? 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) /// @@ -412,8 +419,12 @@ class _NativeTextInputState extends State { } 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); diff --git a/pubspec.yaml b/pubspec.yaml index de6cd24..bb728c8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: