8 #import <Foundation/Foundation.h>
9 #import <UIKit/UIKit.h>
11 #include "unicode/uchar.h"
13 #include "flutter/fml/logging.h"
14 #include "flutter/fml/platform/darwin/string_range_sanitization.h"
37 #pragma mark - TextInput channel method names.
46 @"TextInput.setEditableSizeAndTransform";
57 @"TextInput.onPointerMoveForInteractiveKeyboard";
59 @"TextInput.onPointerUpForInteractiveKeyboard";
61 #pragma mark - TextInputConfiguration Field Names
82 #pragma mark - Static Functions
85 static BOOL
IsEmoji(NSString* text, NSRange charRange) {
87 BOOL gotCodePoint = [text getBytes:&codePoint
88 maxLength:
sizeof(codePoint)
90 encoding:NSUTF32StringEncoding
94 return gotCodePoint && u_hasBinaryProperty(codePoint, UCHAR_EMOJI);
102 NSString* inputType = type[
@"name"];
103 return ![inputType isEqualToString:
@"TextInputType.none"];
106 NSString* inputType = type[
@"name"];
107 if ([inputType isEqualToString:
@"TextInputType.address"]) {
108 return UIKeyboardTypeDefault;
110 if ([inputType isEqualToString:
@"TextInputType.datetime"]) {
111 return UIKeyboardTypeNumbersAndPunctuation;
113 if ([inputType isEqualToString:
@"TextInputType.emailAddress"]) {
114 return UIKeyboardTypeEmailAddress;
116 if ([inputType isEqualToString:
@"TextInputType.multiline"]) {
117 return UIKeyboardTypeDefault;
119 if ([inputType isEqualToString:
@"TextInputType.name"]) {
120 return UIKeyboardTypeNamePhonePad;
122 if ([inputType isEqualToString:
@"TextInputType.number"]) {
123 if ([type[
@"signed"] boolValue]) {
124 return UIKeyboardTypeNumbersAndPunctuation;
126 if ([type[
@"decimal"] boolValue]) {
127 return UIKeyboardTypeDecimalPad;
129 return UIKeyboardTypeNumberPad;
131 if ([inputType isEqualToString:
@"TextInputType.phone"]) {
132 return UIKeyboardTypePhonePad;
134 if ([inputType isEqualToString:
@"TextInputType.text"]) {
135 return UIKeyboardTypeDefault;
137 if ([inputType isEqualToString:
@"TextInputType.url"]) {
138 return UIKeyboardTypeURL;
140 return UIKeyboardTypeDefault;
144 NSString* textCapitalization = type[
@"textCapitalization"];
145 if ([textCapitalization isEqualToString:
@"TextCapitalization.characters"]) {
146 return UITextAutocapitalizationTypeAllCharacters;
147 }
else if ([textCapitalization isEqualToString:
@"TextCapitalization.sentences"]) {
148 return UITextAutocapitalizationTypeSentences;
149 }
else if ([textCapitalization isEqualToString:
@"TextCapitalization.words"]) {
150 return UITextAutocapitalizationTypeWords;
152 return UITextAutocapitalizationTypeNone;
160 if ([inputType isEqualToString:
@"TextInputAction.unspecified"]) {
161 return UIReturnKeyDefault;
164 if ([inputType isEqualToString:
@"TextInputAction.done"]) {
165 return UIReturnKeyDone;
168 if ([inputType isEqualToString:
@"TextInputAction.go"]) {
169 return UIReturnKeyGo;
172 if ([inputType isEqualToString:
@"TextInputAction.send"]) {
173 return UIReturnKeySend;
176 if ([inputType isEqualToString:
@"TextInputAction.search"]) {
177 return UIReturnKeySearch;
180 if ([inputType isEqualToString:
@"TextInputAction.next"]) {
181 return UIReturnKeyNext;
184 if ([inputType isEqualToString:
@"TextInputAction.continueAction"]) {
185 return UIReturnKeyContinue;
188 if ([inputType isEqualToString:
@"TextInputAction.join"]) {
189 return UIReturnKeyJoin;
192 if ([inputType isEqualToString:
@"TextInputAction.route"]) {
193 return UIReturnKeyRoute;
196 if ([inputType isEqualToString:
@"TextInputAction.emergencyCall"]) {
197 return UIReturnKeyEmergencyCall;
200 if ([inputType isEqualToString:
@"TextInputAction.newline"]) {
201 return UIReturnKeyDefault;
205 return UIReturnKeyDefault;
209 if (!hints || hints.count == 0) {
214 NSString* hint = hints[0];
215 if ([hint isEqualToString:
@"addressCityAndState"]) {
216 return UITextContentTypeAddressCityAndState;
219 if ([hint isEqualToString:
@"addressState"]) {
220 return UITextContentTypeAddressState;
223 if ([hint isEqualToString:
@"addressCity"]) {
224 return UITextContentTypeAddressCity;
227 if ([hint isEqualToString:
@"sublocality"]) {
228 return UITextContentTypeSublocality;
231 if ([hint isEqualToString:
@"streetAddressLine1"]) {
232 return UITextContentTypeStreetAddressLine1;
235 if ([hint isEqualToString:
@"streetAddressLine2"]) {
236 return UITextContentTypeStreetAddressLine2;
239 if ([hint isEqualToString:
@"countryName"]) {
240 return UITextContentTypeCountryName;
243 if ([hint isEqualToString:
@"fullStreetAddress"]) {
244 return UITextContentTypeFullStreetAddress;
247 if ([hint isEqualToString:
@"postalCode"]) {
248 return UITextContentTypePostalCode;
251 if ([hint isEqualToString:
@"location"]) {
252 return UITextContentTypeLocation;
255 if ([hint isEqualToString:
@"creditCardNumber"]) {
256 return UITextContentTypeCreditCardNumber;
259 if ([hint isEqualToString:
@"email"]) {
260 return UITextContentTypeEmailAddress;
263 if ([hint isEqualToString:
@"jobTitle"]) {
264 return UITextContentTypeJobTitle;
267 if ([hint isEqualToString:
@"givenName"]) {
268 return UITextContentTypeGivenName;
271 if ([hint isEqualToString:
@"middleName"]) {
272 return UITextContentTypeMiddleName;
275 if ([hint isEqualToString:
@"familyName"]) {
276 return UITextContentTypeFamilyName;
279 if ([hint isEqualToString:
@"name"]) {
280 return UITextContentTypeName;
283 if ([hint isEqualToString:
@"namePrefix"]) {
284 return UITextContentTypeNamePrefix;
287 if ([hint isEqualToString:
@"nameSuffix"]) {
288 return UITextContentTypeNameSuffix;
291 if ([hint isEqualToString:
@"nickname"]) {
292 return UITextContentTypeNickname;
295 if ([hint isEqualToString:
@"organizationName"]) {
296 return UITextContentTypeOrganizationName;
299 if ([hint isEqualToString:
@"telephoneNumber"]) {
300 return UITextContentTypeTelephoneNumber;
303 if ([hint isEqualToString:
@"password"]) {
304 return UITextContentTypePassword;
307 if (@available(iOS 12.0, *)) {
308 if ([hint isEqualToString:
@"oneTimeCode"]) {
309 return UITextContentTypeOneTimeCode;
312 if ([hint isEqualToString:
@"newPassword"]) {
313 return UITextContentTypeNewPassword;
382 typedef NS_ENUM(NSInteger, FlutterAutofillType) {
386 kFlutterAutofillTypeNone,
387 kFlutterAutofillTypeRegular,
388 kFlutterAutofillTypePassword,
398 if (isSecureTextEntry) {
405 if ([contentType isEqualToString:UITextContentTypePassword] ||
406 [contentType isEqualToString:UITextContentTypeUsername]) {
410 if (@available(iOS 12.0, *)) {
411 if ([contentType isEqualToString:UITextContentTypeNewPassword]) {
421 return kFlutterAutofillTypePassword;
426 return kFlutterAutofillTypePassword;
431 return !autofill || [contentType isEqualToString:
@""] ? kFlutterAutofillTypeNone
432 : kFlutterAutofillTypeRegular;
436 return fabsf(x - y) <= delta;
462 CGRect selectionRect,
463 BOOL selectionRectIsRTL,
464 BOOL useTrailingBoundaryOfSelectionRect,
465 CGRect otherSelectionRect,
466 BOOL otherSelectionRectIsRTL,
467 CGFloat verticalPrecision) {
469 if (CGRectContainsPoint(
471 selectionRect.origin.x + ((useTrailingBoundaryOfSelectionRect ^ selectionRectIsRTL)
472 ? 0.5 * selectionRect.size.width
474 selectionRect.origin.y, 0.5 * selectionRect.size.width, selectionRect.size.height),
479 CGPoint pointForSelectionRect = CGPointMake(
480 selectionRect.origin.x +
481 (selectionRectIsRTL ^ useTrailingBoundaryOfSelectionRect ? selectionRect.size.width : 0),
482 selectionRect.origin.y + selectionRect.size.height * 0.5);
483 float yDist = fabs(pointForSelectionRect.y - point.y);
484 float xDist = fabs(pointForSelectionRect.x - point.x);
487 CGPoint pointForOtherSelectionRect = CGPointMake(
488 otherSelectionRect.origin.x + (otherSelectionRectIsRTL ? otherSelectionRect.size.width : 0),
489 otherSelectionRect.origin.y + otherSelectionRect.size.height * 0.5);
490 float yDistOther = fabs(pointForOtherSelectionRect.y - point.y);
491 float xDistOther = fabs(pointForOtherSelectionRect.x - point.x);
496 BOOL isCloserVertically = yDist < yDistOther - verticalPrecision;
498 BOOL isAboveBottomOfLine = point.y <= selectionRect.origin.y + selectionRect.size.height;
499 BOOL isCloserHorizontally = xDist < xDistOther;
500 BOOL isBelowBottomOfLine = point.y > selectionRect.origin.y + selectionRect.size.height;
503 if (selectionRectIsRTL) {
504 isFarther = selectionRect.origin.x < otherSelectionRect.origin.x;
506 isFarther = selectionRect.origin.x +
507 (useTrailingBoundaryOfSelectionRect ? selectionRect.size.width : 0) >
508 otherSelectionRect.origin.x;
510 return (isCloserVertically ||
511 (isEqualVertically &&
512 ((isAboveBottomOfLine && isCloserHorizontally) || (isBelowBottomOfLine && isFarther))));
515 #pragma mark - FlutterTextPosition
519 + (instancetype)positionWithIndex:(NSUInteger)index {
520 return [[
FlutterTextPosition alloc] initWithIndex:index affinity:UITextStorageDirectionForward];
523 + (instancetype)positionWithIndex:(NSUInteger)index affinity:(UITextStorageDirection)affinity {
527 - (instancetype)initWithIndex:(NSUInteger)index affinity:(UITextStorageDirection)affinity {
538 #pragma mark - FlutterTextRange
542 + (instancetype)rangeWithNSRange:(NSRange)range {
546 - (instancetype)initWithNSRange:(NSRange)range {
554 - (UITextPosition*)start {
556 affinity:UITextStorageDirectionForward];
559 - (UITextPosition*)end {
561 affinity:UITextStorageDirectionBackward];
565 return self.range.length == 0;
568 - (
id)copyWithZone:(NSZone*)zone {
573 return NSEqualRanges(
self.
range, other.
range);
577 #pragma mark - FlutterTokenizer
587 - (instancetype)initWithTextInput:(UIResponder<UITextInput>*)textInput {
589 @"The FlutterTokenizer can only be used in a FlutterTextInputView");
590 self = [
super initWithTextInput:textInput];
597 - (UITextRange*)rangeEnclosingPosition:(UITextPosition*)position
598 withGranularity:(UITextGranularity)granularity
599 inDirection:(UITextDirection)direction {
601 switch (granularity) {
602 case UITextGranularityLine:
605 result = [
self lineEnclosingPosition:position inDirection:direction];
607 case UITextGranularityCharacter:
608 case UITextGranularityWord:
609 case UITextGranularitySentence:
610 case UITextGranularityParagraph:
611 case UITextGranularityDocument:
613 result = [
super rangeEnclosingPosition:position
614 withGranularity:granularity
615 inDirection:direction];
621 - (UITextRange*)lineEnclosingPosition:(UITextPosition*)position
622 inDirection:(UITextDirection)direction {
624 if (@available(iOS 17.0, *)) {
629 if (flutterPosition.
index > _textInputView.text.length ||
630 (flutterPosition.
index == _textInputView.text.length &&
631 direction == UITextStorageDirectionForward)) {
637 NSString* textAfter = [_textInputView
638 textInRange:[_textInputView textRangeFromPosition:position
639 toPosition:[_textInputView endOfDocument]]];
640 NSArray<NSString*>* linesAfter = [textAfter componentsSeparatedByString:@"\n"];
641 NSInteger offSetToLineBreak = [linesAfter firstObject].length;
642 UITextPosition* lineBreakAfter = [_textInputView positionFromPosition:position
643 offset:offSetToLineBreak];
645 NSString* textBefore = [_textInputView
646 textInRange:[_textInputView textRangeFromPosition:[_textInputView beginningOfDocument]
647 toPosition:position]];
648 NSArray<NSString*>* linesBefore = [textBefore componentsSeparatedByString:@"\n"];
649 NSInteger offSetFromLineBreak = [linesBefore lastObject].length;
650 UITextPosition* lineBreakBefore = [_textInputView positionFromPosition:position
651 offset:-offSetFromLineBreak];
653 return [_textInputView textRangeFromPosition:lineBreakBefore toPosition:lineBreakAfter];
658 #pragma mark - FlutterTextSelectionRect
662 @synthesize rect = _rect;
668 + (instancetype)selectionRectWithRectAndInfo:(CGRect)rect
669 position:(NSUInteger)position
670 writingDirection:(NSWritingDirection)writingDirection
671 containsStart:(BOOL)containsStart
672 containsEnd:(BOOL)containsEnd
673 isVertical:(BOOL)isVertical {
676 writingDirection:writingDirection
677 containsStart:containsStart
678 containsEnd:containsEnd
679 isVertical:isVertical];
682 + (instancetype)selectionRectWithRect:(CGRect)rect position:(NSUInteger)position {
685 writingDirection:NSWritingDirectionNatural
691 + (instancetype)selectionRectWithRect:(CGRect)rect
692 position:(NSUInteger)position
693 writingDirection:(NSWritingDirection)writingDirection {
696 writingDirection:writingDirection
702 - (instancetype)initWithRectAndInfo:(CGRect)rect
703 position:(NSUInteger)position
704 writingDirection:(NSWritingDirection)writingDirection
705 containsStart:(BOOL)containsStart
706 containsEnd:(BOOL)containsEnd
707 isVertical:(BOOL)isVertical {
721 return _writingDirection == NSWritingDirectionRightToLeft;
726 #pragma mark - FlutterTextPlaceholder
730 - (NSArray<UITextSelectionRect*>*)rects {
746 @property(nonatomic, retain, readonly) UITextField*
textField;
760 - (BOOL)isKindOfClass:(Class)aClass {
761 return [
super isKindOfClass:aClass] || (aClass == [UITextField class]);
764 - (NSMethodSignature*)methodSignatureForSelector:(
SEL)aSelector {
765 NSMethodSignature* signature = [
super methodSignatureForSelector:aSelector];
767 signature = [
self.textField methodSignatureForSelector:aSelector];
772 - (void)forwardInvocation:(NSInvocation*)anInvocation {
773 [anInvocation invokeWithTarget:self.textField];
779 @property(nonatomic, readonly, weak) id<FlutterTextInputDelegate> textInputDelegate;
780 @property(nonatomic, readonly) UIView* hostView;
785 @property(nonatomic, copy) NSString* autofillId;
786 @property(nonatomic, readonly) CATransform3D editableTransform;
787 @property(nonatomic, assign) CGRect markedRect;
789 @property(nonatomic, assign) BOOL preventCursorDismissWhenResignFirstResponder;
790 @property(nonatomic) BOOL isVisibleToAutofill;
791 @property(nonatomic, assign) BOOL accessibilityEnabled;
792 @property(nonatomic, assign)
int textInputClient;
796 @property(nonatomic, copy) NSString* temporarilyDeletedComposedCharacter;
798 - (void)setEditableTransform:(NSArray*)matrix;
802 int _textInputClient;
816 UITextInteraction* _textInteraction
API_AVAILABLE(ios(13.0));
819 @synthesize tokenizer = _tokenizer;
822 self = [
super initWithFrame:CGRectZero];
825 _textInputClient = 0;
827 _preventCursorDismissWhenResignFirstResponder = NO;
830 _text = [[NSMutableString alloc] init];
831 _markedText = [[NSMutableString alloc] init];
836 _pendingDeltas = [[NSMutableArray alloc] init];
839 _editableTransform = CATransform3D();
842 _autocapitalizationType = UITextAutocapitalizationTypeSentences;
843 _autocorrectionType = UITextAutocorrectionTypeDefault;
844 _spellCheckingType = UITextSpellCheckingTypeDefault;
845 _enablesReturnKeyAutomatically = NO;
846 _keyboardAppearance = UIKeyboardAppearanceDefault;
847 _keyboardType = UIKeyboardTypeDefault;
848 _returnKeyType = UIReturnKeyDone;
849 _secureTextEntry = NO;
850 _enableDeltaModel = NO;
852 _accessibilityEnabled = NO;
853 _smartQuotesType = UITextSmartQuotesTypeYes;
854 _smartDashesType = UITextSmartDashesTypeYes;
855 _selectionRects = [[NSArray alloc] init];
857 if (@available(iOS 14.0, *)) {
858 UIScribbleInteraction* interaction = [[UIScribbleInteraction alloc] initWithDelegate:self];
859 [
self addInteraction:interaction];
866 - (void)configureWithDictionary:(NSDictionary*)configuration {
867 NSDictionary* inputType = configuration[kKeyboardType];
869 NSDictionary* autofill = configuration[kAutofillProperties];
871 self.secureTextEntry = [configuration[kSecureTextEntry] boolValue];
872 self.enableDeltaModel = [configuration[kEnableDeltaModel] boolValue];
879 NSString* smartDashesType = configuration[kSmartDashesType];
881 bool smartDashesIsDisabled = smartDashesType && [smartDashesType isEqualToString:@"0"];
882 self.smartDashesType = smartDashesIsDisabled ? UITextSmartDashesTypeNo : UITextSmartDashesTypeYes;
883 NSString* smartQuotesType = configuration[kSmartQuotesType];
885 bool smartQuotesIsDisabled = smartQuotesType && [smartQuotesType isEqualToString:@"0"];
886 self.smartQuotesType = smartQuotesIsDisabled ? UITextSmartQuotesTypeNo : UITextSmartQuotesTypeYes;
888 self.keyboardAppearance = UIKeyboardAppearanceDark;
890 self.keyboardAppearance = UIKeyboardAppearanceLight;
892 self.keyboardAppearance = UIKeyboardAppearanceDefault;
894 NSString* autocorrect = configuration[kAutocorrectionType];
895 bool autocorrectIsDisabled = autocorrect && ![autocorrect boolValue];
896 self.autocorrectionType =
897 autocorrectIsDisabled ? UITextAutocorrectionTypeNo : UITextAutocorrectionTypeDefault;
898 self.spellCheckingType =
899 autocorrectIsDisabled ? UITextSpellCheckingTypeNo : UITextSpellCheckingTypeDefault;
901 if (autofill == nil) {
902 self.textContentType =
@"";
905 [
self setTextInputState:autofill[kAutofillEditingValue]];
906 NSAssert(_autofillId,
@"The autofill configuration must contain an autofill id");
910 self.isVisibleToAutofill = autofill || _secureTextEntry;
913 - (UITextContentType)textContentType {
914 return _textContentType;
920 - (UIColor*)insertionPointColor {
921 return [UIColor clearColor];
924 - (UIColor*)selectionBarColor {
925 return [UIColor clearColor];
928 - (UIColor*)selectionHighlightColor {
929 return [UIColor clearColor];
932 - (UIInputViewController*)inputViewController {
947 - (void)setTextInputClient:(
int)client {
948 _textInputClient = client;
952 - (UITextInteraction*)textInteraction
API_AVAILABLE(ios(13.0)) {
953 if (!_textInteraction) {
954 _textInteraction = [UITextInteraction textInteractionForMode:UITextInteractionModeEditable];
955 _textInteraction.textInput =
self;
957 return _textInteraction;
960 - (void)setTextInputState:(NSDictionary*)state {
961 if (@available(iOS 13.0, *)) {
968 [
self addInteraction:self.textInteraction];
972 NSString* newText = state[@"text"];
973 BOOL textChanged = ![
self.text isEqualToString:newText];
975 [
self.inputDelegate textWillChange:self];
976 [
self.text setString:newText];
978 NSInteger composingBase = [state[@"composingBase"] intValue];
979 NSInteger composingExtent = [state[@"composingExtent"] intValue];
980 NSRange composingRange = [
self clampSelection:NSMakeRange(MIN(composingBase, composingExtent),
981 ABS(composingBase - composingExtent))
984 self.markedTextRange =
987 NSRange selectedRange = [
self clampSelectionFromBase:[state[@"selectionBase"] intValue]
988 extent:[state[@"selectionExtent"] intValue]
991 NSRange oldSelectedRange = [(
FlutterTextRange*)
self.selectedTextRange range];
992 if (!NSEqualRanges(selectedRange, oldSelectedRange)) {
993 [
self.inputDelegate selectionWillChange:self];
1001 [
self.inputDelegate selectionDidChange:self];
1005 [
self.inputDelegate textDidChange:self];
1008 if (@available(iOS 13.0, *)) {
1009 if (_textInteraction) {
1010 [
self removeInteraction:_textInteraction];
1016 - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
1017 _scribbleFocusStatus = FlutterScribbleFocusStatusUnfocused;
1018 [
self resetScribbleInteractionStatusIfEnding];
1019 [
self.viewResponder touchesBegan:touches withEvent:event];
1022 - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
1023 [
self.viewResponder touchesMoved:touches withEvent:event];
1026 - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
1027 [
self.viewResponder touchesEnded:touches withEvent:event];
1030 - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
1031 [
self.viewResponder touchesCancelled:touches withEvent:event];
1034 - (void)touchesEstimatedPropertiesUpdated:(NSSet*)touches {
1035 [
self.viewResponder touchesEstimatedPropertiesUpdated:touches];
1045 - (NSRange)clampSelectionFromBase:(
int)selectionBase
1046 extent:(
int)selectionExtent
1047 forText:(NSString*)text {
1048 int loc = MIN(selectionBase, selectionExtent);
1049 int len = ABS(selectionExtent - selectionBase);
1050 return loc < 0 ? NSMakeRange(0, 0)
1051 : [
self clampSelection:NSMakeRange(loc, len) forText:
self.text];
1054 - (NSRange)clampSelection:(NSRange)range forText:(NSString*)text {
1055 NSUInteger start = MIN(MAX(range.location, 0), text.length);
1056 NSUInteger length = MIN(range.length, text.length - start);
1057 return NSMakeRange(start, length);
1060 - (BOOL)isVisibleToAutofill {
1061 return self.frame.size.width > 0 &&
self.frame.size.height > 0;
1069 - (void)setIsVisibleToAutofill:(BOOL)isVisibleToAutofill {
1072 self.frame = isVisibleToAutofill ? CGRectMake(0, 0, 1, 1) : CGRectZero;
1075 #pragma mark UIScribbleInteractionDelegate
1080 if (@available(iOS 14.0, *)) {
1081 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
1088 - (void)scribbleInteractionWillBeginWriting:(UIScribbleInteraction*)interaction
1089 API_AVAILABLE(ios(14.0)) {
1091 [
self.textInputDelegate flutterTextInputViewScribbleInteractionBegan:self];
1094 - (void)scribbleInteractionDidFinishWriting:(UIScribbleInteraction*)interaction
1095 API_AVAILABLE(ios(14.0)) {
1097 [
self.textInputDelegate flutterTextInputViewScribbleInteractionFinished:self];
1100 - (BOOL)scribbleInteraction:(UIScribbleInteraction*)interaction
1101 shouldBeginAtLocation:(CGPoint)location API_AVAILABLE(ios(14.0)) {
1105 - (BOOL)scribbleInteractionShouldDelayFocus:(UIScribbleInteraction*)interaction
1106 API_AVAILABLE(ios(14.0)) {
1110 #pragma mark - UIResponder Overrides
1112 - (BOOL)canBecomeFirstResponder {
1117 return _textInputClient != 0;
1120 - (BOOL)resignFirstResponder {
1121 BOOL success = [
super resignFirstResponder];
1123 if (!_preventCursorDismissWhenResignFirstResponder) {
1124 [
self.textInputDelegate flutterTextInputView:self
1125 didResignFirstResponderWithTextInputClient:_textInputClient];
1131 - (BOOL)canPerformAction:(
SEL)action withSender:(
id)sender {
1137 if (
action ==
@selector(paste:)) {
1139 return [UIPasteboard generalPasteboard].string != nil;
1142 return [
super canPerformAction:action withSender:sender];
1145 #pragma mark - UIResponderStandardEditActions Overrides
1147 - (void)cut:(
id)sender {
1148 [UIPasteboard generalPasteboard].string = [
self textInRange:_selectedTextRange];
1149 [
self replaceRange:_selectedTextRange withText:@""];
1152 - (void)copy:(
id)sender {
1153 [UIPasteboard generalPasteboard].string = [
self textInRange:_selectedTextRange];
1156 - (void)paste:(
id)sender {
1157 NSString* pasteboardString = [UIPasteboard generalPasteboard].string;
1158 if (pasteboardString != nil) {
1159 [
self insertText:pasteboardString];
1163 - (void)delete:(
id)sender {
1164 [
self replaceRange:_selectedTextRange withText:@""];
1167 - (void)selectAll:(
id)sender {
1168 [
self setSelectedTextRange:[
self textRangeFromPosition:[
self beginningOfDocument]
1169 toPosition:[
self endOfDocument]]];
1172 #pragma mark - UITextInput Overrides
1174 - (
id<UITextInputTokenizer>)tokenizer {
1175 if (_tokenizer == nil) {
1182 return [_selectedTextRange copy];
1186 - (void)setSelectedTextRangeLocal:(UITextRange*)selectedTextRange {
1191 rangeWithNSRange:fml::RangeForCharactersInRange(self.text, flutterTextRange.range)] copy];
1198 - (void)setSelectedTextRange:(UITextRange*)selectedTextRange {
1203 [
self setSelectedTextRangeLocal:selectedTextRange];
1205 if (_enableDeltaModel) {
1206 [
self updateEditingStateWithDelta:flutter::TextEditingDelta([
self.text UTF8String])];
1208 [
self updateEditingState];
1212 _scribbleFocusStatus == FlutterScribbleFocusStatusFocused) {
1216 if (flutterTextRange.
range.length > 0) {
1217 [
self.textInputDelegate flutterTextInputView:self showToolbar:_textInputClient];
1221 [
self resetScribbleInteractionStatusIfEnding];
1224 - (
id)insertDictationResultPlaceholder {
1228 - (void)removeDictationResultPlaceholder:(
id)placeholder willInsertResult:(BOOL)willInsertResult {
1231 - (NSString*)textInRange:(UITextRange*)range {
1236 @"Expected a FlutterTextRange for range (got %@).", [range
class]);
1238 NSAssert(textRange.location != NSNotFound,
@"Expected a valid text range.");
1240 NSUInteger location = MIN(textRange.location,
self.text.length);
1241 NSUInteger length = MIN(
self.text.length - location, textRange.length);
1242 NSRange safeRange = NSMakeRange(location, length);
1243 return [
self.text substringWithRange:safeRange];
1248 - (void)replaceRangeLocal:(NSRange)range withText:(NSString*)text {
1254 NSRange intersectionRange = NSIntersectionRange(range, selectedRange);
1255 if (range.location <= selectedRange.location) {
1256 selectedRange.location += text.length - range.length;
1258 if (intersectionRange.location != NSNotFound) {
1259 selectedRange.location += intersectionRange.length;
1260 selectedRange.length -= intersectionRange.length;
1263 [
self.text replaceCharactersInRange:[
self clampSelection:range forText:self.text]
1267 forText:self.text]]];
1270 - (void)replaceRange:(UITextRange*)range withText:(NSString*)text {
1271 NSString* textBeforeChange = [
self.text copy];
1273 [
self replaceRangeLocal:replaceRange withText:text];
1274 if (_enableDeltaModel) {
1275 NSRange nextReplaceRange = [
self clampSelection:replaceRange forText:textBeforeChange];
1276 [
self updateEditingStateWithDelta:flutter::TextEditingDelta(
1277 [textBeforeChange UTF8String],
1279 nextReplaceRange.location,
1280 nextReplaceRange.location + nextReplaceRange.length),
1281 [text UTF8String])];
1283 [
self updateEditingState];
1287 - (BOOL)shouldChangeTextInRange:(UITextRange*)range replacementText:(NSString*)text {
1290 self.temporarilyDeletedComposedCharacter = nil;
1292 if (
self.
returnKeyType == UIReturnKeyDefault && [text isEqualToString:
@"\n"]) {
1293 [
self.textInputDelegate flutterTextInputView:self
1294 performAction:FlutterTextInputActionNewline
1295 withClient:_textInputClient];
1299 if ([text isEqualToString:
@"\n"]) {
1300 FlutterTextInputAction
action;
1302 case UIReturnKeyDefault:
1303 action = FlutterTextInputActionUnspecified;
1305 case UIReturnKeyDone:
1306 action = FlutterTextInputActionDone;
1309 action = FlutterTextInputActionGo;
1311 case UIReturnKeySend:
1312 action = FlutterTextInputActionSend;
1314 case UIReturnKeySearch:
1315 case UIReturnKeyGoogle:
1316 case UIReturnKeyYahoo:
1317 action = FlutterTextInputActionSearch;
1319 case UIReturnKeyNext:
1320 action = FlutterTextInputActionNext;
1322 case UIReturnKeyContinue:
1323 action = FlutterTextInputActionContinue;
1325 case UIReturnKeyJoin:
1326 action = FlutterTextInputActionJoin;
1328 case UIReturnKeyRoute:
1329 action = FlutterTextInputActionRoute;
1331 case UIReturnKeyEmergencyCall:
1332 action = FlutterTextInputActionEmergencyCall;
1336 [
self.textInputDelegate flutterTextInputView:self
1337 performAction:action
1338 withClient:_textInputClient];
1345 - (void)setMarkedText:(NSString*)markedText selectedRange:(NSRange)markedSelectedRange {
1346 NSString* textBeforeChange = [
self.text copy];
1349 NSRange actualReplacedRange;
1352 _scribbleFocusStatus != FlutterScribbleFocusStatusUnfocused) {
1362 [
self replaceRangeLocal:markedTextRange withText:markedText];
1367 actualReplacedRange = selectedRange;
1368 [
self replaceRangeLocal:selectedRange withText:markedText];
1372 self.markedTextRange =
1375 NSUInteger selectionLocation = markedSelectedRange.location +
markedTextRange.location;
1376 selectedRange = NSMakeRange(selectionLocation, markedSelectedRange.length);
1379 forText:self.text]]];
1380 if (_enableDeltaModel) {
1381 NSRange nextReplaceRange = [
self clampSelection:actualReplacedRange forText:textBeforeChange];
1382 [
self updateEditingStateWithDelta:flutter::TextEditingDelta(
1383 [textBeforeChange UTF8String],
1385 nextReplaceRange.location,
1386 nextReplaceRange.location + nextReplaceRange.length),
1387 [markedText UTF8String])];
1389 [
self updateEditingState];
1393 - (void)unmarkText {
1397 self.markedTextRange = nil;
1398 if (_enableDeltaModel) {
1399 [
self updateEditingStateWithDelta:flutter::TextEditingDelta([
self.text UTF8String])];
1401 [
self updateEditingState];
1405 - (UITextRange*)textRangeFromPosition:(UITextPosition*)fromPosition
1406 toPosition:(UITextPosition*)toPosition {
1409 if (toIndex >= fromIndex) {
1422 - (NSUInteger)decrementOffsetPosition:(NSUInteger)position {
1423 return fml::RangeForCharacterAtIndex(
self.text, MAX(0, position - 1)).location;
1426 - (NSUInteger)incrementOffsetPosition:(NSUInteger)position {
1427 NSRange charRange = fml::RangeForCharacterAtIndex(
self.text, position);
1428 return MIN(position + charRange.length,
self.text.length);
1431 - (UITextPosition*)positionFromPosition:(UITextPosition*)position offset:(NSInteger)offset {
1434 NSInteger newLocation = (NSInteger)offsetPosition + offset;
1435 if (newLocation < 0 || newLocation > (NSInteger)
self.text.length) {
1444 for (NSInteger i = 0; i < offset && offsetPosition <
self.text.length; ++i) {
1445 offsetPosition = [
self incrementOffsetPosition:offsetPosition];
1448 for (NSInteger i = 0; i < ABS(offset) && offsetPosition > 0; ++i) {
1449 offsetPosition = [
self decrementOffsetPosition:offsetPosition];
1455 - (UITextPosition*)positionFromPosition:(UITextPosition*)position
1456 inDirection:(UITextLayoutDirection)direction
1457 offset:(NSInteger)offset {
1459 switch (direction) {
1460 case UITextLayoutDirectionLeft:
1461 case UITextLayoutDirectionUp:
1462 return [
self positionFromPosition:position offset:offset * -1];
1463 case UITextLayoutDirectionRight:
1464 case UITextLayoutDirectionDown:
1465 return [
self positionFromPosition:position offset:1];
1469 - (UITextPosition*)beginningOfDocument {
1473 - (UITextPosition*)endOfDocument {
1475 affinity:UITextStorageDirectionBackward];
1478 - (NSComparisonResult)comparePosition:(UITextPosition*)position toPosition:(UITextPosition*)other {
1481 if (positionIndex < otherIndex) {
1482 return NSOrderedAscending;
1484 if (positionIndex > otherIndex) {
1485 return NSOrderedDescending;
1489 if (positionAffinity == otherAffinity) {
1490 return NSOrderedSame;
1492 if (positionAffinity == UITextStorageDirectionBackward) {
1494 return NSOrderedAscending;
1497 return NSOrderedDescending;
1500 - (NSInteger)offsetFromPosition:(UITextPosition*)from toPosition:(UITextPosition*)toPosition {
1504 - (UITextPosition*)positionWithinRange:(UITextRange*)range
1505 farthestInDirection:(UITextLayoutDirection)direction {
1507 UITextStorageDirection affinity;
1508 switch (direction) {
1509 case UITextLayoutDirectionLeft:
1510 case UITextLayoutDirectionUp:
1512 affinity = UITextStorageDirectionForward;
1514 case UITextLayoutDirectionRight:
1515 case UITextLayoutDirectionDown:
1517 affinity = UITextStorageDirectionBackward;
1523 - (UITextRange*)characterRangeByExtendingPosition:(UITextPosition*)position
1524 inDirection:(UITextLayoutDirection)direction {
1526 NSUInteger startIndex;
1527 NSUInteger endIndex;
1528 switch (direction) {
1529 case UITextLayoutDirectionLeft:
1530 case UITextLayoutDirectionUp:
1531 startIndex = [
self decrementOffsetPosition:positionIndex];
1532 endIndex = positionIndex;
1534 case UITextLayoutDirectionRight:
1535 case UITextLayoutDirectionDown:
1536 startIndex = positionIndex;
1537 endIndex = [
self incrementOffsetPosition:positionIndex];
1543 #pragma mark - UITextInput text direction handling
1545 - (UITextWritingDirection)baseWritingDirectionForPosition:(UITextPosition*)position
1546 inDirection:(UITextStorageDirection)direction {
1548 return UITextWritingDirectionNatural;
1551 - (void)setBaseWritingDirection:(UITextWritingDirection)writingDirection
1552 forRange:(UITextRange*)range {
1556 #pragma mark - UITextInput cursor, selection rect handling
1558 - (void)setMarkedRect:(CGRect)markedRect {
1559 _markedRect = markedRect;
1566 - (void)setEditableTransform:(NSArray*)matrix {
1567 CATransform3D* transform = &_editableTransform;
1569 transform->m11 = [matrix[0] doubleValue];
1570 transform->m12 = [matrix[1] doubleValue];
1571 transform->m13 = [matrix[2] doubleValue];
1572 transform->m14 = [matrix[3] doubleValue];
1574 transform->m21 = [matrix[4] doubleValue];
1575 transform->m22 = [matrix[5] doubleValue];
1576 transform->m23 = [matrix[6] doubleValue];
1577 transform->m24 = [matrix[7] doubleValue];
1579 transform->m31 = [matrix[8] doubleValue];
1580 transform->m32 = [matrix[9] doubleValue];
1581 transform->m33 = [matrix[10] doubleValue];
1582 transform->m34 = [matrix[11] doubleValue];
1584 transform->m41 = [matrix[12] doubleValue];
1585 transform->m42 = [matrix[13] doubleValue];
1586 transform->m43 = [matrix[14] doubleValue];
1587 transform->m44 = [matrix[15] doubleValue];
1595 - (CGRect)localRectFromFrameworkTransform:(CGRect)incomingRect {
1596 CGPoint points[] = {
1597 incomingRect.origin,
1598 CGPointMake(incomingRect.origin.x, incomingRect.origin.y + incomingRect.size.height),
1599 CGPointMake(incomingRect.origin.x + incomingRect.size.width, incomingRect.origin.y),
1600 CGPointMake(incomingRect.origin.x + incomingRect.size.width,
1601 incomingRect.origin.y + incomingRect.size.height)};
1603 CGPoint origin = CGPointMake(CGFLOAT_MAX, CGFLOAT_MAX);
1604 CGPoint farthest = CGPointMake(-CGFLOAT_MAX, -CGFLOAT_MAX);
1606 for (
int i = 0; i < 4; i++) {
1607 const CGPoint point = points[i];
1609 CGFloat x = _editableTransform.m11 * point.x + _editableTransform.m21 * point.y +
1610 _editableTransform.m41;
1611 CGFloat y = _editableTransform.m12 * point.x + _editableTransform.m22 * point.y +
1612 _editableTransform.m42;
1614 const CGFloat w = _editableTransform.m14 * point.x + _editableTransform.m24 * point.y +
1615 _editableTransform.m44;
1619 }
else if (w != 1.0) {
1624 origin.x = MIN(origin.x, x);
1625 origin.y = MIN(origin.y, y);
1626 farthest.x = MAX(farthest.x, x);
1627 farthest.y = MAX(farthest.y, y);
1629 return CGRectMake(origin.x, origin.y, farthest.x - origin.x, farthest.y - origin.y);
1638 - (CGRect)firstRectForRange:(UITextRange*)range {
1640 @"Expected a FlutterTextPosition for range.start (got %@).", [range.start
class]);
1642 @"Expected a FlutterTextPosition for range.end (got %@).", [range.end
class]);
1645 if (_markedTextRange != nil) {
1656 CGRect rect = _markedRect;
1657 if (CGRectIsEmpty(rect)) {
1658 rect = CGRectInset(rect, -0.1, 0);
1664 NSAssert(hostView == nil || [
self isDescendantOfView:hostView],
@"%@ is not a descendant of %@",
1666 return hostView ? [hostView convertRect:_cachedFirstRect toView:self] :
_cachedFirstRect;
1670 _scribbleFocusStatus == FlutterScribbleFocusStatusUnfocused) {
1671 if (@available(iOS 17.0, *)) {
1681 [
self.textInputDelegate flutterTextInputView:self
1682 showAutocorrectionPromptRectForStart:start
1684 withClient:_textInputClient];
1688 NSUInteger first = start;
1693 CGRect startSelectionRect = CGRectNull;
1694 CGRect endSelectionRect = CGRectNull;
1697 CGFloat minY = CGFLOAT_MAX;
1698 CGFloat maxY = CGFLOAT_MIN;
1701 rangeWithNSRange:fml::RangeForCharactersInRange(self.text, NSMakeRange(0, self.text.length))];
1702 for (NSUInteger i = 0; i < [_selectionRects count]; i++) {
1703 BOOL startsOnOrBeforeStartOfRange = _selectionRects[i].position <= first;
1704 BOOL isLastSelectionRect = i + 1 == [_selectionRects count];
1705 BOOL endOfTextIsAfterStartOfRange = isLastSelectionRect && textRange.
range.length > first;
1706 BOOL nextSelectionRectIsAfterStartOfRange =
1707 !isLastSelectionRect && _selectionRects[i + 1].position > first;
1708 if (startsOnOrBeforeStartOfRange &&
1709 (endOfTextIsAfterStartOfRange || nextSelectionRectIsAfterStartOfRange)) {
1711 if (@available(iOS 17, *)) {
1712 startSelectionRect = _selectionRects[i].rect;
1714 return _selectionRects[i].rect;
1717 if (!CGRectIsNull(startSelectionRect)) {
1718 minY = fmin(minY, CGRectGetMinY(_selectionRects[i].rect));
1719 maxY = fmax(maxY, CGRectGetMaxY(_selectionRects[i].rect));
1720 BOOL endsOnOrAfterEndOfRange = _selectionRects[i].position >= end - 1;
1721 BOOL nextSelectionRectIsOnNextLine =
1722 !isLastSelectionRect &&
1727 CGRectGetMidY(_selectionRects[i + 1].rect) > CGRectGetMaxY(_selectionRects[i].rect);
1728 if (endsOnOrAfterEndOfRange || isLastSelectionRect || nextSelectionRectIsOnNextLine) {
1729 endSelectionRect = _selectionRects[i].rect;
1734 if (CGRectIsNull(startSelectionRect) || CGRectIsNull(endSelectionRect)) {
1738 CGFloat minX = fmin(CGRectGetMinX(startSelectionRect), CGRectGetMinX(endSelectionRect));
1739 CGFloat maxX = fmax(CGRectGetMaxX(startSelectionRect), CGRectGetMaxX(endSelectionRect));
1740 return CGRectMake(minX, minY, maxX - minX, maxY - minY);
1744 - (CGRect)caretRectForPosition:(UITextPosition*)position {
1748 NSArray<UITextSelectionRect*>* rects = [
self
1750 rangeWithNSRange:fml::RangeForCharactersInRange(
1754 (index >= (NSInteger)self.text.length)
1757 if (rects.count == 0) {
1763 CGRect characterAfterCaret = rects[0].rect;
1768 return CGRectMake(characterAfterCaret.origin.x + characterAfterCaret.size.width,
1769 characterAfterCaret.origin.y, 0, characterAfterCaret.size.height);
1771 return CGRectMake(characterAfterCaret.origin.x, characterAfterCaret.origin.y, 0,
1772 characterAfterCaret.size.height);
1774 }
else if (rects.count == 2 && affinity == UITextStorageDirectionForward) {
1777 CGRect characterAfterCaret = rects[1].rect;
1782 return CGRectMake(characterAfterCaret.origin.x + characterAfterCaret.size.width,
1783 characterAfterCaret.origin.y, 0, characterAfterCaret.size.height);
1785 return CGRectMake(characterAfterCaret.origin.x, characterAfterCaret.origin.y, 0,
1786 characterAfterCaret.size.height);
1795 CGRect characterBeforeCaret = rects[0].rect;
1798 return CGRectMake(characterBeforeCaret.origin.x, characterBeforeCaret.origin.y, 0,
1799 characterBeforeCaret.size.height);
1801 return CGRectMake(characterBeforeCaret.origin.x + characterBeforeCaret.size.width,
1802 characterBeforeCaret.origin.y, 0, characterBeforeCaret.size.height);
1806 - (UITextPosition*)closestPositionToPoint:(CGPoint)point {
1807 if ([_selectionRects count] == 0) {
1809 @"Expected a FlutterTextPosition for position (got %@).",
1812 UITextStorageDirection currentAffinity =
1818 rangeWithNSRange:fml::RangeForCharactersInRange(self.text, NSMakeRange(0, self.text.length))];
1819 return [
self closestPositionToPoint:point withinRange:range];
1822 - (NSArray*)selectionRectsForRange:(UITextRange*)range {
1830 @"Expected a FlutterTextPosition for range.start (got %@).", [range.start
class]);
1832 @"Expected a FlutterTextPosition for range.end (got %@).", [range.end
class]);
1835 NSMutableArray* rects = [[NSMutableArray alloc] init];
1836 for (NSUInteger i = 0; i < [_selectionRects count]; i++) {
1837 if (_selectionRects[i].position >= start &&
1838 (_selectionRects[i].position < end ||
1839 (start == end && _selectionRects[i].position <= end))) {
1840 float width = _selectionRects[i].rect.size.width;
1844 CGRect rect = CGRectMake(_selectionRects[i].rect.origin.x, _selectionRects[i].rect.origin.y,
1845 width, _selectionRects[i].rect.size.height);
1848 position:_selectionRects[i].position
1852 self.text, NSMakeRange(0, self.text.length))
1855 [rects addObject:selectionRect];
1861 - (UITextPosition*)closestPositionToPoint:(CGPoint)point withinRange:(UITextRange*)range {
1863 @"Expected a FlutterTextPosition for range.start (got %@).", [range.start
class]);
1865 @"Expected a FlutterTextPosition for range.end (got %@).", [range.end
class]);
1875 NSUInteger _closestRectIndex = 0;
1876 for (NSUInteger i = 0; i < [_selectionRects count]; i++) {
1877 NSUInteger position = _selectionRects[i].position;
1878 if (position >= start && position <= end) {
1881 point, _selectionRects[i].rect, _selectionRects[i].isRTL,
1882 NO, _selectionRects[_closestRectIndex].rect,
1883 _selectionRects[_closestRectIndex].isRTL, verticalPrecision)) {
1885 _closestRectIndex = i;
1892 affinity:UITextStorageDirectionForward];
1898 for (NSUInteger i = MAX(0, _closestRectIndex - 1);
1899 i < MIN(_closestRectIndex + 2, [_selectionRects count]); i++) {
1900 NSUInteger position = _selectionRects[i].position + 1;
1901 if (position >= start && position <= end) {
1903 point, _selectionRects[i].rect, _selectionRects[i].isRTL,
1904 YES, _selectionRects[_closestRectIndex].rect,
1905 _selectionRects[_closestRectIndex].isRTL, verticalPrecision)) {
1908 affinity:UITextStorageDirectionBackward];
1913 return closestPosition;
1916 - (UITextRange*)characterRangeAtPoint:(CGPoint)point {
1919 return [
FlutterTextRange rangeWithNSRange:fml::RangeForCharacterAtIndex(self.text, currentIndex)];
1950 - (void)beginFloatingCursorAtPoint:(CGPoint)point {
1967 [
self.textInputDelegate flutterTextInputView:self
1968 updateFloatingCursor:FlutterFloatingCursorDragStateStart
1969 withClient:_textInputClient
1970 withPosition:@{@"X" : @0, @"Y" : @0}];
1973 - (void)updateFloatingCursorAtPoint:(CGPoint)point {
1974 [
self.textInputDelegate flutterTextInputView:self
1975 updateFloatingCursor:FlutterFloatingCursorDragStateUpdate
1976 withClient:_textInputClient
1978 @"X" : @(point.x - _floatingCursorOffset.x),
1979 @"Y" : @(point.y - _floatingCursorOffset.y)
1983 - (void)endFloatingCursor {
1985 [
self.textInputDelegate flutterTextInputView:self
1986 updateFloatingCursor:FlutterFloatingCursorDragStateEnd
1987 withClient:_textInputClient
1988 withPosition:@{@"X" : @0, @"Y" : @0}];
1991 #pragma mark - UIKeyInput Overrides
1993 - (void)updateEditingState {
1998 NSInteger composingBase = -1;
1999 NSInteger composingExtent = -1;
2004 NSDictionary* state = @{
2005 @"selectionBase" : @(selectionBase),
2006 @"selectionExtent" : @(selectionExtent),
2008 @"selectionIsDirectional" : @(
false),
2009 @"composingBase" : @(composingBase),
2010 @"composingExtent" : @(composingExtent),
2011 @"text" : [NSString stringWithString:self.text],
2014 if (_textInputClient == 0 && _autofillId != nil) {
2015 [
self.textInputDelegate flutterTextInputView:self
2016 updateEditingClient:_textInputClient
2018 withTag:_autofillId];
2020 [
self.textInputDelegate flutterTextInputView:self
2021 updateEditingClient:_textInputClient
2026 - (void)updateEditingStateWithDelta:(
flutter::TextEditingDelta)delta {
2031 NSInteger composingBase = -1;
2032 NSInteger composingExtent = -1;
2038 NSDictionary* deltaToFramework = @{
2039 @"oldText" : @(delta.old_text().c_str()),
2040 @"deltaText" : @(delta.delta_text().c_str()),
2041 @"deltaStart" : @(delta.delta_start()),
2042 @"deltaEnd" : @(delta.delta_end()),
2043 @"selectionBase" : @(selectionBase),
2044 @"selectionExtent" : @(selectionExtent),
2046 @"selectionIsDirectional" : @(
false),
2047 @"composingBase" : @(composingBase),
2048 @"composingExtent" : @(composingExtent),
2051 [_pendingDeltas addObject:deltaToFramework];
2053 if (_pendingDeltas.count == 1) {
2055 dispatch_async(dispatch_get_main_queue(), ^{
2057 if (strongSelf && strongSelf.pendingDeltas.count > 0) {
2058 NSDictionary* deltas = @{
2059 @"deltas" : strongSelf.pendingDeltas,
2062 [strongSelf.textInputDelegate flutterTextInputView:strongSelf
2063 updateEditingClient:strongSelf->_textInputClient
2065 [strongSelf.pendingDeltas removeAllObjects];
2072 return self.text.length > 0;
2075 - (void)insertText:(NSString*)text {
2076 if (
self.temporarilyDeletedComposedCharacter.length > 0 && text.length == 1 && !text.UTF8String &&
2077 [text characterAtIndex:0] == [
self.temporarilyDeletedComposedCharacter characterAtIndex:0]) {
2081 text =
self.temporarilyDeletedComposedCharacter;
2082 self.temporarilyDeletedComposedCharacter = nil;
2085 NSMutableArray<FlutterTextSelectionRect*>* copiedRects =
2086 [[NSMutableArray alloc] initWithCapacity:[_selectionRects count]];
2088 @"Expected a FlutterTextPosition for position (got %@).",
2091 for (NSUInteger i = 0; i < [_selectionRects count]; i++) {
2092 NSUInteger rectPosition = _selectionRects[i].position;
2093 if (rectPosition == insertPosition) {
2094 for (NSUInteger j = 0; j <= text.length; j++) {
2101 if (rectPosition > insertPosition) {
2102 rectPosition = rectPosition + text.length;
2111 _scribbleFocusStatus = FlutterScribbleFocusStatusUnfocused;
2112 [
self resetScribbleInteractionStatusIfEnding];
2113 self.selectionRects = copiedRects;
2115 [
self replaceRange:_selectedTextRange withText:text];
2118 - (UITextPlaceholder*)insertTextPlaceholderWithSize:(CGSize)size API_AVAILABLE(ios(13.0)) {
2119 [
self.textInputDelegate flutterTextInputView:self
2120 insertTextPlaceholderWithSize:size
2121 withClient:_textInputClient];
2126 - (void)removeTextPlaceholder:(UITextPlaceholder*)textPlaceholder API_AVAILABLE(ios(13.0)) {
2128 [
self.textInputDelegate flutterTextInputView:self removeTextPlaceholder:_textInputClient];
2131 - (void)deleteBackward {
2133 _scribbleFocusStatus = FlutterScribbleFocusStatusUnfocused;
2134 [
self resetScribbleInteractionStatusIfEnding];
2151 if (oldRange.location > 0) {
2152 NSRange newRange = NSMakeRange(oldRange.location - 1, 1);
2156 NSRange charRange = fml::RangeForCharacterAtIndex(
self.text, oldRange.location - 1);
2157 if (
IsEmoji(
self.text, charRange)) {
2158 newRange = NSMakeRange(charRange.location, oldRange.location - charRange.location);
2170 NSString* deletedText = [
self.text substringWithRange:_selectedTextRange.range];
2171 NSRange deleteFirstCharacterRange = fml::RangeForCharacterAtIndex(deletedText, 0);
2172 self.temporarilyDeletedComposedCharacter =
2173 [deletedText substringWithRange:deleteFirstCharacterRange];
2175 [
self replaceRange:_selectedTextRange withText:@""];
2179 - (void)postAccessibilityNotification:(UIAccessibilityNotifications)notification target:(
id)target {
2180 UIAccessibilityPostNotification(notification, target);
2183 - (void)accessibilityElementDidBecomeFocused {
2184 if ([
self accessibilityElementIsFocused]) {
2188 FML_DCHECK(_backingTextInputAccessibilityObject);
2189 [
self postAccessibilityNotification:UIAccessibilityScreenChangedNotification
2190 target:_backingTextInputAccessibilityObject];
2194 - (BOOL)accessibilityElementsHidden {
2195 return !_accessibilityEnabled;
2204 #pragma mark - Key Events Handling
2205 - (void)pressesBegan:(NSSet<UIPress*>*)presses
2206 withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
2207 [_textInputPlugin.viewController pressesBegan:presses withEvent:event];
2210 - (void)pressesChanged:(NSSet<UIPress*>*)presses
2211 withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
2212 [_textInputPlugin.viewController pressesChanged:presses withEvent:event];
2215 - (void)pressesEnded:(NSSet<UIPress*>*)presses
2216 withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
2217 [_textInputPlugin.viewController pressesEnded:presses withEvent:event];
2220 - (void)pressesCancelled:(NSSet<UIPress*>*)presses
2221 withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
2222 [_textInputPlugin.viewController pressesCancelled:presses withEvent:event];
2251 - (BOOL)accessibilityElementsHidden {
2258 - (void)enableActiveViewAccessibility;
2275 - (void)enableActiveViewAccessibility {
2276 [
self.target enableActiveViewAccessibility];
2283 @property(nonatomic, readonly)
2284 NSMutableDictionary<NSString*, FlutterTextInputView*>* autofillContext;
2289 @property(nonatomic, strong) UIView* keyboardViewContainer;
2290 @property(nonatomic, strong) UIView* keyboardView;
2291 @property(nonatomic, strong) UIView* cachedFirstResponder;
2292 @property(nonatomic, assign) CGRect keyboardRect;
2293 @property(nonatomic, assign) CGFloat previousPointerYPosition;
2294 @property(nonatomic, assign) CGFloat pointerYVelocity;
2298 NSTimer* _enableFlutterTextInputViewAccessibilityTimer;
2302 self = [
super init];
2305 _textInputDelegate = textInputDelegate;
2306 _autofillContext = [[NSMutableDictionary alloc] init];
2308 _scribbleElements = [[NSMutableDictionary alloc] init];
2309 _keyboardViewContainer = [[UIView alloc] init];
2311 [[NSNotificationCenter defaultCenter] addObserver:self
2312 selector:@selector(handleKeyboardWillShow:)
2313 name:UIKeyboardWillShowNotification
2320 - (void)handleKeyboardWillShow:(NSNotification*)notification {
2321 NSDictionary* keyboardInfo = [notification userInfo];
2322 NSValue* keyboardFrameEnd = [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey];
2323 _keyboardRect = [keyboardFrameEnd CGRectValue];
2327 [
self hideTextInput];
2330 - (void)removeEnableFlutterTextInputViewAccessibilityTimer {
2331 if (_enableFlutterTextInputViewAccessibilityTimer) {
2332 [_enableFlutterTextInputViewAccessibilityTimer invalidate];
2333 _enableFlutterTextInputViewAccessibilityTimer = nil;
2337 - (UIView<UITextInput>*)textInputView {
2342 NSString* method = call.
method;
2345 [
self showTextInput];
2347 }
else if ([method isEqualToString:
kHideMethod]) {
2348 [
self hideTextInput];
2351 [
self setTextInputClient:[args[0] intValue] withConfiguration:args[1]];
2355 [
self setPlatformViewTextInputClient];
2358 [
self setTextInputEditingState:args];
2361 [
self clearTextInputClient];
2364 [
self setEditableSizeAndTransform:args];
2367 [
self updateMarkedRect:args];
2370 [
self triggerAutofillSave:[args boolValue]];
2376 [
self setSelectionRects:args];
2379 [
self setSelectionRects:args];
2382 [
self startLiveTextInput];
2385 [
self updateConfig:args];
2388 CGFloat pointerY = (CGFloat)[args[
@"pointerY"] doubleValue];
2389 [
self handlePointerMove:pointerY];
2392 CGFloat pointerY = (CGFloat)[args[
@"pointerY"] doubleValue];
2393 [
self handlePointerUp:pointerY];
2400 - (void)handlePointerUp:(CGFloat)pointerY {
2401 if (_keyboardView.superview != nil) {
2405 CGFloat screenHeight = screen.bounds.size.height;
2406 CGFloat keyboardHeight = _keyboardRect.size.height;
2408 BOOL shouldDismissKeyboardBasedOnVelocity = _pointerYVelocity < 0;
2409 [UIView animateWithDuration:kKeyboardAnimationTimeToCompleteion
2411 double keyboardDestination =
2412 shouldDismissKeyboardBasedOnVelocity ? screenHeight : screenHeight - keyboardHeight;
2413 _keyboardViewContainer.frame = CGRectMake(
2414 0, keyboardDestination, _viewController.flutterScreenIfViewLoaded.bounds.size.width,
2415 _keyboardViewContainer.frame.size.height);
2417 completion:^(BOOL finished) {
2418 if (shouldDismissKeyboardBasedOnVelocity) {
2419 [
self.textInputDelegate flutterTextInputView:self.activeView
2420 didResignFirstResponderWithTextInputClient:self.activeView.textInputClient];
2421 [
self dismissKeyboardScreenshot];
2423 [
self showKeyboardAndRemoveScreenshot];
2429 - (void)dismissKeyboardScreenshot {
2430 for (UIView* subView in _keyboardViewContainer.subviews) {
2431 [subView removeFromSuperview];
2435 - (void)showKeyboardAndRemoveScreenshot {
2436 [UIView setAnimationsEnabled:NO];
2437 [_cachedFirstResponder becomeFirstResponder];
2441 dispatch_get_main_queue(), ^{
2442 [UIView setAnimationsEnabled:YES];
2443 [
self dismissKeyboardScreenshot];
2447 - (void)handlePointerMove:(CGFloat)pointerY {
2450 CGFloat screenHeight = screen.bounds.size.height;
2451 CGFloat keyboardHeight = _keyboardRect.size.height;
2452 if (screenHeight - keyboardHeight <= pointerY) {
2454 if (_keyboardView.superview == nil) {
2456 [
self takeKeyboardScreenshotAndDisplay];
2457 [
self hideKeyboardWithoutAnimationAndAvoidCursorDismissUpdate];
2459 [
self setKeyboardContainerHeight:pointerY];
2460 _pointerYVelocity = _previousPointerYPosition - pointerY;
2463 if (_keyboardView.superview != nil) {
2465 _keyboardViewContainer.frame = _keyboardRect;
2466 _pointerYVelocity = _previousPointerYPosition - pointerY;
2469 _previousPointerYPosition = pointerY;
2472 - (void)setKeyboardContainerHeight:(CGFloat)pointerY {
2473 CGRect frameRect = _keyboardRect;
2474 frameRect.origin.y = pointerY;
2475 _keyboardViewContainer.frame = frameRect;
2478 - (void)hideKeyboardWithoutAnimationAndAvoidCursorDismissUpdate {
2479 [UIView setAnimationsEnabled:NO];
2480 _cachedFirstResponder = UIApplication.sharedApplication.keyWindow.flutterFirstResponder;
2481 _activeView.preventCursorDismissWhenResignFirstResponder = YES;
2482 [_cachedFirstResponder resignFirstResponder];
2483 _activeView.preventCursorDismissWhenResignFirstResponder = NO;
2484 [UIView setAnimationsEnabled:YES];
2487 - (void)takeKeyboardScreenshotAndDisplay {
2490 UIView* keyboardSnap = [screen snapshotViewAfterScreenUpdates:YES];
2491 keyboardSnap = [keyboardSnap resizableSnapshotViewFromRect:_keyboardRect
2492 afterScreenUpdates:YES
2493 withCapInsets:UIEdgeInsetsZero];
2494 _keyboardView = keyboardSnap;
2495 [_keyboardViewContainer addSubview:_keyboardView];
2496 if (_keyboardViewContainer.superview == nil) {
2497 [UIApplication.sharedApplication.delegate.window.rootViewController.view
2498 addSubview:_keyboardViewContainer];
2500 _keyboardViewContainer.layer.zPosition = NSIntegerMax;
2501 _keyboardViewContainer.frame = _keyboardRect;
2504 - (void)setEditableSizeAndTransform:(NSDictionary*)dictionary {
2505 NSArray* transform = dictionary[@"transform"];
2506 [_activeView setEditableTransform:transform];
2507 const int leftIndex = 12;
2508 const int topIndex = 13;
2512 CGRectMake([transform[leftIndex] intValue], [transform[topIndex] intValue],
2513 [dictionary[
@"width"] intValue], [dictionary[
@"height"] intValue]);
2515 CGRectMake(0, 0, [dictionary[
@"width"] intValue], [dictionary[
@"height"] intValue]);
2516 _activeView.tintColor = [UIColor clearColor];
2521 if (@available(iOS 17, *)) {
2529 CGRectMake([transform[leftIndex] intValue], [transform[topIndex] intValue], 0, 0);
2534 - (void)updateMarkedRect:(NSDictionary*)dictionary {
2535 NSAssert(dictionary[
@"x"] != nil && dictionary[
@"y"] != nil && dictionary[
@"width"] != nil &&
2536 dictionary[
@"height"] != nil,
2537 @"Expected a dictionary representing a CGRect, got %@", dictionary);
2538 CGRect rect = CGRectMake([dictionary[
@"x"] doubleValue], [dictionary[
@"y"] doubleValue],
2539 [dictionary[
@"width"] doubleValue], [dictionary[
@"height"] doubleValue]);
2540 _activeView.markedRect = rect.size.width < 0 && rect.size.height < 0 ?
kInvalidFirstRect : rect;
2543 - (void)setSelectionRects:(NSArray*)encodedRects {
2544 NSMutableArray<FlutterTextSelectionRect*>* rectsAsRect =
2545 [[NSMutableArray alloc] initWithCapacity:[encodedRects count]];
2546 for (NSUInteger i = 0; i < [encodedRects count]; i++) {
2547 NSArray<NSNumber*>* encodedRect = encodedRects[i];
2549 selectionRectWithRect:CGRectMake([encodedRect[0] floatValue],
2550 [encodedRect[1] floatValue],
2551 [encodedRect[2] floatValue],
2552 [encodedRect[3] floatValue])
2553 position:[encodedRect[4] unsignedIntegerValue]
2554 writingDirection:[encodedRect[5] unsignedIntegerValue] == 1
2555 ? NSWritingDirectionLeftToRight
2556 : NSWritingDirectionRightToLeft]];
2562 _activeView.selectionRects = rectsAsRect;
2565 - (void)startLiveTextInput {
2566 if (@available(iOS 15.0, *)) {
2567 if (_activeView == nil || !_activeView.isFirstResponder) {
2570 [_activeView captureTextFromCamera:nil];
2574 - (void)showTextInput {
2575 _activeView.viewResponder = _viewResponder;
2576 [
self addToInputParentViewIfNeeded:_activeView];
2585 if (!_enableFlutterTextInputViewAccessibilityTimer) {
2586 _enableFlutterTextInputViewAccessibilityTimer =
2587 [NSTimer scheduledTimerWithTimeInterval:kUITextInputAccessibilityEnablingDelaySeconds
2589 selector:@selector(enableActiveViewAccessibility)
2593 [_activeView becomeFirstResponder];
2596 - (void)enableActiveViewAccessibility {
2597 if (_activeView.isFirstResponder) {
2598 _activeView.accessibilityEnabled = YES;
2600 [
self removeEnableFlutterTextInputViewAccessibilityTimer];
2603 - (void)hideTextInput {
2604 [
self removeEnableFlutterTextInputViewAccessibilityTimer];
2605 _activeView.accessibilityEnabled = NO;
2606 [_activeView resignFirstResponder];
2607 [_activeView removeFromSuperview];
2608 [_inputHider removeFromSuperview];
2611 - (void)triggerAutofillSave:(BOOL)saveEntries {
2612 [_activeView resignFirstResponder];
2617 [
self cleanUpViewHierarchy:YES clearText:YES delayRemoval:NO];
2618 [_autofillContext removeAllObjects];
2619 [
self changeInputViewsAutofillVisibility:YES];
2621 [_autofillContext removeAllObjects];
2624 [
self cleanUpViewHierarchy:YES clearText:!saveEntries delayRemoval:NO];
2625 [
self addToInputParentViewIfNeeded:_activeView];
2628 - (void)setPlatformViewTextInputClient {
2632 [
self removeEnableFlutterTextInputViewAccessibilityTimer];
2633 _activeView.accessibilityEnabled = NO;
2634 [_activeView removeFromSuperview];
2635 [_inputHider removeFromSuperview];
2638 - (void)setTextInputClient:(
int)client withConfiguration:(NSDictionary*)configuration {
2639 [
self resetAllClientIds];
2642 [
self changeInputViewsAutofillVisibility:NO];
2646 case kFlutterAutofillTypeNone:
2647 self.activeView = [
self createInputViewWith:configuration];
2649 case kFlutterAutofillTypeRegular:
2652 self.activeView = [
self updateAndShowAutofillViews:nil
2653 focusedField:configuration
2654 isPasswordRelated:NO];
2656 case kFlutterAutofillTypePassword:
2657 self.activeView = [
self updateAndShowAutofillViews:configuration[kAssociatedAutofillFields]
2658 focusedField:configuration
2659 isPasswordRelated:YES];
2662 [_activeView setTextInputClient:client];
2663 [_activeView reloadInputViews];
2675 [
self cleanUpViewHierarchy:NO clearText:YES delayRemoval:YES];
2686 [_autofillContext removeObjectForKey:autofillId];
2689 [newView configureWithDictionary:configuration];
2690 [
self addToInputParentViewIfNeeded:newView];
2694 if (autofillId &&
AutofillTypeOf(field) == kFlutterAutofillTypeNone) {
2695 [_autofillContext removeObjectForKey:autofillId];
2702 focusedField:(NSDictionary*)focusedField
2703 isPasswordRelated:(BOOL)isPassword {
2706 NSAssert(focusedId,
@"autofillId must not be null for the focused field: %@", focusedField);
2711 focused = [
self getOrCreateAutofillableView:focusedField isPasswordAutofill:isPassword];
2712 [_autofillContext removeObjectForKey:focusedId];
2715 for (NSDictionary* field in fields) {
2717 NSAssert(autofillId,
@"autofillId must not be null for field: %@", field);
2719 BOOL hasHints =
AutofillTypeOf(field) != kFlutterAutofillTypeNone;
2720 BOOL isFocused = [focusedId isEqualToString:autofillId];
2723 focused = [
self getOrCreateAutofillableView:field isPasswordAutofill:isPassword];
2728 _autofillContext[autofillId] = isFocused ? focused
2729 : [
self getOrCreateAutofillableView:field
2730 isPasswordAutofill:isPassword];
2733 [_autofillContext removeObjectForKey:autofillId];
2737 NSAssert(focused,
@"The current focused input view must not be nil.");
2747 isPasswordAutofill:(BOOL)needsPasswordAutofill {
2753 inputView = [inputView initWithOwner:self];
2754 [
self addToInputParentViewIfNeeded:inputView];
2757 [inputView configureWithDictionary:field];
2762 - (UIView*)hostView {
2764 NSAssert(host !=
nullptr,
2765 @"The application must have a host view since the keyboard client "
2766 @"must be part of the responder chain to function. The host view controller is %@",
2772 - (NSArray<UIView*>*)textInputViews {
2773 return _inputHider.subviews;
2786 - (void)cleanUpViewHierarchy:(BOOL)includeActiveView
2787 clearText:(BOOL)clearText
2788 delayRemoval:(BOOL)delayRemoval {
2789 for (UIView* view in
self.textInputViews) {
2791 (includeActiveView || view != _activeView)) {
2793 if (_autofillContext[inputView.autofillId] != view) {
2795 [inputView replaceRangeLocal:NSMakeRange(0, inputView.text.length) withText:@""];
2798 [inputView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.1];
2800 [inputView removeFromSuperview];
2809 - (void)changeInputViewsAutofillVisibility:(BOOL)newVisibility {
2810 for (UIView* view in
self.textInputViews) {
2813 inputView.isVisibleToAutofill = newVisibility;
2825 - (void)resetAllClientIds {
2826 for (UIView* view in
self.textInputViews) {
2829 [inputView setTextInputClient:0];
2835 if (![inputView isDescendantOfView:_inputHider]) {
2836 [_inputHider addSubview:inputView];
2845 UIView* parentView =
self.hostView;
2846 if (_inputHider.superview != parentView) {
2847 [parentView addSubview:_inputHider];
2851 - (void)setTextInputEditingState:(NSDictionary*)state {
2852 [_activeView setTextInputState:state];
2855 - (void)clearTextInputClient {
2856 [_activeView setTextInputClient:0];
2857 _activeView.frame = CGRectZero;
2860 - (void)updateConfig:(NSDictionary*)dictionary {
2861 BOOL isSecureTextEntry = [dictionary[kSecureTextEntry] boolValue];
2862 for (UIView* view in
self.textInputViews) {
2869 if (inputView.isSecureTextEntry != isSecureTextEntry) {
2870 inputView.secureTextEntry = isSecureTextEntry;
2871 [inputView reloadInputViews];
2877 #pragma mark UIIndirectScribbleInteractionDelegate
2879 - (BOOL)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2880 isElementFocused:(UIScribbleElementIdentifier)elementIdentifier
2881 API_AVAILABLE(ios(14.0)) {
2882 return _activeView.scribbleFocusStatus == FlutterScribbleFocusStatusFocused;
2885 - (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2886 focusElementIfNeeded:(UIScribbleElementIdentifier)elementIdentifier
2887 referencePoint:(CGPoint)focusReferencePoint
2888 completion:(
void (^)(UIResponder<UITextInput>* focusedInput))completion
2889 API_AVAILABLE(ios(14.0)) {
2890 _activeView.scribbleFocusStatus = FlutterScribbleFocusStatusFocusing;
2891 [_indirectScribbleDelegate flutterTextInputPlugin:self
2892 focusElement:elementIdentifier
2893 atPoint:focusReferencePoint
2894 result:^(id _Nullable result) {
2895 _activeView.scribbleFocusStatus =
2896 FlutterScribbleFocusStatusFocused;
2897 completion(_activeView);
2901 - (BOOL)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2902 shouldDelayFocusForElement:(UIScribbleElementIdentifier)elementIdentifier
2903 API_AVAILABLE(ios(14.0)) {
2907 - (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2908 willBeginWritingInElement:(UIScribbleElementIdentifier)elementIdentifier
2909 API_AVAILABLE(ios(14.0)) {
2912 - (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2913 didFinishWritingInElement:(UIScribbleElementIdentifier)elementIdentifier
2914 API_AVAILABLE(ios(14.0)) {
2917 - (CGRect)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2918 frameForElement:(UIScribbleElementIdentifier)elementIdentifier
2919 API_AVAILABLE(ios(14.0)) {
2920 NSValue* elementValue = [_scribbleElements objectForKey:elementIdentifier];
2921 if (elementValue == nil) {
2924 return [elementValue CGRectValue];
2927 - (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2928 requestElementsInRect:(CGRect)rect
2930 (
void (^)(NSArray<UIScribbleElementIdentifier>* elements))completion
2931 API_AVAILABLE(ios(14.0)) {
2932 [_indirectScribbleDelegate
2933 flutterTextInputPlugin:self
2934 requestElementsInRect:rect
2935 result:^(id _Nullable result) {
2936 NSMutableArray<UIScribbleElementIdentifier>* elements =
2937 [[NSMutableArray alloc] init];
2938 if ([result isKindOfClass:[NSArray class]]) {
2939 for (NSArray* elementArray in result) {
2940 [elements addObject:elementArray[0]];
2943 valueWithCGRect:CGRectMake(
2944 [elementArray[1] floatValue],
2945 [elementArray[2] floatValue],
2946 [elementArray[3] floatValue],
2947 [elementArray[4] floatValue])]
2948 forKey:elementArray[0]];
2951 completion(elements);
2955 #pragma mark - Methods related to Scribble support
2959 if (@available(iOS 14.0, *)) {
2961 if (parentView != nil) {
2962 UIIndirectScribbleInteraction* scribbleInteraction = [[UIIndirectScribbleInteraction alloc]
2963 initWithDelegate:(id<UIIndirectScribbleInteractionDelegate>)self];
2964 [parentView addInteraction:scribbleInteraction];
2971 - (void)resetViewResponder {
2972 _viewResponder = nil;
2976 #pragma mark FlutterKeySecondaryResponder
2991 - (
id)flutterFirstResponder {
2992 if (
self.isFirstResponder) {
2995 for (UIView* subView in
self.subviews) {
2996 UIView* firstResponder = subView.flutterFirstResponder;
2997 if (firstResponder) {
2998 return firstResponder;