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];
835 _pendingDeltas = [[NSMutableArray alloc] init];
838 _editableTransform = CATransform3D();
841 _autocapitalizationType = UITextAutocapitalizationTypeSentences;
842 _autocorrectionType = UITextAutocorrectionTypeDefault;
843 _spellCheckingType = UITextSpellCheckingTypeDefault;
844 _enablesReturnKeyAutomatically = NO;
845 _keyboardAppearance = UIKeyboardAppearanceDefault;
846 _keyboardType = UIKeyboardTypeDefault;
847 _returnKeyType = UIReturnKeyDone;
848 _secureTextEntry = NO;
849 _enableDeltaModel = NO;
851 _accessibilityEnabled = NO;
852 _smartQuotesType = UITextSmartQuotesTypeYes;
853 _smartDashesType = UITextSmartDashesTypeYes;
854 _selectionRects = [[NSArray alloc] init];
856 if (@available(iOS 14.0, *)) {
857 UIScribbleInteraction* interaction = [[UIScribbleInteraction alloc] initWithDelegate:self];
858 [
self addInteraction:interaction];
865 - (void)configureWithDictionary:(NSDictionary*)configuration {
866 NSDictionary* inputType = configuration[kKeyboardType];
868 NSDictionary* autofill = configuration[kAutofillProperties];
870 self.secureTextEntry = [configuration[kSecureTextEntry] boolValue];
871 self.enableDeltaModel = [configuration[kEnableDeltaModel] boolValue];
878 NSString* smartDashesType = configuration[kSmartDashesType];
880 bool smartDashesIsDisabled = smartDashesType && [smartDashesType isEqualToString:@"0"];
881 self.smartDashesType = smartDashesIsDisabled ? UITextSmartDashesTypeNo : UITextSmartDashesTypeYes;
882 NSString* smartQuotesType = configuration[kSmartQuotesType];
884 bool smartQuotesIsDisabled = smartQuotesType && [smartQuotesType isEqualToString:@"0"];
885 self.smartQuotesType = smartQuotesIsDisabled ? UITextSmartQuotesTypeNo : UITextSmartQuotesTypeYes;
887 self.keyboardAppearance = UIKeyboardAppearanceDark;
889 self.keyboardAppearance = UIKeyboardAppearanceLight;
891 self.keyboardAppearance = UIKeyboardAppearanceDefault;
893 NSString* autocorrect = configuration[kAutocorrectionType];
894 bool autocorrectIsDisabled = autocorrect && ![autocorrect boolValue];
895 self.autocorrectionType =
896 autocorrectIsDisabled ? UITextAutocorrectionTypeNo : UITextAutocorrectionTypeDefault;
897 self.spellCheckingType =
898 autocorrectIsDisabled ? UITextSpellCheckingTypeNo : UITextSpellCheckingTypeDefault;
900 if (autofill == nil) {
901 self.textContentType =
@"";
904 [
self setTextInputState:autofill[kAutofillEditingValue]];
905 NSAssert(_autofillId,
@"The autofill configuration must contain an autofill id");
909 self.isVisibleToAutofill = autofill || _secureTextEntry;
912 - (UITextContentType)textContentType {
913 return _textContentType;
926 - (UIColor*)insertionPointColor {
927 return [UIColor clearColor];
930 - (UIColor*)selectionBarColor {
931 return [UIColor clearColor];
934 - (UIColor*)selectionHighlightColor {
935 return [UIColor clearColor];
938 - (UIInputViewController*)inputViewController {
953 - (BOOL)respondsToSelector:(
SEL)selector {
954 if (@available(iOS 17.0, *)) {
956 if (selector ==
@selector(insertionPointColor)) {
960 return [
super respondsToSelector:selector];
963 - (void)setTextInputClient:(
int)client {
964 _textInputClient = client;
968 - (UITextInteraction*)textInteraction
API_AVAILABLE(ios(13.0)) {
969 if (!_textInteraction) {
970 _textInteraction = [UITextInteraction textInteractionForMode:UITextInteractionModeEditable];
971 _textInteraction.textInput =
self;
973 return _textInteraction;
976 - (void)setTextInputState:(NSDictionary*)state {
977 if (@available(iOS 13.0, *)) {
984 [
self addInteraction:self.textInteraction];
988 NSString* newText = state[@"text"];
989 BOOL textChanged = ![
self.text isEqualToString:newText];
991 [
self.inputDelegate textWillChange:self];
992 [
self.text setString:newText];
994 NSInteger composingBase = [state[@"composingBase"] intValue];
995 NSInteger composingExtent = [state[@"composingExtent"] intValue];
996 NSRange composingRange = [
self clampSelection:NSMakeRange(MIN(composingBase, composingExtent),
997 ABS(composingBase - composingExtent))
1000 self.markedTextRange =
1003 NSRange selectedRange = [
self clampSelectionFromBase:[state[@"selectionBase"] intValue]
1004 extent:[state[@"selectionExtent"] intValue]
1007 NSRange oldSelectedRange = [(
FlutterTextRange*)
self.selectedTextRange range];
1008 if (!NSEqualRanges(selectedRange, oldSelectedRange)) {
1009 [
self.inputDelegate selectionWillChange:self];
1017 [
self.inputDelegate selectionDidChange:self];
1021 [
self.inputDelegate textDidChange:self];
1024 if (@available(iOS 13.0, *)) {
1025 if (_textInteraction) {
1026 [
self removeInteraction:_textInteraction];
1032 - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
1033 _scribbleFocusStatus = FlutterScribbleFocusStatusUnfocused;
1034 [
self resetScribbleInteractionStatusIfEnding];
1035 [
self.viewResponder touchesBegan:touches withEvent:event];
1038 - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
1039 [
self.viewResponder touchesMoved:touches withEvent:event];
1042 - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
1043 [
self.viewResponder touchesEnded:touches withEvent:event];
1046 - (void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event {
1047 [
self.viewResponder touchesCancelled:touches withEvent:event];
1050 - (void)touchesEstimatedPropertiesUpdated:(NSSet*)touches {
1051 [
self.viewResponder touchesEstimatedPropertiesUpdated:touches];
1061 - (NSRange)clampSelectionFromBase:(
int)selectionBase
1062 extent:(
int)selectionExtent
1063 forText:(NSString*)text {
1064 int loc = MIN(selectionBase, selectionExtent);
1065 int len = ABS(selectionExtent - selectionBase);
1066 return loc < 0 ? NSMakeRange(0, 0)
1067 : [
self clampSelection:NSMakeRange(loc, len) forText:
self.text];
1070 - (NSRange)clampSelection:(NSRange)range forText:(NSString*)text {
1071 NSUInteger start = MIN(MAX(range.location, 0), text.length);
1072 NSUInteger length = MIN(range.length, text.length - start);
1073 return NSMakeRange(start, length);
1076 - (BOOL)isVisibleToAutofill {
1077 return self.frame.size.width > 0 &&
self.frame.size.height > 0;
1085 - (void)setIsVisibleToAutofill:(BOOL)isVisibleToAutofill {
1088 self.frame = isVisibleToAutofill ? CGRectMake(0, 0, 1, 1) : CGRectZero;
1091 #pragma mark UIScribbleInteractionDelegate
1096 if (@available(iOS 14.0, *)) {
1097 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
1104 - (void)scribbleInteractionWillBeginWriting:(UIScribbleInteraction*)interaction
1105 API_AVAILABLE(ios(14.0)) {
1107 [
self.textInputDelegate flutterTextInputViewScribbleInteractionBegan:self];
1110 - (void)scribbleInteractionDidFinishWriting:(UIScribbleInteraction*)interaction
1111 API_AVAILABLE(ios(14.0)) {
1113 [
self.textInputDelegate flutterTextInputViewScribbleInteractionFinished:self];
1116 - (BOOL)scribbleInteraction:(UIScribbleInteraction*)interaction
1117 shouldBeginAtLocation:(CGPoint)location API_AVAILABLE(ios(14.0)) {
1121 - (BOOL)scribbleInteractionShouldDelayFocus:(UIScribbleInteraction*)interaction
1122 API_AVAILABLE(ios(14.0)) {
1126 #pragma mark - UIResponder Overrides
1128 - (BOOL)canBecomeFirstResponder {
1133 return _textInputClient != 0;
1136 - (BOOL)resignFirstResponder {
1137 BOOL success = [
super resignFirstResponder];
1139 if (!_preventCursorDismissWhenResignFirstResponder) {
1140 [
self.textInputDelegate flutterTextInputView:self
1141 didResignFirstResponderWithTextInputClient:_textInputClient];
1147 - (BOOL)canPerformAction:(
SEL)action withSender:(
id)sender {
1153 if (action ==
@selector(paste:)) {
1155 return [UIPasteboard generalPasteboard].string != nil;
1158 return [
super canPerformAction:action withSender:sender];
1161 #pragma mark - UIResponderStandardEditActions Overrides
1163 - (void)cut:(
id)sender {
1164 [UIPasteboard generalPasteboard].string = [
self textInRange:_selectedTextRange];
1165 [
self replaceRange:_selectedTextRange withText:@""];
1168 - (void)copy:(
id)sender {
1169 [UIPasteboard generalPasteboard].string = [
self textInRange:_selectedTextRange];
1172 - (void)paste:(
id)sender {
1173 NSString* pasteboardString = [UIPasteboard generalPasteboard].string;
1174 if (pasteboardString != nil) {
1175 [
self insertText:pasteboardString];
1179 - (void)delete:(
id)sender {
1180 [
self replaceRange:_selectedTextRange withText:@""];
1183 - (void)selectAll:(
id)sender {
1184 [
self setSelectedTextRange:[
self textRangeFromPosition:[
self beginningOfDocument]
1185 toPosition:[
self endOfDocument]]];
1188 #pragma mark - UITextInput Overrides
1190 - (id<UITextInputTokenizer>)tokenizer {
1191 if (_tokenizer == nil) {
1198 return [_selectedTextRange copy];
1202 - (void)setSelectedTextRangeLocal:(UITextRange*)selectedTextRange {
1207 rangeWithNSRange:fml::RangeForCharactersInRange(self.text, flutterTextRange.range)] copy];
1214 - (void)setSelectedTextRange:(UITextRange*)selectedTextRange {
1219 [
self setSelectedTextRangeLocal:selectedTextRange];
1221 if (_enableDeltaModel) {
1222 [
self updateEditingStateWithDelta:flutter::TextEditingDelta([
self.text UTF8String])];
1224 [
self updateEditingState];
1228 _scribbleFocusStatus == FlutterScribbleFocusStatusFocused) {
1232 if (flutterTextRange.
range.length > 0) {
1233 [
self.textInputDelegate flutterTextInputView:self showToolbar:_textInputClient];
1237 [
self resetScribbleInteractionStatusIfEnding];
1240 - (id)insertDictationResultPlaceholder {
1244 - (void)removeDictationResultPlaceholder:(
id)placeholder willInsertResult:(BOOL)willInsertResult {
1247 - (NSString*)textInRange:(UITextRange*)range {
1252 @"Expected a FlutterTextRange for range (got %@).", [range
class]);
1254 NSAssert(textRange.location != NSNotFound,
@"Expected a valid text range.");
1256 NSUInteger location = MIN(textRange.location,
self.text.length);
1257 NSUInteger length = MIN(
self.text.length - location, textRange.length);
1258 NSRange safeRange = NSMakeRange(location, length);
1259 return [
self.text substringWithRange:safeRange];
1264 - (void)replaceRangeLocal:(NSRange)range withText:(NSString*)text {
1265 [
self.text replaceCharactersInRange:[
self clampSelection:range forText:self.text]
1271 const NSRange newSelectionRange =
1272 [
self clampSelection:NSMakeRange(range.location + text.length, 0) forText:self.text];
1275 self.markedTextRange = nil;
1278 - (void)replaceRange:(UITextRange*)range withText:(NSString*)text {
1279 NSString* textBeforeChange = [
self.text copy];
1281 [
self replaceRangeLocal:replaceRange withText:text];
1282 if (_enableDeltaModel) {
1283 NSRange nextReplaceRange = [
self clampSelection:replaceRange forText:textBeforeChange];
1284 [
self updateEditingStateWithDelta:flutter::TextEditingDelta(
1285 [textBeforeChange UTF8String],
1287 nextReplaceRange.location,
1288 nextReplaceRange.location + nextReplaceRange.length),
1289 [text UTF8String])];
1291 [
self updateEditingState];
1295 - (BOOL)shouldChangeTextInRange:(UITextRange*)range replacementText:(NSString*)text {
1298 self.temporarilyDeletedComposedCharacter = nil;
1300 if (
self.
returnKeyType == UIReturnKeyDefault && [text isEqualToString:
@"\n"]) {
1301 [
self.textInputDelegate flutterTextInputView:self
1302 performAction:FlutterTextInputActionNewline
1303 withClient:_textInputClient];
1307 if ([text isEqualToString:
@"\n"]) {
1308 FlutterTextInputAction action;
1310 case UIReturnKeyDefault:
1311 action = FlutterTextInputActionUnspecified;
1313 case UIReturnKeyDone:
1314 action = FlutterTextInputActionDone;
1317 action = FlutterTextInputActionGo;
1319 case UIReturnKeySend:
1320 action = FlutterTextInputActionSend;
1322 case UIReturnKeySearch:
1323 case UIReturnKeyGoogle:
1324 case UIReturnKeyYahoo:
1325 action = FlutterTextInputActionSearch;
1327 case UIReturnKeyNext:
1328 action = FlutterTextInputActionNext;
1330 case UIReturnKeyContinue:
1331 action = FlutterTextInputActionContinue;
1333 case UIReturnKeyJoin:
1334 action = FlutterTextInputActionJoin;
1336 case UIReturnKeyRoute:
1337 action = FlutterTextInputActionRoute;
1339 case UIReturnKeyEmergencyCall:
1340 action = FlutterTextInputActionEmergencyCall;
1344 [
self.textInputDelegate flutterTextInputView:self
1345 performAction:action
1346 withClient:_textInputClient];
1355 - (void)setMarkedText:(NSString*)markedText selectedRange:(NSRange)markedSelectedRange {
1356 NSString* textBeforeChange = [
self.text copy];
1359 _scribbleFocusStatus != FlutterScribbleFocusStatusUnfocused) {
1363 if (markedText == nil) {
1368 const NSRange& actualReplacedRange = currentMarkedTextRange && !currentMarkedTextRange.isEmpty
1369 ? currentMarkedTextRange.
range
1373 [
self.text replaceCharactersInRange:actualReplacedRange withString:markedText];
1375 const NSRange newMarkedRange = NSMakeRange(actualReplacedRange.location, markedText.length);
1376 self.markedTextRange =
1379 [
self setSelectedTextRangeLocal:
1381 rangeWithNSRange:[
self clampSelection:NSMakeRange(markedSelectedRange.location +
1382 newMarkedRange.location,
1383 markedSelectedRange.length)
1384 forText:self.text]]];
1385 if (_enableDeltaModel) {
1386 NSRange nextReplaceRange = [
self clampSelection:actualReplacedRange forText:textBeforeChange];
1387 [
self updateEditingStateWithDelta:flutter::TextEditingDelta(
1388 [textBeforeChange UTF8String],
1390 nextReplaceRange.location,
1391 nextReplaceRange.location + nextReplaceRange.length),
1392 [markedText UTF8String])];
1394 [
self updateEditingState];
1398 - (void)unmarkText {
1402 self.markedTextRange = nil;
1403 if (_enableDeltaModel) {
1404 [
self updateEditingStateWithDelta:flutter::TextEditingDelta([
self.text UTF8String])];
1406 [
self updateEditingState];
1410 - (UITextRange*)textRangeFromPosition:(UITextPosition*)fromPosition
1411 toPosition:(UITextPosition*)toPosition {
1414 if (toIndex >= fromIndex) {
1427 - (NSUInteger)decrementOffsetPosition:(NSUInteger)position {
1428 return fml::RangeForCharacterAtIndex(
self.text, MAX(0, position - 1)).location;
1431 - (NSUInteger)incrementOffsetPosition:(NSUInteger)position {
1432 NSRange charRange = fml::RangeForCharacterAtIndex(
self.text, position);
1433 return MIN(position + charRange.length,
self.text.length);
1436 - (UITextPosition*)positionFromPosition:(UITextPosition*)position offset:(NSInteger)offset {
1439 NSInteger newLocation = (NSInteger)offsetPosition + offset;
1440 if (newLocation < 0 || newLocation > (NSInteger)
self.text.length) {
1449 for (NSInteger i = 0; i < offset && offsetPosition <
self.text.length; ++i) {
1450 offsetPosition = [
self incrementOffsetPosition:offsetPosition];
1453 for (NSInteger i = 0; i < ABS(offset) && offsetPosition > 0; ++i) {
1454 offsetPosition = [
self decrementOffsetPosition:offsetPosition];
1460 - (UITextPosition*)positionFromPosition:(UITextPosition*)position
1461 inDirection:(UITextLayoutDirection)direction
1462 offset:(NSInteger)offset {
1464 switch (direction) {
1465 case UITextLayoutDirectionLeft:
1466 case UITextLayoutDirectionUp:
1467 return [
self positionFromPosition:position offset:offset * -1];
1468 case UITextLayoutDirectionRight:
1469 case UITextLayoutDirectionDown:
1470 return [
self positionFromPosition:position offset:1];
1474 - (UITextPosition*)beginningOfDocument {
1478 - (UITextPosition*)endOfDocument {
1480 affinity:UITextStorageDirectionBackward];
1483 - (NSComparisonResult)comparePosition:(UITextPosition*)position toPosition:(UITextPosition*)other {
1486 if (positionIndex < otherIndex) {
1487 return NSOrderedAscending;
1489 if (positionIndex > otherIndex) {
1490 return NSOrderedDescending;
1494 if (positionAffinity == otherAffinity) {
1495 return NSOrderedSame;
1497 if (positionAffinity == UITextStorageDirectionBackward) {
1499 return NSOrderedAscending;
1502 return NSOrderedDescending;
1505 - (NSInteger)offsetFromPosition:(UITextPosition*)from toPosition:(UITextPosition*)toPosition {
1509 - (UITextPosition*)positionWithinRange:(UITextRange*)range
1510 farthestInDirection:(UITextLayoutDirection)direction {
1512 UITextStorageDirection affinity;
1513 switch (direction) {
1514 case UITextLayoutDirectionLeft:
1515 case UITextLayoutDirectionUp:
1517 affinity = UITextStorageDirectionForward;
1519 case UITextLayoutDirectionRight:
1520 case UITextLayoutDirectionDown:
1522 affinity = UITextStorageDirectionBackward;
1528 - (UITextRange*)characterRangeByExtendingPosition:(UITextPosition*)position
1529 inDirection:(UITextLayoutDirection)direction {
1531 NSUInteger startIndex;
1532 NSUInteger endIndex;
1533 switch (direction) {
1534 case UITextLayoutDirectionLeft:
1535 case UITextLayoutDirectionUp:
1536 startIndex = [
self decrementOffsetPosition:positionIndex];
1537 endIndex = positionIndex;
1539 case UITextLayoutDirectionRight:
1540 case UITextLayoutDirectionDown:
1541 startIndex = positionIndex;
1542 endIndex = [
self incrementOffsetPosition:positionIndex];
1548 #pragma mark - UITextInput text direction handling
1550 - (UITextWritingDirection)baseWritingDirectionForPosition:(UITextPosition*)position
1551 inDirection:(UITextStorageDirection)direction {
1553 return UITextWritingDirectionNatural;
1556 - (void)setBaseWritingDirection:(UITextWritingDirection)writingDirection
1557 forRange:(UITextRange*)range {
1561 #pragma mark - UITextInput cursor, selection rect handling
1563 - (void)setMarkedRect:(CGRect)markedRect {
1564 _markedRect = markedRect;
1571 - (void)setEditableTransform:(NSArray*)matrix {
1572 CATransform3D* transform = &_editableTransform;
1574 transform->m11 = [matrix[0] doubleValue];
1575 transform->m12 = [matrix[1] doubleValue];
1576 transform->m13 = [matrix[2] doubleValue];
1577 transform->m14 = [matrix[3] doubleValue];
1579 transform->m21 = [matrix[4] doubleValue];
1580 transform->m22 = [matrix[5] doubleValue];
1581 transform->m23 = [matrix[6] doubleValue];
1582 transform->m24 = [matrix[7] doubleValue];
1584 transform->m31 = [matrix[8] doubleValue];
1585 transform->m32 = [matrix[9] doubleValue];
1586 transform->m33 = [matrix[10] doubleValue];
1587 transform->m34 = [matrix[11] doubleValue];
1589 transform->m41 = [matrix[12] doubleValue];
1590 transform->m42 = [matrix[13] doubleValue];
1591 transform->m43 = [matrix[14] doubleValue];
1592 transform->m44 = [matrix[15] doubleValue];
1601 CGPoint points[] = {
1602 incomingRect.origin,
1603 CGPointMake(incomingRect.origin.x, incomingRect.origin.y + incomingRect.size.height),
1604 CGPointMake(incomingRect.origin.x + incomingRect.size.width, incomingRect.origin.y),
1605 CGPointMake(incomingRect.origin.x + incomingRect.size.width,
1606 incomingRect.origin.y + incomingRect.size.height)};
1608 CGPoint origin = CGPointMake(CGFLOAT_MAX, CGFLOAT_MAX);
1609 CGPoint farthest = CGPointMake(-CGFLOAT_MAX, -CGFLOAT_MAX);
1611 for (
int i = 0; i < 4; i++) {
1612 const CGPoint point = points[i];
1614 CGFloat x = _editableTransform.m11 * point.x + _editableTransform.m21 * point.y +
1615 _editableTransform.m41;
1616 CGFloat y = _editableTransform.m12 * point.x + _editableTransform.m22 * point.y +
1617 _editableTransform.m42;
1619 const CGFloat w = _editableTransform.m14 * point.x + _editableTransform.m24 * point.y +
1620 _editableTransform.m44;
1624 }
else if (w != 1.0) {
1629 origin.x = MIN(origin.x, x);
1630 origin.y = MIN(origin.y, y);
1631 farthest.x = MAX(farthest.x, x);
1632 farthest.y = MAX(farthest.y, y);
1634 return CGRectMake(origin.x, origin.y, farthest.x - origin.x, farthest.y - origin.y);
1643 - (CGRect)firstRectForRange:(UITextRange*)range {
1645 @"Expected a FlutterTextPosition for range.start (got %@).", [range.start
class]);
1647 @"Expected a FlutterTextPosition for range.end (got %@).", [range.end
class]);
1650 if (_markedTextRange != nil) {
1661 CGRect rect = _markedRect;
1662 if (CGRectIsEmpty(rect)) {
1663 rect = CGRectInset(rect, -0.1, 0);
1669 NSAssert(hostView == nil || [
self isDescendantOfView:hostView],
@"%@ is not a descendant of %@",
1671 return hostView ? [hostView convertRect:_cachedFirstRect toView:self] :
_cachedFirstRect;
1675 _scribbleFocusStatus == FlutterScribbleFocusStatusUnfocused) {
1676 if (@available(iOS 17.0, *)) {
1686 [
self.textInputDelegate flutterTextInputView:self
1687 showAutocorrectionPromptRectForStart:start
1689 withClient:_textInputClient];
1697 if (@available(iOS 17, *)) {
1703 NSUInteger first = start;
1708 CGRect startSelectionRect = CGRectNull;
1709 CGRect endSelectionRect = CGRectNull;
1712 CGFloat minY = CGFLOAT_MAX;
1713 CGFloat maxY = CGFLOAT_MIN;
1716 rangeWithNSRange:fml::RangeForCharactersInRange(self.text, NSMakeRange(0, self.text.length))];
1717 for (NSUInteger i = 0; i < [_selectionRects count]; i++) {
1718 BOOL startsOnOrBeforeStartOfRange = _selectionRects[i].position <= first;
1719 BOOL isLastSelectionRect = i + 1 == [_selectionRects count];
1720 BOOL endOfTextIsAfterStartOfRange = isLastSelectionRect && textRange.
range.length > first;
1721 BOOL nextSelectionRectIsAfterStartOfRange =
1722 !isLastSelectionRect && _selectionRects[i + 1].position > first;
1723 if (startsOnOrBeforeStartOfRange &&
1724 (endOfTextIsAfterStartOfRange || nextSelectionRectIsAfterStartOfRange)) {
1726 if (@available(iOS 17, *)) {
1727 startSelectionRect = _selectionRects[i].rect;
1729 return _selectionRects[i].rect;
1732 if (!CGRectIsNull(startSelectionRect)) {
1733 minY = fmin(minY, CGRectGetMinY(_selectionRects[i].rect));
1734 maxY = fmax(maxY, CGRectGetMaxY(_selectionRects[i].rect));
1735 BOOL endsOnOrAfterEndOfRange = _selectionRects[i].position >= end - 1;
1736 BOOL nextSelectionRectIsOnNextLine =
1737 !isLastSelectionRect &&
1742 CGRectGetMidY(_selectionRects[i + 1].rect) > CGRectGetMaxY(_selectionRects[i].rect);
1743 if (endsOnOrAfterEndOfRange || isLastSelectionRect || nextSelectionRectIsOnNextLine) {
1744 endSelectionRect = _selectionRects[i].rect;
1749 if (CGRectIsNull(startSelectionRect) || CGRectIsNull(endSelectionRect)) {
1753 CGFloat minX = fmin(CGRectGetMinX(startSelectionRect), CGRectGetMinX(endSelectionRect));
1754 CGFloat maxX = fmax(CGRectGetMaxX(startSelectionRect), CGRectGetMaxX(endSelectionRect));
1755 return CGRectMake(minX, minY, maxX - minX, maxY - minY);
1763 NSArray<UITextSelectionRect*>* rects = [
self
1765 rangeWithNSRange:fml::RangeForCharactersInRange(
1769 (index >= (NSInteger)self.text.length)
1772 if (rects.count == 0) {
1778 CGRect characterAfterCaret = rects[0].rect;
1783 return CGRectMake(characterAfterCaret.origin.x + characterAfterCaret.size.width,
1784 characterAfterCaret.origin.y, 0, characterAfterCaret.size.height);
1786 return CGRectMake(characterAfterCaret.origin.x, characterAfterCaret.origin.y, 0,
1787 characterAfterCaret.size.height);
1789 }
else if (rects.count == 2 && affinity == UITextStorageDirectionForward) {
1792 CGRect characterAfterCaret = rects[1].rect;
1797 return CGRectMake(characterAfterCaret.origin.x + characterAfterCaret.size.width,
1798 characterAfterCaret.origin.y, 0, characterAfterCaret.size.height);
1800 return CGRectMake(characterAfterCaret.origin.x, characterAfterCaret.origin.y, 0,
1801 characterAfterCaret.size.height);
1810 CGRect characterBeforeCaret = rects[0].rect;
1813 return CGRectMake(characterBeforeCaret.origin.x, characterBeforeCaret.origin.y, 0,
1814 characterBeforeCaret.size.height);
1816 return CGRectMake(characterBeforeCaret.origin.x + characterBeforeCaret.size.width,
1817 characterBeforeCaret.origin.y, 0, characterBeforeCaret.size.height);
1821 - (UITextPosition*)closestPositionToPoint:(CGPoint)point {
1822 if ([_selectionRects count] == 0) {
1824 @"Expected a FlutterTextPosition for position (got %@).",
1827 UITextStorageDirection currentAffinity =
1833 rangeWithNSRange:fml::RangeForCharactersInRange(self.text, NSMakeRange(0, self.text.length))];
1834 return [
self closestPositionToPoint:point withinRange:range];
1837 - (NSArray*)selectionRectsForRange:(UITextRange*)range {
1845 @"Expected a FlutterTextPosition for range.start (got %@).", [range.start
class]);
1847 @"Expected a FlutterTextPosition for range.end (got %@).", [range.end
class]);
1850 NSMutableArray* rects = [[NSMutableArray alloc] init];
1851 for (NSUInteger i = 0; i < [_selectionRects count]; i++) {
1852 if (_selectionRects[i].position >= start &&
1853 (_selectionRects[i].position < end ||
1854 (start == end && _selectionRects[i].position <= end))) {
1855 float width = _selectionRects[i].rect.size.width;
1859 CGRect rect = CGRectMake(_selectionRects[i].rect.origin.x, _selectionRects[i].rect.origin.y,
1860 width, _selectionRects[i].rect.size.height);
1863 position:_selectionRects[i].position
1867 self.text, NSMakeRange(0, self.text.length))
1870 [rects addObject:selectionRect];
1876 - (UITextPosition*)closestPositionToPoint:(CGPoint)point withinRange:(UITextRange*)range {
1878 @"Expected a FlutterTextPosition for range.start (got %@).", [range.start
class]);
1880 @"Expected a FlutterTextPosition for range.end (got %@).", [range.end
class]);
1890 NSUInteger _closestRectIndex = 0;
1891 for (NSUInteger i = 0; i < [_selectionRects count]; i++) {
1892 NSUInteger position = _selectionRects[i].position;
1893 if (position >= start && position <= end) {
1896 point, _selectionRects[i].rect, _selectionRects[i].isRTL,
1897 NO, _selectionRects[_closestRectIndex].rect,
1898 _selectionRects[_closestRectIndex].isRTL, verticalPrecision)) {
1900 _closestRectIndex = i;
1907 affinity:UITextStorageDirectionForward];
1913 for (NSUInteger i = MAX(0, _closestRectIndex - 1);
1914 i < MIN(_closestRectIndex + 2, [_selectionRects count]); i++) {
1915 NSUInteger position = _selectionRects[i].position + 1;
1916 if (position >= start && position <= end) {
1918 point, _selectionRects[i].rect, _selectionRects[i].isRTL,
1919 YES, _selectionRects[_closestRectIndex].rect,
1920 _selectionRects[_closestRectIndex].isRTL, verticalPrecision)) {
1923 affinity:UITextStorageDirectionBackward];
1928 return closestPosition;
1931 - (UITextRange*)characterRangeAtPoint:(CGPoint)point {
1934 return [
FlutterTextRange rangeWithNSRange:fml::RangeForCharacterAtIndex(self.text, currentIndex)];
1965 - (void)beginFloatingCursorAtPoint:(CGPoint)point {
1982 [
self.textInputDelegate flutterTextInputView:self
1983 updateFloatingCursor:FlutterFloatingCursorDragStateStart
1984 withClient:_textInputClient
1985 withPosition:@{@"X" : @0, @"Y" : @0}];
1988 - (void)updateFloatingCursorAtPoint:(CGPoint)point {
1989 [
self.textInputDelegate flutterTextInputView:self
1990 updateFloatingCursor:FlutterFloatingCursorDragStateUpdate
1991 withClient:_textInputClient
1993 @"X" : @(point.x - _floatingCursorOffset.x),
1994 @"Y" : @(point.y - _floatingCursorOffset.y)
1998 - (void)endFloatingCursor {
2000 [
self.textInputDelegate flutterTextInputView:self
2001 updateFloatingCursor:FlutterFloatingCursorDragStateEnd
2002 withClient:_textInputClient
2003 withPosition:@{@"X" : @0, @"Y" : @0}];
2006 #pragma mark - UIKeyInput Overrides
2008 - (void)updateEditingState {
2013 NSInteger composingBase = -1;
2014 NSInteger composingExtent = -1;
2019 NSDictionary* state = @{
2020 @"selectionBase" : @(selectionBase),
2021 @"selectionExtent" : @(selectionExtent),
2023 @"selectionIsDirectional" : @(
false),
2024 @"composingBase" : @(composingBase),
2025 @"composingExtent" : @(composingExtent),
2026 @"text" : [NSString stringWithString:self.text],
2029 if (_textInputClient == 0 && _autofillId != nil) {
2030 [
self.textInputDelegate flutterTextInputView:self
2031 updateEditingClient:_textInputClient
2033 withTag:_autofillId];
2035 [
self.textInputDelegate flutterTextInputView:self
2036 updateEditingClient:_textInputClient
2041 - (void)updateEditingStateWithDelta:(
flutter::TextEditingDelta)delta {
2046 NSInteger composingBase = -1;
2047 NSInteger composingExtent = -1;
2053 NSDictionary* deltaToFramework = @{
2054 @"oldText" : @(delta.old_text().c_str()),
2055 @"deltaText" : @(delta.delta_text().c_str()),
2056 @"deltaStart" : @(delta.delta_start()),
2057 @"deltaEnd" : @(delta.delta_end()),
2058 @"selectionBase" : @(selectionBase),
2059 @"selectionExtent" : @(selectionExtent),
2061 @"selectionIsDirectional" : @(
false),
2062 @"composingBase" : @(composingBase),
2063 @"composingExtent" : @(composingExtent),
2066 [_pendingDeltas addObject:deltaToFramework];
2068 if (_pendingDeltas.count == 1) {
2070 dispatch_async(dispatch_get_main_queue(), ^{
2072 if (strongSelf && strongSelf.pendingDeltas.count > 0) {
2073 NSDictionary* deltas = @{
2074 @"deltas" : strongSelf.pendingDeltas,
2077 [strongSelf.textInputDelegate flutterTextInputView:strongSelf
2078 updateEditingClient:strongSelf->_textInputClient
2080 [strongSelf.pendingDeltas removeAllObjects];
2087 return self.text.length > 0;
2090 - (void)insertText:(NSString*)text {
2091 if (
self.temporarilyDeletedComposedCharacter.length > 0 && text.length == 1 && !text.UTF8String &&
2092 [text characterAtIndex:0] == [
self.temporarilyDeletedComposedCharacter characterAtIndex:0]) {
2096 text =
self.temporarilyDeletedComposedCharacter;
2097 self.temporarilyDeletedComposedCharacter = nil;
2100 NSMutableArray<FlutterTextSelectionRect*>* copiedRects =
2101 [[NSMutableArray alloc] initWithCapacity:[_selectionRects count]];
2103 @"Expected a FlutterTextPosition for position (got %@).",
2106 for (NSUInteger i = 0; i < [_selectionRects count]; i++) {
2107 NSUInteger rectPosition = _selectionRects[i].position;
2108 if (rectPosition == insertPosition) {
2109 for (NSUInteger j = 0; j <= text.length; j++) {
2116 if (rectPosition > insertPosition) {
2117 rectPosition = rectPosition + text.length;
2126 _scribbleFocusStatus = FlutterScribbleFocusStatusUnfocused;
2127 [
self resetScribbleInteractionStatusIfEnding];
2128 self.selectionRects = copiedRects;
2130 [
self replaceRange:_selectedTextRange withText:text];
2133 - (UITextPlaceholder*)insertTextPlaceholderWithSize:(CGSize)size API_AVAILABLE(ios(13.0)) {
2134 [
self.textInputDelegate flutterTextInputView:self
2135 insertTextPlaceholderWithSize:size
2136 withClient:_textInputClient];
2141 - (void)removeTextPlaceholder:(UITextPlaceholder*)textPlaceholder API_AVAILABLE(ios(13.0)) {
2143 [
self.textInputDelegate flutterTextInputView:self removeTextPlaceholder:_textInputClient];
2146 - (void)deleteBackward {
2148 _scribbleFocusStatus = FlutterScribbleFocusStatusUnfocused;
2149 [
self resetScribbleInteractionStatusIfEnding];
2166 if (oldRange.location > 0) {
2167 NSRange newRange = NSMakeRange(oldRange.location - 1, 1);
2171 NSRange charRange = fml::RangeForCharacterAtIndex(
self.text, oldRange.location - 1);
2172 if (
IsEmoji(
self.text, charRange)) {
2173 newRange = NSMakeRange(charRange.location, oldRange.location - charRange.location);
2185 NSString* deletedText = [
self.text substringWithRange:_selectedTextRange.range];
2186 NSRange deleteFirstCharacterRange = fml::RangeForCharacterAtIndex(deletedText, 0);
2187 self.temporarilyDeletedComposedCharacter =
2188 [deletedText substringWithRange:deleteFirstCharacterRange];
2190 [
self replaceRange:_selectedTextRange withText:@""];
2194 - (void)postAccessibilityNotification:(UIAccessibilityNotifications)notification target:(
id)target {
2195 UIAccessibilityPostNotification(notification, target);
2198 - (void)accessibilityElementDidBecomeFocused {
2199 if ([
self accessibilityElementIsFocused]) {
2203 FML_DCHECK(_backingTextInputAccessibilityObject);
2204 [
self postAccessibilityNotification:UIAccessibilityScreenChangedNotification
2205 target:_backingTextInputAccessibilityObject];
2209 - (BOOL)accessibilityElementsHidden {
2210 return !_accessibilityEnabled;
2219 #pragma mark - Key Events Handling
2220 - (void)pressesBegan:(NSSet<UIPress*>*)presses
2221 withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
2222 [_textInputPlugin.viewController pressesBegan:presses withEvent:event];
2225 - (void)pressesChanged:(NSSet<UIPress*>*)presses
2226 withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
2227 [_textInputPlugin.viewController pressesChanged:presses withEvent:event];
2230 - (void)pressesEnded:(NSSet<UIPress*>*)presses
2231 withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
2232 [_textInputPlugin.viewController pressesEnded:presses withEvent:event];
2235 - (void)pressesCancelled:(NSSet<UIPress*>*)presses
2236 withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
2237 [_textInputPlugin.viewController pressesCancelled:presses withEvent:event];
2266 - (BOOL)accessibilityElementsHidden {
2273 - (void)enableActiveViewAccessibility;
2290 - (void)enableActiveViewAccessibility {
2291 [
self.target enableActiveViewAccessibility];
2298 @property(nonatomic, readonly)
2299 NSMutableDictionary<NSString*, FlutterTextInputView*>* autofillContext;
2304 @property(nonatomic, strong) UIView* keyboardViewContainer;
2305 @property(nonatomic, strong) UIView* keyboardView;
2306 @property(nonatomic, strong) UIView* cachedFirstResponder;
2307 @property(nonatomic, assign) CGRect keyboardRect;
2308 @property(nonatomic, assign) CGFloat previousPointerYPosition;
2309 @property(nonatomic, assign) CGFloat pointerYVelocity;
2313 NSTimer* _enableFlutterTextInputViewAccessibilityTimer;
2317 self = [
super init];
2320 _textInputDelegate = textInputDelegate;
2321 _autofillContext = [[NSMutableDictionary alloc] init];
2323 _scribbleElements = [[NSMutableDictionary alloc] init];
2324 _keyboardViewContainer = [[UIView alloc] init];
2326 [[NSNotificationCenter defaultCenter] addObserver:self
2327 selector:@selector(handleKeyboardWillShow:)
2328 name:UIKeyboardWillShowNotification
2335 - (void)handleKeyboardWillShow:(NSNotification*)notification {
2336 NSDictionary* keyboardInfo = [notification userInfo];
2337 NSValue* keyboardFrameEnd = [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey];
2338 _keyboardRect = [keyboardFrameEnd CGRectValue];
2342 [
self hideTextInput];
2345 - (void)removeEnableFlutterTextInputViewAccessibilityTimer {
2346 if (_enableFlutterTextInputViewAccessibilityTimer) {
2347 [_enableFlutterTextInputViewAccessibilityTimer invalidate];
2348 _enableFlutterTextInputViewAccessibilityTimer = nil;
2352 - (UIView<UITextInput>*)textInputView {
2357 NSString* method = call.
method;
2360 [
self showTextInput];
2362 }
else if ([method isEqualToString:
kHideMethod]) {
2363 [
self hideTextInput];
2366 [
self setTextInputClient:[args[0] intValue] withConfiguration:args[1]];
2370 [
self setPlatformViewTextInputClient];
2373 [
self setTextInputEditingState:args];
2376 [
self clearTextInputClient];
2379 [
self setEditableSizeAndTransform:args];
2382 [
self updateMarkedRect:args];
2385 [
self triggerAutofillSave:[args boolValue]];
2391 [
self setSelectionRects:args];
2394 [
self setSelectionRects:args];
2397 [
self startLiveTextInput];
2400 [
self updateConfig:args];
2403 CGFloat pointerY = (CGFloat)[args[
@"pointerY"] doubleValue];
2404 [
self handlePointerMove:pointerY];
2407 CGFloat pointerY = (CGFloat)[args[
@"pointerY"] doubleValue];
2408 [
self handlePointerUp:pointerY];
2415 - (void)handlePointerUp:(CGFloat)pointerY {
2416 if (_keyboardView.superview != nil) {
2420 CGFloat screenHeight = screen.bounds.size.height;
2421 CGFloat keyboardHeight = _keyboardRect.size.height;
2423 BOOL shouldDismissKeyboardBasedOnVelocity = _pointerYVelocity < 0;
2424 [UIView animateWithDuration:kKeyboardAnimationTimeToCompleteion
2426 double keyboardDestination =
2427 shouldDismissKeyboardBasedOnVelocity ? screenHeight : screenHeight - keyboardHeight;
2428 _keyboardViewContainer.frame = CGRectMake(
2429 0, keyboardDestination, _viewController.flutterScreenIfViewLoaded.bounds.size.width,
2430 _keyboardViewContainer.frame.size.height);
2432 completion:^(BOOL finished) {
2433 if (shouldDismissKeyboardBasedOnVelocity) {
2434 [
self.textInputDelegate flutterTextInputView:self.activeView
2435 didResignFirstResponderWithTextInputClient:self.activeView.textInputClient];
2436 [
self dismissKeyboardScreenshot];
2438 [
self showKeyboardAndRemoveScreenshot];
2444 - (void)dismissKeyboardScreenshot {
2445 for (UIView* subView in _keyboardViewContainer.subviews) {
2446 [subView removeFromSuperview];
2450 - (void)showKeyboardAndRemoveScreenshot {
2451 [UIView setAnimationsEnabled:NO];
2452 [_cachedFirstResponder becomeFirstResponder];
2456 dispatch_get_main_queue(), ^{
2457 [UIView setAnimationsEnabled:YES];
2458 [
self dismissKeyboardScreenshot];
2462 - (void)handlePointerMove:(CGFloat)pointerY {
2465 CGFloat screenHeight = screen.bounds.size.height;
2466 CGFloat keyboardHeight = _keyboardRect.size.height;
2467 if (screenHeight - keyboardHeight <= pointerY) {
2469 if (_keyboardView.superview == nil) {
2471 [
self takeKeyboardScreenshotAndDisplay];
2472 [
self hideKeyboardWithoutAnimationAndAvoidCursorDismissUpdate];
2474 [
self setKeyboardContainerHeight:pointerY];
2475 _pointerYVelocity = _previousPointerYPosition - pointerY;
2478 if (_keyboardView.superview != nil) {
2480 _keyboardViewContainer.frame = _keyboardRect;
2481 _pointerYVelocity = _previousPointerYPosition - pointerY;
2484 _previousPointerYPosition = pointerY;
2487 - (void)setKeyboardContainerHeight:(CGFloat)pointerY {
2488 CGRect frameRect = _keyboardRect;
2489 frameRect.origin.y = pointerY;
2490 _keyboardViewContainer.frame = frameRect;
2493 - (void)hideKeyboardWithoutAnimationAndAvoidCursorDismissUpdate {
2494 [UIView setAnimationsEnabled:NO];
2495 _cachedFirstResponder = UIApplication.sharedApplication.keyWindow.flutterFirstResponder;
2496 _activeView.preventCursorDismissWhenResignFirstResponder = YES;
2497 [_cachedFirstResponder resignFirstResponder];
2498 _activeView.preventCursorDismissWhenResignFirstResponder = NO;
2499 [UIView setAnimationsEnabled:YES];
2502 - (void)takeKeyboardScreenshotAndDisplay {
2505 UIView* keyboardSnap = [screen snapshotViewAfterScreenUpdates:YES];
2506 keyboardSnap = [keyboardSnap resizableSnapshotViewFromRect:_keyboardRect
2507 afterScreenUpdates:YES
2508 withCapInsets:UIEdgeInsetsZero];
2509 _keyboardView = keyboardSnap;
2510 [_keyboardViewContainer addSubview:_keyboardView];
2511 if (_keyboardViewContainer.superview == nil) {
2512 [UIApplication.sharedApplication.delegate.window.rootViewController.view
2513 addSubview:_keyboardViewContainer];
2515 _keyboardViewContainer.layer.zPosition = NSIntegerMax;
2516 _keyboardViewContainer.frame = _keyboardRect;
2519 - (void)setEditableSizeAndTransform:(NSDictionary*)dictionary {
2520 NSArray* transform = dictionary[@"transform"];
2521 [_activeView setEditableTransform:transform];
2522 const int leftIndex = 12;
2523 const int topIndex = 13;
2527 CGRectMake([transform[leftIndex] intValue], [transform[topIndex] intValue],
2528 [dictionary[
@"width"] intValue], [dictionary[
@"height"] intValue]);
2530 CGRectMake(0, 0, [dictionary[
@"width"] intValue], [dictionary[
@"height"] intValue]);
2531 _activeView.tintColor = [UIColor clearColor];
2536 if (@available(iOS 17, *)) {
2544 CGRectMake([transform[leftIndex] intValue], [transform[topIndex] intValue], 0, 0);
2549 - (void)updateMarkedRect:(NSDictionary*)dictionary {
2550 NSAssert(dictionary[
@"x"] != nil && dictionary[
@"y"] != nil && dictionary[
@"width"] != nil &&
2551 dictionary[
@"height"] != nil,
2552 @"Expected a dictionary representing a CGRect, got %@", dictionary);
2553 CGRect rect = CGRectMake([dictionary[
@"x"] doubleValue], [dictionary[
@"y"] doubleValue],
2554 [dictionary[
@"width"] doubleValue], [dictionary[
@"height"] doubleValue]);
2555 _activeView.markedRect = rect.size.width < 0 && rect.size.height < 0 ?
kInvalidFirstRect : rect;
2558 - (void)setSelectionRects:(NSArray*)encodedRects {
2559 NSMutableArray<FlutterTextSelectionRect*>* rectsAsRect =
2560 [[NSMutableArray alloc] initWithCapacity:[encodedRects count]];
2561 for (NSUInteger i = 0; i < [encodedRects count]; i++) {
2562 NSArray<NSNumber*>* encodedRect = encodedRects[i];
2564 selectionRectWithRect:CGRectMake([encodedRect[0] floatValue],
2565 [encodedRect[1] floatValue],
2566 [encodedRect[2] floatValue],
2567 [encodedRect[3] floatValue])
2568 position:[encodedRect[4] unsignedIntegerValue]
2569 writingDirection:[encodedRect[5] unsignedIntegerValue] == 1
2570 ? NSWritingDirectionLeftToRight
2571 : NSWritingDirectionRightToLeft]];
2577 _activeView.selectionRects = rectsAsRect;
2580 - (void)startLiveTextInput {
2581 if (@available(iOS 15.0, *)) {
2582 if (_activeView == nil || !_activeView.isFirstResponder) {
2585 [_activeView captureTextFromCamera:nil];
2589 - (void)showTextInput {
2590 _activeView.viewResponder = _viewResponder;
2591 [
self addToInputParentViewIfNeeded:_activeView];
2600 if (!_enableFlutterTextInputViewAccessibilityTimer) {
2601 _enableFlutterTextInputViewAccessibilityTimer =
2602 [NSTimer scheduledTimerWithTimeInterval:kUITextInputAccessibilityEnablingDelaySeconds
2604 selector:@selector(enableActiveViewAccessibility)
2608 [_activeView becomeFirstResponder];
2611 - (void)enableActiveViewAccessibility {
2612 if (_activeView.isFirstResponder) {
2613 _activeView.accessibilityEnabled = YES;
2615 [
self removeEnableFlutterTextInputViewAccessibilityTimer];
2618 - (void)hideTextInput {
2619 [
self removeEnableFlutterTextInputViewAccessibilityTimer];
2620 _activeView.accessibilityEnabled = NO;
2621 [_activeView resignFirstResponder];
2622 [_activeView removeFromSuperview];
2623 [_inputHider removeFromSuperview];
2626 - (void)triggerAutofillSave:(BOOL)saveEntries {
2627 [_activeView resignFirstResponder];
2632 [
self cleanUpViewHierarchy:YES clearText:YES delayRemoval:NO];
2633 [_autofillContext removeAllObjects];
2634 [
self changeInputViewsAutofillVisibility:YES];
2636 [_autofillContext removeAllObjects];
2639 [
self cleanUpViewHierarchy:YES clearText:!saveEntries delayRemoval:NO];
2640 [
self addToInputParentViewIfNeeded:_activeView];
2643 - (void)setPlatformViewTextInputClient {
2647 [
self removeEnableFlutterTextInputViewAccessibilityTimer];
2648 _activeView.accessibilityEnabled = NO;
2649 [_activeView removeFromSuperview];
2650 [_inputHider removeFromSuperview];
2653 - (void)setTextInputClient:(
int)client withConfiguration:(NSDictionary*)configuration {
2654 [
self resetAllClientIds];
2657 [
self changeInputViewsAutofillVisibility:NO];
2661 case kFlutterAutofillTypeNone:
2662 self.activeView = [
self createInputViewWith:configuration];
2664 case kFlutterAutofillTypeRegular:
2667 self.activeView = [
self updateAndShowAutofillViews:nil
2668 focusedField:configuration
2669 isPasswordRelated:NO];
2671 case kFlutterAutofillTypePassword:
2672 self.activeView = [
self updateAndShowAutofillViews:configuration[kAssociatedAutofillFields]
2673 focusedField:configuration
2674 isPasswordRelated:YES];
2677 [_activeView setTextInputClient:client];
2678 [_activeView reloadInputViews];
2690 [
self cleanUpViewHierarchy:NO clearText:YES delayRemoval:YES];
2701 [_autofillContext removeObjectForKey:autofillId];
2704 [newView configureWithDictionary:configuration];
2705 [
self addToInputParentViewIfNeeded:newView];
2709 if (autofillId &&
AutofillTypeOf(field) == kFlutterAutofillTypeNone) {
2710 [_autofillContext removeObjectForKey:autofillId];
2717 focusedField:(NSDictionary*)focusedField
2718 isPasswordRelated:(BOOL)isPassword {
2721 NSAssert(focusedId,
@"autofillId must not be null for the focused field: %@", focusedField);
2726 focused = [
self getOrCreateAutofillableView:focusedField isPasswordAutofill:isPassword];
2727 [_autofillContext removeObjectForKey:focusedId];
2730 for (NSDictionary* field in fields) {
2732 NSAssert(autofillId,
@"autofillId must not be null for field: %@", field);
2734 BOOL hasHints =
AutofillTypeOf(field) != kFlutterAutofillTypeNone;
2735 BOOL isFocused = [focusedId isEqualToString:autofillId];
2738 focused = [
self getOrCreateAutofillableView:field isPasswordAutofill:isPassword];
2743 _autofillContext[autofillId] = isFocused ? focused
2744 : [
self getOrCreateAutofillableView:field
2745 isPasswordAutofill:isPassword];
2748 [_autofillContext removeObjectForKey:autofillId];
2752 NSAssert(focused,
@"The current focused input view must not be nil.");
2762 isPasswordAutofill:(BOOL)needsPasswordAutofill {
2768 inputView = [inputView initWithOwner:self];
2769 [
self addToInputParentViewIfNeeded:inputView];
2772 [inputView configureWithDictionary:field];
2777 - (UIView*)hostView {
2779 NSAssert(host !=
nullptr,
2780 @"The application must have a host view since the keyboard client "
2781 @"must be part of the responder chain to function. The host view controller is %@",
2787 - (NSArray<UIView*>*)textInputViews {
2788 return _inputHider.subviews;
2801 - (void)cleanUpViewHierarchy:(BOOL)includeActiveView
2802 clearText:(BOOL)clearText
2803 delayRemoval:(BOOL)delayRemoval {
2804 for (UIView* view in
self.textInputViews) {
2806 (includeActiveView || view != _activeView)) {
2808 if (_autofillContext[inputView.autofillId] != view) {
2810 [inputView replaceRangeLocal:NSMakeRange(0, inputView.text.length) withText:@""];
2813 [inputView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.1];
2815 [inputView removeFromSuperview];
2824 - (void)changeInputViewsAutofillVisibility:(BOOL)newVisibility {
2825 for (UIView* view in
self.textInputViews) {
2828 inputView.isVisibleToAutofill = newVisibility;
2840 - (void)resetAllClientIds {
2841 for (UIView* view in
self.textInputViews) {
2844 [inputView setTextInputClient:0];
2850 if (![inputView isDescendantOfView:_inputHider]) {
2851 [_inputHider addSubview:inputView];
2860 UIView* parentView =
self.hostView;
2861 if (_inputHider.superview != parentView) {
2862 [parentView addSubview:_inputHider];
2866 - (void)setTextInputEditingState:(NSDictionary*)state {
2867 [_activeView setTextInputState:state];
2870 - (void)clearTextInputClient {
2871 [_activeView setTextInputClient:0];
2872 _activeView.frame = CGRectZero;
2875 - (void)updateConfig:(NSDictionary*)dictionary {
2876 BOOL isSecureTextEntry = [dictionary[kSecureTextEntry] boolValue];
2877 for (UIView* view in
self.textInputViews) {
2884 if (inputView.isSecureTextEntry != isSecureTextEntry) {
2885 inputView.secureTextEntry = isSecureTextEntry;
2886 [inputView reloadInputViews];
2892 #pragma mark UIIndirectScribbleInteractionDelegate
2894 - (BOOL)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2895 isElementFocused:(UIScribbleElementIdentifier)elementIdentifier
2896 API_AVAILABLE(ios(14.0)) {
2897 return _activeView.scribbleFocusStatus == FlutterScribbleFocusStatusFocused;
2900 - (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2901 focusElementIfNeeded:(UIScribbleElementIdentifier)elementIdentifier
2902 referencePoint:(CGPoint)focusReferencePoint
2903 completion:(
void (^)(UIResponder<UITextInput>* focusedInput))completion
2904 API_AVAILABLE(ios(14.0)) {
2905 _activeView.scribbleFocusStatus = FlutterScribbleFocusStatusFocusing;
2906 [_indirectScribbleDelegate flutterTextInputPlugin:self
2907 focusElement:elementIdentifier
2908 atPoint:focusReferencePoint
2909 result:^(id _Nullable result) {
2910 _activeView.scribbleFocusStatus =
2911 FlutterScribbleFocusStatusFocused;
2912 completion(_activeView);
2916 - (BOOL)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2917 shouldDelayFocusForElement:(UIScribbleElementIdentifier)elementIdentifier
2918 API_AVAILABLE(ios(14.0)) {
2922 - (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2923 willBeginWritingInElement:(UIScribbleElementIdentifier)elementIdentifier
2924 API_AVAILABLE(ios(14.0)) {
2927 - (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2928 didFinishWritingInElement:(UIScribbleElementIdentifier)elementIdentifier
2929 API_AVAILABLE(ios(14.0)) {
2932 - (CGRect)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2933 frameForElement:(UIScribbleElementIdentifier)elementIdentifier
2934 API_AVAILABLE(ios(14.0)) {
2935 NSValue* elementValue = [_scribbleElements objectForKey:elementIdentifier];
2936 if (elementValue == nil) {
2939 return [elementValue CGRectValue];
2942 - (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2943 requestElementsInRect:(CGRect)rect
2945 (
void (^)(NSArray<UIScribbleElementIdentifier>* elements))completion
2946 API_AVAILABLE(ios(14.0)) {
2947 [_indirectScribbleDelegate
2948 flutterTextInputPlugin:self
2949 requestElementsInRect:rect
2950 result:^(id _Nullable result) {
2951 NSMutableArray<UIScribbleElementIdentifier>* elements =
2952 [[NSMutableArray alloc] init];
2953 if ([result isKindOfClass:[NSArray class]]) {
2954 for (NSArray* elementArray in result) {
2955 [elements addObject:elementArray[0]];
2958 valueWithCGRect:CGRectMake(
2959 [elementArray[1] floatValue],
2960 [elementArray[2] floatValue],
2961 [elementArray[3] floatValue],
2962 [elementArray[4] floatValue])]
2963 forKey:elementArray[0]];
2966 completion(elements);
2970 #pragma mark - Methods related to Scribble support
2974 if (@available(iOS 14.0, *)) {
2976 if (parentView != nil) {
2977 UIIndirectScribbleInteraction* scribbleInteraction = [[UIIndirectScribbleInteraction alloc]
2978 initWithDelegate:(id<UIIndirectScribbleInteractionDelegate>)self];
2979 [parentView addInteraction:scribbleInteraction];
2986 - (void)resetViewResponder {
2987 _viewResponder = nil;
2991 #pragma mark FlutterKeySecondaryResponder
3006 - (id)flutterFirstResponder {
3007 if (
self.isFirstResponder) {
3010 for (UIView* subView in
self.subviews) {
3011 UIView* firstResponder = subView.flutterFirstResponder;
3012 if (firstResponder) {
3013 return firstResponder;