diff --git a/example/lib/more_use_case_listing_page.dart b/example/lib/more_use_case_listing_page.dart index 1bb91d0..bac49be 100644 --- a/example/lib/more_use_case_listing_page.dart +++ b/example/lib/more_use_case_listing_page.dart @@ -63,7 +63,6 @@ class _MoreUseCaseListingPageState extends State { child: NativeTextInput( minLines: 3, maxLines: 5, - returnKeyType: ReturnKeyType.done, onChanged: _onChangeText, onSubmitted: _onSubmittedText, )), diff --git a/ios/Classes/NativeTextInput.m b/ios/Classes/NativeTextInput.m index 4d247db..55b7435 100644 --- a/ios/Classes/NativeTextInput.m +++ b/ios/Classes/NativeTextInput.m @@ -7,6 +7,7 @@ @implementation NativeInputField { int64_t _viewId; FlutterMethodChannel* _channel; NativeTextInputDelegate* _delegate; + id _Nullable _args; float _containerWidth; } @@ -22,6 +23,7 @@ - (instancetype)initWithFrame:(CGRect)frame _channel = [FlutterMethodChannel methodChannelWithName:channelName binaryMessenger:messenger]; _viewId = viewId; + _args = args; _textView = [[UITextView alloc] initWithFrame:frame]; _textView.backgroundColor = UIColor.clearColor; @@ -97,6 +99,18 @@ - (void)onUnFocus:(FlutterMethodCall*)call result:(FlutterResult)result { - (void)onSetText:(FlutterMethodCall*)call result:(FlutterResult)result { _textView.text = call.arguments[@"text"]; + _textView.textColor = _delegate.fontColor; + _textView.font = _delegate.font; + + if (_textView.text.length == 0) { + _textView.text = _args[@"placeholder"]; + _textView.textColor = _delegate.placeholderFontColor; + _textView.font = _delegate.placeholderFont; + } + + if (_textView.textContainer.maximumNumberOfLines == 1) { + _textView.textContainer.lineBreakMode = NSLineBreakByTruncatingTail; + } result(nil); } diff --git a/ios/Classes/NativeTextInputDelegate.m b/ios/Classes/NativeTextInputDelegate.m index 4936ec8..69eed69 100644 --- a/ios/Classes/NativeTextInputDelegate.m +++ b/ios/Classes/NativeTextInputDelegate.m @@ -130,9 +130,6 @@ - (void)textViewDidEndEditing:(UITextView *)textView { if (textView.textContainer.maximumNumberOfLines == 1) { textView.textContainer.lineBreakMode = NSLineBreakByTruncatingTail; } - - [_channel invokeMethod:@"inputFinished" - arguments:@{ @"text": textView.text }]; } - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { @@ -140,6 +137,9 @@ - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range r textView.textContainer.maximumNumberOfLines == 1) && [text isEqualToString:@"\n"] ) { + [_channel invokeMethod:@"inputFinished" + arguments:@{ @"text": textView.text }]; + [textView resignFirstResponder]; return false; }