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 if ([inputType isEqualToString:
@"TextInputType.visiblePassword"]) {
141 return UIKeyboardTypeASCIICapable;
143 return UIKeyboardTypeDefault;
147 NSString* textCapitalization = type[
@"textCapitalization"];
148 if ([textCapitalization isEqualToString:
@"TextCapitalization.characters"]) {
149 return UITextAutocapitalizationTypeAllCharacters;
150 }
else if ([textCapitalization isEqualToString:
@"TextCapitalization.sentences"]) {
151 return UITextAutocapitalizationTypeSentences;
152 }
else if ([textCapitalization isEqualToString:
@"TextCapitalization.words"]) {
153 return UITextAutocapitalizationTypeWords;
155 return UITextAutocapitalizationTypeNone;
163 if ([inputType isEqualToString:
@"TextInputAction.unspecified"]) {
164 return UIReturnKeyDefault;
167 if ([inputType isEqualToString:
@"TextInputAction.done"]) {
168 return UIReturnKeyDone;
171 if ([inputType isEqualToString:
@"TextInputAction.go"]) {
172 return UIReturnKeyGo;
175 if ([inputType isEqualToString:
@"TextInputAction.send"]) {
176 return UIReturnKeySend;
179 if ([inputType isEqualToString:
@"TextInputAction.search"]) {
180 return UIReturnKeySearch;
183 if ([inputType isEqualToString:
@"TextInputAction.next"]) {
184 return UIReturnKeyNext;
187 if ([inputType isEqualToString:
@"TextInputAction.continueAction"]) {
188 return UIReturnKeyContinue;
191 if ([inputType isEqualToString:
@"TextInputAction.join"]) {
192 return UIReturnKeyJoin;
195 if ([inputType isEqualToString:
@"TextInputAction.route"]) {
196 return UIReturnKeyRoute;
199 if ([inputType isEqualToString:
@"TextInputAction.emergencyCall"]) {
200 return UIReturnKeyEmergencyCall;
203 if ([inputType isEqualToString:
@"TextInputAction.newline"]) {
204 return UIReturnKeyDefault;
208 return UIReturnKeyDefault;
212 if (!hints || hints.count == 0) {
217 NSString* hint = hints[0];
218 if ([hint isEqualToString:
@"addressCityAndState"]) {
219 return UITextContentTypeAddressCityAndState;
222 if ([hint isEqualToString:
@"addressState"]) {
223 return UITextContentTypeAddressState;
226 if ([hint isEqualToString:
@"addressCity"]) {
227 return UITextContentTypeAddressCity;
230 if ([hint isEqualToString:
@"sublocality"]) {
231 return UITextContentTypeSublocality;
234 if ([hint isEqualToString:
@"streetAddressLine1"]) {
235 return UITextContentTypeStreetAddressLine1;
238 if ([hint isEqualToString:
@"streetAddressLine2"]) {
239 return UITextContentTypeStreetAddressLine2;
242 if ([hint isEqualToString:
@"countryName"]) {
243 return UITextContentTypeCountryName;
246 if ([hint isEqualToString:
@"fullStreetAddress"]) {
247 return UITextContentTypeFullStreetAddress;
250 if ([hint isEqualToString:
@"postalCode"]) {
251 return UITextContentTypePostalCode;
254 if ([hint isEqualToString:
@"location"]) {
255 return UITextContentTypeLocation;
258 if ([hint isEqualToString:
@"creditCardNumber"]) {
259 return UITextContentTypeCreditCardNumber;
262 if ([hint isEqualToString:
@"email"]) {
263 return UITextContentTypeEmailAddress;
266 if ([hint isEqualToString:
@"jobTitle"]) {
267 return UITextContentTypeJobTitle;
270 if ([hint isEqualToString:
@"givenName"]) {
271 return UITextContentTypeGivenName;
274 if ([hint isEqualToString:
@"middleName"]) {
275 return UITextContentTypeMiddleName;
278 if ([hint isEqualToString:
@"familyName"]) {
279 return UITextContentTypeFamilyName;
282 if ([hint isEqualToString:
@"name"]) {
283 return UITextContentTypeName;
286 if ([hint isEqualToString:
@"namePrefix"]) {
287 return UITextContentTypeNamePrefix;
290 if ([hint isEqualToString:
@"nameSuffix"]) {
291 return UITextContentTypeNameSuffix;
294 if ([hint isEqualToString:
@"nickname"]) {
295 return UITextContentTypeNickname;
298 if ([hint isEqualToString:
@"organizationName"]) {
299 return UITextContentTypeOrganizationName;
302 if ([hint isEqualToString:
@"telephoneNumber"]) {
303 return UITextContentTypeTelephoneNumber;
306 if ([hint isEqualToString:
@"password"]) {
307 return UITextContentTypePassword;
310 if ([hint isEqualToString:
@"oneTimeCode"]) {
311 return UITextContentTypeOneTimeCode;
314 if ([hint isEqualToString:
@"newPassword"]) {
315 return UITextContentTypeNewPassword;
383 typedef NS_ENUM(NSInteger, FlutterAutofillType) {
387 kFlutterAutofillTypeNone,
388 kFlutterAutofillTypeRegular,
389 kFlutterAutofillTypePassword,
399 if (isSecureTextEntry) {
406 if ([contentType isEqualToString:UITextContentTypePassword] ||
407 [contentType isEqualToString:UITextContentTypeUsername]) {
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 {
1148 if (action ==
@selector(paste:)) {
1150 return [UIPasteboard generalPasteboard].hasStrings;
1153 return [
super canPerformAction:action withSender:sender];
1156 #pragma mark - UIResponderStandardEditActions Overrides
1158 - (void)cut:(
id)sender {
1159 [UIPasteboard generalPasteboard].string = [
self textInRange:_selectedTextRange];
1160 [
self replaceRange:_selectedTextRange withText:@""];
1163 - (void)copy:(
id)sender {
1164 [UIPasteboard generalPasteboard].string = [
self textInRange:_selectedTextRange];
1167 - (void)paste:(
id)sender {
1168 NSString* pasteboardString = [UIPasteboard generalPasteboard].string;
1169 if (pasteboardString != nil) {
1170 [
self insertText:pasteboardString];
1174 - (void)delete:(
id)sender {
1175 [
self replaceRange:_selectedTextRange withText:@""];
1178 - (void)selectAll:(
id)sender {
1179 [
self setSelectedTextRange:[
self textRangeFromPosition:[
self beginningOfDocument]
1180 toPosition:[
self endOfDocument]]];
1183 #pragma mark - UITextInput Overrides
1185 - (id<UITextInputTokenizer>)tokenizer {
1186 if (_tokenizer == nil) {
1193 return [_selectedTextRange copy];
1197 - (void)setSelectedTextRangeLocal:(UITextRange*)selectedTextRange {
1202 rangeWithNSRange:fml::RangeForCharactersInRange(self.text, flutterTextRange.range)] copy];
1209 - (void)setSelectedTextRange:(UITextRange*)selectedTextRange {
1214 [
self setSelectedTextRangeLocal:selectedTextRange];
1216 if (_enableDeltaModel) {
1217 [
self updateEditingStateWithDelta:flutter::TextEditingDelta([
self.text UTF8String])];
1219 [
self updateEditingState];
1223 _scribbleFocusStatus == FlutterScribbleFocusStatusFocused) {
1227 if (flutterTextRange.
range.length > 0) {
1228 [
self.textInputDelegate flutterTextInputView:self showToolbar:_textInputClient];
1232 [
self resetScribbleInteractionStatusIfEnding];
1235 - (id)insertDictationResultPlaceholder {
1239 - (void)removeDictationResultPlaceholder:(
id)placeholder willInsertResult:(BOOL)willInsertResult {
1242 - (NSString*)textInRange:(UITextRange*)range {
1247 @"Expected a FlutterTextRange for range (got %@).", [range
class]);
1249 NSAssert(textRange.location != NSNotFound,
@"Expected a valid text range.");
1251 NSUInteger location = MIN(textRange.location,
self.text.length);
1252 NSUInteger length = MIN(
self.text.length - location, textRange.length);
1253 NSRange safeRange = NSMakeRange(location, length);
1254 return [
self.text substringWithRange:safeRange];
1259 - (void)replaceRangeLocal:(NSRange)range withText:(NSString*)text {
1260 [
self.text replaceCharactersInRange:[
self clampSelection:range forText:self.text]
1266 const NSRange newSelectionRange =
1267 [
self clampSelection:NSMakeRange(range.location + text.length, 0) forText:self.text];
1270 self.markedTextRange = nil;
1273 - (void)replaceRange:(UITextRange*)range withText:(NSString*)text {
1274 NSString* textBeforeChange = [
self.text copy];
1276 [
self replaceRangeLocal:replaceRange withText:text];
1277 if (_enableDeltaModel) {
1278 NSRange nextReplaceRange = [
self clampSelection:replaceRange forText:textBeforeChange];
1279 [
self updateEditingStateWithDelta:flutter::TextEditingDelta(
1280 [textBeforeChange UTF8String],
1282 nextReplaceRange.location,
1283 nextReplaceRange.location + nextReplaceRange.length),
1284 [text UTF8String])];
1286 [
self updateEditingState];
1290 - (BOOL)shouldChangeTextInRange:(UITextRange*)range replacementText:(NSString*)text {
1293 self.temporarilyDeletedComposedCharacter = nil;
1295 if (
self.
returnKeyType == UIReturnKeyDefault && [text isEqualToString:
@"\n"]) {
1296 [
self.textInputDelegate flutterTextInputView:self
1297 performAction:FlutterTextInputActionNewline
1298 withClient:_textInputClient];
1302 if ([text isEqualToString:
@"\n"]) {
1303 FlutterTextInputAction action;
1305 case UIReturnKeyDefault:
1306 action = FlutterTextInputActionUnspecified;
1308 case UIReturnKeyDone:
1309 action = FlutterTextInputActionDone;
1312 action = FlutterTextInputActionGo;
1314 case UIReturnKeySend:
1315 action = FlutterTextInputActionSend;
1317 case UIReturnKeySearch:
1318 case UIReturnKeyGoogle:
1319 case UIReturnKeyYahoo:
1320 action = FlutterTextInputActionSearch;
1322 case UIReturnKeyNext:
1323 action = FlutterTextInputActionNext;
1325 case UIReturnKeyContinue:
1326 action = FlutterTextInputActionContinue;
1328 case UIReturnKeyJoin:
1329 action = FlutterTextInputActionJoin;
1331 case UIReturnKeyRoute:
1332 action = FlutterTextInputActionRoute;
1334 case UIReturnKeyEmergencyCall:
1335 action = FlutterTextInputActionEmergencyCall;
1339 [
self.textInputDelegate flutterTextInputView:self
1340 performAction:action
1341 withClient:_textInputClient];
1350 - (void)setMarkedText:(NSString*)markedText selectedRange:(NSRange)markedSelectedRange {
1351 NSString* textBeforeChange = [
self.text copy];
1354 _scribbleFocusStatus != FlutterScribbleFocusStatusUnfocused) {
1358 if (markedText == nil) {
1363 const NSRange& actualReplacedRange = currentMarkedTextRange && !currentMarkedTextRange.isEmpty
1364 ? currentMarkedTextRange.
range
1368 [
self.text replaceCharactersInRange:actualReplacedRange withString:markedText];
1370 const NSRange newMarkedRange = NSMakeRange(actualReplacedRange.location, markedText.length);
1371 self.markedTextRange =
1374 [
self setSelectedTextRangeLocal:
1376 rangeWithNSRange:[
self clampSelection:NSMakeRange(markedSelectedRange.location +
1377 newMarkedRange.location,
1378 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];
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];
1692 if (@available(iOS 17, *)) {
1698 NSUInteger first = start;
1703 CGRect startSelectionRect = CGRectNull;
1704 CGRect endSelectionRect = CGRectNull;
1707 CGFloat minY = CGFLOAT_MAX;
1708 CGFloat maxY = CGFLOAT_MIN;
1711 rangeWithNSRange:fml::RangeForCharactersInRange(self.text, NSMakeRange(0, self.text.length))];
1712 for (NSUInteger i = 0; i < [_selectionRects count]; i++) {
1713 BOOL startsOnOrBeforeStartOfRange = _selectionRects[i].position <= first;
1714 BOOL isLastSelectionRect = i + 1 == [_selectionRects count];
1715 BOOL endOfTextIsAfterStartOfRange = isLastSelectionRect && textRange.
range.length > first;
1716 BOOL nextSelectionRectIsAfterStartOfRange =
1717 !isLastSelectionRect && _selectionRects[i + 1].position > first;
1718 if (startsOnOrBeforeStartOfRange &&
1719 (endOfTextIsAfterStartOfRange || nextSelectionRectIsAfterStartOfRange)) {
1721 if (@available(iOS 17, *)) {
1722 startSelectionRect = _selectionRects[i].rect;
1724 return _selectionRects[i].rect;
1727 if (!CGRectIsNull(startSelectionRect)) {
1728 minY = fmin(minY, CGRectGetMinY(_selectionRects[i].rect));
1729 maxY = fmax(maxY, CGRectGetMaxY(_selectionRects[i].rect));
1730 BOOL endsOnOrAfterEndOfRange = _selectionRects[i].position >= end - 1;
1731 BOOL nextSelectionRectIsOnNextLine =
1732 !isLastSelectionRect &&
1737 CGRectGetMidY(_selectionRects[i + 1].rect) > CGRectGetMaxY(_selectionRects[i].rect);
1738 if (endsOnOrAfterEndOfRange || isLastSelectionRect || nextSelectionRectIsOnNextLine) {
1739 endSelectionRect = _selectionRects[i].rect;
1744 if (CGRectIsNull(startSelectionRect) || CGRectIsNull(endSelectionRect)) {
1748 CGFloat minX = fmin(CGRectGetMinX(startSelectionRect), CGRectGetMinX(endSelectionRect));
1749 CGFloat maxX = fmax(CGRectGetMaxX(startSelectionRect), CGRectGetMaxX(endSelectionRect));
1750 return CGRectMake(minX, minY, maxX - minX, maxY - minY);
1758 NSArray<UITextSelectionRect*>* rects = [
self
1760 rangeWithNSRange:fml::RangeForCharactersInRange(
1764 (index >= (NSInteger)self.text.length)
1767 if (rects.count == 0) {
1773 CGRect characterAfterCaret = rects[0].rect;
1778 return CGRectMake(characterAfterCaret.origin.x + characterAfterCaret.size.width,
1779 characterAfterCaret.origin.y, 0, characterAfterCaret.size.height);
1781 return CGRectMake(characterAfterCaret.origin.x, characterAfterCaret.origin.y, 0,
1782 characterAfterCaret.size.height);
1784 }
else if (rects.count == 2 && affinity == UITextStorageDirectionForward) {
1787 CGRect characterAfterCaret = rects[1].rect;
1792 return CGRectMake(characterAfterCaret.origin.x + characterAfterCaret.size.width,
1793 characterAfterCaret.origin.y, 0, characterAfterCaret.size.height);
1795 return CGRectMake(characterAfterCaret.origin.x, characterAfterCaret.origin.y, 0,
1796 characterAfterCaret.size.height);
1805 CGRect characterBeforeCaret = rects[0].rect;
1808 return CGRectMake(characterBeforeCaret.origin.x, characterBeforeCaret.origin.y, 0,
1809 characterBeforeCaret.size.height);
1811 return CGRectMake(characterBeforeCaret.origin.x + characterBeforeCaret.size.width,
1812 characterBeforeCaret.origin.y, 0, characterBeforeCaret.size.height);
1816 - (UITextPosition*)closestPositionToPoint:(CGPoint)point {
1817 if ([_selectionRects count] == 0) {
1819 @"Expected a FlutterTextPosition for position (got %@).",
1822 UITextStorageDirection currentAffinity =
1828 rangeWithNSRange:fml::RangeForCharactersInRange(self.text, NSMakeRange(0, self.text.length))];
1829 return [
self closestPositionToPoint:point withinRange:range];
1832 - (NSArray*)selectionRectsForRange:(UITextRange*)range {
1840 @"Expected a FlutterTextPosition for range.start (got %@).", [range.start
class]);
1842 @"Expected a FlutterTextPosition for range.end (got %@).", [range.end
class]);
1845 NSMutableArray* rects = [[NSMutableArray alloc] init];
1846 for (NSUInteger i = 0; i < [_selectionRects count]; i++) {
1847 if (_selectionRects[i].position >= start &&
1848 (_selectionRects[i].position < end ||
1849 (start == end && _selectionRects[i].position <= end))) {
1850 float width = _selectionRects[i].rect.size.width;
1854 CGRect rect = CGRectMake(_selectionRects[i].rect.origin.x, _selectionRects[i].rect.origin.y,
1855 width, _selectionRects[i].rect.size.height);
1858 position:_selectionRects[i].position
1862 self.text, NSMakeRange(0, self.text.length))
1865 [rects addObject:selectionRect];
1871 - (UITextPosition*)closestPositionToPoint:(CGPoint)point withinRange:(UITextRange*)range {
1873 @"Expected a FlutterTextPosition for range.start (got %@).", [range.start
class]);
1875 @"Expected a FlutterTextPosition for range.end (got %@).", [range.end
class]);
1885 NSUInteger _closestRectIndex = 0;
1886 for (NSUInteger i = 0; i < [_selectionRects count]; i++) {
1887 NSUInteger position = _selectionRects[i].position;
1888 if (position >= start && position <= end) {
1891 point, _selectionRects[i].rect, _selectionRects[i].isRTL,
1892 NO, _selectionRects[_closestRectIndex].rect,
1893 _selectionRects[_closestRectIndex].isRTL, verticalPrecision)) {
1895 _closestRectIndex = i;
1902 affinity:UITextStorageDirectionForward];
1908 for (NSUInteger i = MAX(0, _closestRectIndex - 1);
1909 i < MIN(_closestRectIndex + 2, [_selectionRects count]); i++) {
1910 NSUInteger position = _selectionRects[i].position + 1;
1911 if (position >= start && position <= end) {
1913 point, _selectionRects[i].rect, _selectionRects[i].isRTL,
1914 YES, _selectionRects[_closestRectIndex].rect,
1915 _selectionRects[_closestRectIndex].isRTL, verticalPrecision)) {
1918 affinity:UITextStorageDirectionBackward];
1923 return closestPosition;
1926 - (UITextRange*)characterRangeAtPoint:(CGPoint)point {
1929 return [
FlutterTextRange rangeWithNSRange:fml::RangeForCharacterAtIndex(self.text, currentIndex)];
1960 - (void)beginFloatingCursorAtPoint:(CGPoint)point {
1977 [
self.textInputDelegate flutterTextInputView:self
1978 updateFloatingCursor:FlutterFloatingCursorDragStateStart
1979 withClient:_textInputClient
1980 withPosition:@{@"X" : @0, @"Y" : @0}];
1983 - (void)updateFloatingCursorAtPoint:(CGPoint)point {
1984 [
self.textInputDelegate flutterTextInputView:self
1985 updateFloatingCursor:FlutterFloatingCursorDragStateUpdate
1986 withClient:_textInputClient
1988 @"X" : @(point.x - _floatingCursorOffset.x),
1989 @"Y" : @(point.y - _floatingCursorOffset.y)
1993 - (void)endFloatingCursor {
1995 [
self.textInputDelegate flutterTextInputView:self
1996 updateFloatingCursor:FlutterFloatingCursorDragStateEnd
1997 withClient:_textInputClient
1998 withPosition:@{@"X" : @0, @"Y" : @0}];
2001 #pragma mark - UIKeyInput Overrides
2003 - (void)updateEditingState {
2008 NSInteger composingBase = -1;
2009 NSInteger composingExtent = -1;
2014 NSDictionary* state = @{
2015 @"selectionBase" : @(selectionBase),
2016 @"selectionExtent" : @(selectionExtent),
2018 @"selectionIsDirectional" : @(
false),
2019 @"composingBase" : @(composingBase),
2020 @"composingExtent" : @(composingExtent),
2021 @"text" : [NSString stringWithString:self.text],
2024 if (_textInputClient == 0 && _autofillId != nil) {
2025 [
self.textInputDelegate flutterTextInputView:self
2026 updateEditingClient:_textInputClient
2028 withTag:_autofillId];
2030 [
self.textInputDelegate flutterTextInputView:self
2031 updateEditingClient:_textInputClient
2036 - (void)updateEditingStateWithDelta:(
flutter::TextEditingDelta)delta {
2041 NSInteger composingBase = -1;
2042 NSInteger composingExtent = -1;
2048 NSDictionary* deltaToFramework = @{
2049 @"oldText" : @(delta.old_text().c_str()),
2050 @"deltaText" : @(delta.delta_text().c_str()),
2051 @"deltaStart" : @(delta.delta_start()),
2052 @"deltaEnd" : @(delta.delta_end()),
2053 @"selectionBase" : @(selectionBase),
2054 @"selectionExtent" : @(selectionExtent),
2056 @"selectionIsDirectional" : @(
false),
2057 @"composingBase" : @(composingBase),
2058 @"composingExtent" : @(composingExtent),
2061 [_pendingDeltas addObject:deltaToFramework];
2063 if (_pendingDeltas.count == 1) {
2065 dispatch_async(dispatch_get_main_queue(), ^{
2067 if (strongSelf && strongSelf.pendingDeltas.count > 0) {
2068 NSDictionary* deltas = @{
2069 @"deltas" : strongSelf.pendingDeltas,
2072 [strongSelf.textInputDelegate flutterTextInputView:strongSelf
2073 updateEditingClient:strongSelf->_textInputClient
2075 [strongSelf.pendingDeltas removeAllObjects];
2082 return self.text.length > 0;
2085 - (void)insertText:(NSString*)text {
2086 if (
self.temporarilyDeletedComposedCharacter.length > 0 && text.length == 1 && !text.UTF8String &&
2087 [text characterAtIndex:0] == [
self.temporarilyDeletedComposedCharacter characterAtIndex:0]) {
2091 text =
self.temporarilyDeletedComposedCharacter;
2092 self.temporarilyDeletedComposedCharacter = nil;
2095 NSMutableArray<FlutterTextSelectionRect*>* copiedRects =
2096 [[NSMutableArray alloc] initWithCapacity:[_selectionRects count]];
2098 @"Expected a FlutterTextPosition for position (got %@).",
2101 for (NSUInteger i = 0; i < [_selectionRects count]; i++) {
2102 NSUInteger rectPosition = _selectionRects[i].position;
2103 if (rectPosition == insertPosition) {
2104 for (NSUInteger j = 0; j <= text.length; j++) {
2111 if (rectPosition > insertPosition) {
2112 rectPosition = rectPosition + text.length;
2121 _scribbleFocusStatus = FlutterScribbleFocusStatusUnfocused;
2122 [
self resetScribbleInteractionStatusIfEnding];
2123 self.selectionRects = copiedRects;
2125 [
self replaceRange:_selectedTextRange withText:text];
2128 - (UITextPlaceholder*)insertTextPlaceholderWithSize:(CGSize)size API_AVAILABLE(ios(13.0)) {
2129 [
self.textInputDelegate flutterTextInputView:self
2130 insertTextPlaceholderWithSize:size
2131 withClient:_textInputClient];
2136 - (void)removeTextPlaceholder:(UITextPlaceholder*)textPlaceholder API_AVAILABLE(ios(13.0)) {
2138 [
self.textInputDelegate flutterTextInputView:self removeTextPlaceholder:_textInputClient];
2141 - (void)deleteBackward {
2143 _scribbleFocusStatus = FlutterScribbleFocusStatusUnfocused;
2144 [
self resetScribbleInteractionStatusIfEnding];
2161 if (oldRange.location > 0) {
2162 NSRange newRange = NSMakeRange(oldRange.location - 1, 1);
2166 NSRange charRange = fml::RangeForCharacterAtIndex(
self.text, oldRange.location - 1);
2167 if (
IsEmoji(
self.text, charRange)) {
2168 newRange = NSMakeRange(charRange.location, oldRange.location - charRange.location);
2180 NSString* deletedText = [
self.text substringWithRange:_selectedTextRange.range];
2181 NSRange deleteFirstCharacterRange = fml::RangeForCharacterAtIndex(deletedText, 0);
2182 self.temporarilyDeletedComposedCharacter =
2183 [deletedText substringWithRange:deleteFirstCharacterRange];
2185 [
self replaceRange:_selectedTextRange withText:@""];
2189 - (void)postAccessibilityNotification:(UIAccessibilityNotifications)notification target:(
id)target {
2190 UIAccessibilityPostNotification(notification, target);
2193 - (void)accessibilityElementDidBecomeFocused {
2194 if ([
self accessibilityElementIsFocused]) {
2198 FML_DCHECK(_backingTextInputAccessibilityObject);
2199 [
self postAccessibilityNotification:UIAccessibilityScreenChangedNotification
2200 target:_backingTextInputAccessibilityObject];
2204 - (BOOL)accessibilityElementsHidden {
2205 return !_accessibilityEnabled;
2214 #pragma mark - Key Events Handling
2215 - (void)pressesBegan:(NSSet<UIPress*>*)presses
2216 withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
2217 [_textInputPlugin.viewController pressesBegan:presses withEvent:event];
2220 - (void)pressesChanged:(NSSet<UIPress*>*)presses
2221 withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
2222 [_textInputPlugin.viewController pressesChanged:presses withEvent:event];
2225 - (void)pressesEnded:(NSSet<UIPress*>*)presses
2226 withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
2227 [_textInputPlugin.viewController pressesEnded:presses withEvent:event];
2230 - (void)pressesCancelled:(NSSet<UIPress*>*)presses
2231 withEvent:(UIPressesEvent*)event API_AVAILABLE(ios(9.0)) {
2232 [_textInputPlugin.viewController pressesCancelled:presses withEvent:event];
2261 - (BOOL)accessibilityElementsHidden {
2268 - (void)enableActiveViewAccessibility;
2285 - (void)enableActiveViewAccessibility {
2286 [
self.target enableActiveViewAccessibility];
2293 @property(nonatomic, readonly)
2294 NSMutableDictionary<NSString*, FlutterTextInputView*>* autofillContext;
2299 @property(nonatomic, strong) UIView* keyboardViewContainer;
2300 @property(nonatomic, strong) UIView* keyboardView;
2301 @property(nonatomic, strong) UIView* cachedFirstResponder;
2302 @property(nonatomic, assign) CGRect keyboardRect;
2303 @property(nonatomic, assign) CGFloat previousPointerYPosition;
2304 @property(nonatomic, assign) CGFloat pointerYVelocity;
2308 NSTimer* _enableFlutterTextInputViewAccessibilityTimer;
2312 self = [
super init];
2315 _textInputDelegate = textInputDelegate;
2316 _autofillContext = [[NSMutableDictionary alloc] init];
2318 _scribbleElements = [[NSMutableDictionary alloc] init];
2319 _keyboardViewContainer = [[UIView alloc] init];
2321 [[NSNotificationCenter defaultCenter] addObserver:self
2322 selector:@selector(handleKeyboardWillShow:)
2323 name:UIKeyboardWillShowNotification
2330 - (void)handleKeyboardWillShow:(NSNotification*)notification {
2331 NSDictionary* keyboardInfo = [notification userInfo];
2332 NSValue* keyboardFrameEnd = [keyboardInfo valueForKey:UIKeyboardFrameEndUserInfoKey];
2333 _keyboardRect = [keyboardFrameEnd CGRectValue];
2337 [
self hideTextInput];
2340 - (void)removeEnableFlutterTextInputViewAccessibilityTimer {
2341 if (_enableFlutterTextInputViewAccessibilityTimer) {
2342 [_enableFlutterTextInputViewAccessibilityTimer invalidate];
2343 _enableFlutterTextInputViewAccessibilityTimer = nil;
2347 - (UIView<UITextInput>*)textInputView {
2352 NSString* method = call.
method;
2355 [
self showTextInput];
2357 }
else if ([method isEqualToString:
kHideMethod]) {
2358 [
self hideTextInput];
2361 [
self setTextInputClient:[args[0] intValue] withConfiguration:args[1]];
2365 [
self setPlatformViewTextInputClient];
2368 [
self setTextInputEditingState:args];
2371 [
self clearTextInputClient];
2374 [
self setEditableSizeAndTransform:args];
2377 [
self updateMarkedRect:args];
2380 [
self triggerAutofillSave:[args boolValue]];
2386 [
self setSelectionRects:args];
2389 [
self setSelectionRects:args];
2392 [
self startLiveTextInput];
2395 [
self updateConfig:args];
2398 CGFloat pointerY = (CGFloat)[args[
@"pointerY"] doubleValue];
2399 [
self handlePointerMove:pointerY];
2402 CGFloat pointerY = (CGFloat)[args[
@"pointerY"] doubleValue];
2403 [
self handlePointerUp:pointerY];
2410 - (void)handlePointerUp:(CGFloat)pointerY {
2411 if (_keyboardView.superview != nil) {
2415 CGFloat screenHeight = screen.bounds.size.height;
2416 CGFloat keyboardHeight = _keyboardRect.size.height;
2418 BOOL shouldDismissKeyboardBasedOnVelocity = _pointerYVelocity < 0;
2419 [UIView animateWithDuration:kKeyboardAnimationTimeToCompleteion
2421 double keyboardDestination =
2422 shouldDismissKeyboardBasedOnVelocity ? screenHeight : screenHeight - keyboardHeight;
2423 _keyboardViewContainer.frame = CGRectMake(
2424 0, keyboardDestination, _viewController.flutterScreenIfViewLoaded.bounds.size.width,
2425 _keyboardViewContainer.frame.size.height);
2427 completion:^(BOOL finished) {
2428 if (shouldDismissKeyboardBasedOnVelocity) {
2429 [
self.textInputDelegate flutterTextInputView:self.activeView
2430 didResignFirstResponderWithTextInputClient:self.activeView.textInputClient];
2431 [
self dismissKeyboardScreenshot];
2433 [
self showKeyboardAndRemoveScreenshot];
2439 - (void)dismissKeyboardScreenshot {
2440 for (UIView* subView in _keyboardViewContainer.subviews) {
2441 [subView removeFromSuperview];
2445 - (void)showKeyboardAndRemoveScreenshot {
2446 [UIView setAnimationsEnabled:NO];
2447 [_cachedFirstResponder becomeFirstResponder];
2451 dispatch_get_main_queue(), ^{
2452 [UIView setAnimationsEnabled:YES];
2453 [
self dismissKeyboardScreenshot];
2457 - (void)handlePointerMove:(CGFloat)pointerY {
2460 CGFloat screenHeight = screen.bounds.size.height;
2461 CGFloat keyboardHeight = _keyboardRect.size.height;
2462 if (screenHeight - keyboardHeight <= pointerY) {
2464 if (_keyboardView.superview == nil) {
2466 [
self takeKeyboardScreenshotAndDisplay];
2467 [
self hideKeyboardWithoutAnimationAndAvoidCursorDismissUpdate];
2469 [
self setKeyboardContainerHeight:pointerY];
2470 _pointerYVelocity = _previousPointerYPosition - pointerY;
2473 if (_keyboardView.superview != nil) {
2475 _keyboardViewContainer.frame = _keyboardRect;
2476 _pointerYVelocity = _previousPointerYPosition - pointerY;
2479 _previousPointerYPosition = pointerY;
2482 - (void)setKeyboardContainerHeight:(CGFloat)pointerY {
2483 CGRect frameRect = _keyboardRect;
2484 frameRect.origin.y = pointerY;
2485 _keyboardViewContainer.frame = frameRect;
2488 - (void)hideKeyboardWithoutAnimationAndAvoidCursorDismissUpdate {
2489 [UIView setAnimationsEnabled:NO];
2490 _cachedFirstResponder = UIApplication.sharedApplication.keyWindow.flutterFirstResponder;
2491 _activeView.preventCursorDismissWhenResignFirstResponder = YES;
2492 [_cachedFirstResponder resignFirstResponder];
2493 _activeView.preventCursorDismissWhenResignFirstResponder = NO;
2494 [UIView setAnimationsEnabled:YES];
2497 - (void)takeKeyboardScreenshotAndDisplay {
2500 UIView* keyboardSnap = [screen snapshotViewAfterScreenUpdates:YES];
2501 keyboardSnap = [keyboardSnap resizableSnapshotViewFromRect:_keyboardRect
2502 afterScreenUpdates:YES
2503 withCapInsets:UIEdgeInsetsZero];
2504 _keyboardView = keyboardSnap;
2505 [_keyboardViewContainer addSubview:_keyboardView];
2506 if (_keyboardViewContainer.superview == nil) {
2507 [UIApplication.sharedApplication.delegate.window.rootViewController.view
2508 addSubview:_keyboardViewContainer];
2510 _keyboardViewContainer.layer.zPosition = NSIntegerMax;
2511 _keyboardViewContainer.frame = _keyboardRect;
2514 - (void)setEditableSizeAndTransform:(NSDictionary*)dictionary {
2515 NSArray* transform = dictionary[@"transform"];
2516 [_activeView setEditableTransform:transform];
2517 const int leftIndex = 12;
2518 const int topIndex = 13;
2522 CGRectMake([transform[leftIndex] intValue], [transform[topIndex] intValue],
2523 [dictionary[
@"width"] intValue], [dictionary[
@"height"] intValue]);
2525 CGRectMake(0, 0, [dictionary[
@"width"] intValue], [dictionary[
@"height"] intValue]);
2526 _activeView.tintColor = [UIColor clearColor];
2531 if (@available(iOS 17, *)) {
2539 CGRectMake([transform[leftIndex] intValue], [transform[topIndex] intValue], 0, 0);
2544 - (void)updateMarkedRect:(NSDictionary*)dictionary {
2545 NSAssert(dictionary[
@"x"] != nil && dictionary[
@"y"] != nil && dictionary[
@"width"] != nil &&
2546 dictionary[
@"height"] != nil,
2547 @"Expected a dictionary representing a CGRect, got %@", dictionary);
2548 CGRect rect = CGRectMake([dictionary[
@"x"] doubleValue], [dictionary[
@"y"] doubleValue],
2549 [dictionary[
@"width"] doubleValue], [dictionary[
@"height"] doubleValue]);
2550 _activeView.markedRect = rect.size.width < 0 && rect.size.height < 0 ?
kInvalidFirstRect : rect;
2553 - (void)setSelectionRects:(NSArray*)encodedRects {
2554 NSMutableArray<FlutterTextSelectionRect*>* rectsAsRect =
2555 [[NSMutableArray alloc] initWithCapacity:[encodedRects count]];
2556 for (NSUInteger i = 0; i < [encodedRects count]; i++) {
2557 NSArray<NSNumber*>* encodedRect = encodedRects[i];
2559 selectionRectWithRect:CGRectMake([encodedRect[0] floatValue],
2560 [encodedRect[1] floatValue],
2561 [encodedRect[2] floatValue],
2562 [encodedRect[3] floatValue])
2563 position:[encodedRect[4] unsignedIntegerValue]
2564 writingDirection:[encodedRect[5] unsignedIntegerValue] == 1
2565 ? NSWritingDirectionLeftToRight
2566 : NSWritingDirectionRightToLeft]];
2572 _activeView.selectionRects = rectsAsRect;
2575 - (void)startLiveTextInput {
2576 if (@available(iOS 15.0, *)) {
2577 if (_activeView == nil || !_activeView.isFirstResponder) {
2580 [_activeView captureTextFromCamera:nil];
2584 - (void)showTextInput {
2585 _activeView.viewResponder = _viewResponder;
2586 [
self addToInputParentViewIfNeeded:_activeView];
2595 if (!_enableFlutterTextInputViewAccessibilityTimer) {
2596 _enableFlutterTextInputViewAccessibilityTimer =
2597 [NSTimer scheduledTimerWithTimeInterval:kUITextInputAccessibilityEnablingDelaySeconds
2599 selector:@selector(enableActiveViewAccessibility)
2603 [_activeView becomeFirstResponder];
2606 - (void)enableActiveViewAccessibility {
2607 if (_activeView.isFirstResponder) {
2608 _activeView.accessibilityEnabled = YES;
2610 [
self removeEnableFlutterTextInputViewAccessibilityTimer];
2613 - (void)hideTextInput {
2614 [
self removeEnableFlutterTextInputViewAccessibilityTimer];
2615 _activeView.accessibilityEnabled = NO;
2616 [_activeView resignFirstResponder];
2617 [_activeView removeFromSuperview];
2618 [_inputHider removeFromSuperview];
2621 - (void)triggerAutofillSave:(BOOL)saveEntries {
2622 [_activeView resignFirstResponder];
2627 [
self cleanUpViewHierarchy:YES clearText:YES delayRemoval:NO];
2628 [_autofillContext removeAllObjects];
2629 [
self changeInputViewsAutofillVisibility:YES];
2631 [_autofillContext removeAllObjects];
2634 [
self cleanUpViewHierarchy:YES clearText:!saveEntries delayRemoval:NO];
2635 [
self addToInputParentViewIfNeeded:_activeView];
2638 - (void)setPlatformViewTextInputClient {
2642 [
self removeEnableFlutterTextInputViewAccessibilityTimer];
2643 _activeView.accessibilityEnabled = NO;
2644 [_activeView removeFromSuperview];
2645 [_inputHider removeFromSuperview];
2648 - (void)setTextInputClient:(
int)client withConfiguration:(NSDictionary*)configuration {
2649 [
self resetAllClientIds];
2652 [
self changeInputViewsAutofillVisibility:NO];
2656 case kFlutterAutofillTypeNone:
2657 self.activeView = [
self createInputViewWith:configuration];
2659 case kFlutterAutofillTypeRegular:
2662 self.activeView = [
self updateAndShowAutofillViews:nil
2663 focusedField:configuration
2664 isPasswordRelated:NO];
2666 case kFlutterAutofillTypePassword:
2667 self.activeView = [
self updateAndShowAutofillViews:configuration[kAssociatedAutofillFields]
2668 focusedField:configuration
2669 isPasswordRelated:YES];
2672 [_activeView setTextInputClient:client];
2673 [_activeView reloadInputViews];
2685 [
self cleanUpViewHierarchy:NO clearText:YES delayRemoval:YES];
2696 [_autofillContext removeObjectForKey:autofillId];
2699 [newView configureWithDictionary:configuration];
2700 [
self addToInputParentViewIfNeeded:newView];
2704 if (autofillId &&
AutofillTypeOf(field) == kFlutterAutofillTypeNone) {
2705 [_autofillContext removeObjectForKey:autofillId];
2712 focusedField:(NSDictionary*)focusedField
2713 isPasswordRelated:(BOOL)isPassword {
2716 NSAssert(focusedId,
@"autofillId must not be null for the focused field: %@", focusedField);
2721 focused = [
self getOrCreateAutofillableView:focusedField isPasswordAutofill:isPassword];
2722 [_autofillContext removeObjectForKey:focusedId];
2725 for (NSDictionary* field in fields) {
2727 NSAssert(autofillId,
@"autofillId must not be null for field: %@", field);
2729 BOOL hasHints =
AutofillTypeOf(field) != kFlutterAutofillTypeNone;
2730 BOOL isFocused = [focusedId isEqualToString:autofillId];
2733 focused = [
self getOrCreateAutofillableView:field isPasswordAutofill:isPassword];
2738 _autofillContext[autofillId] = isFocused ? focused
2739 : [
self getOrCreateAutofillableView:field
2740 isPasswordAutofill:isPassword];
2743 [_autofillContext removeObjectForKey:autofillId];
2747 NSAssert(focused,
@"The current focused input view must not be nil.");
2757 isPasswordAutofill:(BOOL)needsPasswordAutofill {
2763 inputView = [inputView initWithOwner:self];
2764 [
self addToInputParentViewIfNeeded:inputView];
2767 [inputView configureWithDictionary:field];
2772 - (UIView*)hostView {
2774 NSAssert(host !=
nullptr,
2775 @"The application must have a host view since the keyboard client "
2776 @"must be part of the responder chain to function. The host view controller is %@",
2782 - (NSArray<UIView*>*)textInputViews {
2783 return _inputHider.subviews;
2796 - (void)cleanUpViewHierarchy:(BOOL)includeActiveView
2797 clearText:(BOOL)clearText
2798 delayRemoval:(BOOL)delayRemoval {
2799 for (UIView* view in
self.textInputViews) {
2801 (includeActiveView || view != _activeView)) {
2803 if (_autofillContext[inputView.autofillId] != view) {
2805 [inputView replaceRangeLocal:NSMakeRange(0, inputView.text.length) withText:@""];
2808 [inputView performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.1];
2810 [inputView removeFromSuperview];
2819 - (void)changeInputViewsAutofillVisibility:(BOOL)newVisibility {
2820 for (UIView* view in
self.textInputViews) {
2823 inputView.isVisibleToAutofill = newVisibility;
2835 - (void)resetAllClientIds {
2836 for (UIView* view in
self.textInputViews) {
2839 [inputView setTextInputClient:0];
2845 if (![inputView isDescendantOfView:_inputHider]) {
2846 [_inputHider addSubview:inputView];
2855 UIView* parentView =
self.hostView;
2856 if (_inputHider.superview != parentView) {
2857 [parentView addSubview:_inputHider];
2861 - (void)setTextInputEditingState:(NSDictionary*)state {
2862 [_activeView setTextInputState:state];
2865 - (void)clearTextInputClient {
2866 [_activeView setTextInputClient:0];
2867 _activeView.frame = CGRectZero;
2870 - (void)updateConfig:(NSDictionary*)dictionary {
2871 BOOL isSecureTextEntry = [dictionary[kSecureTextEntry] boolValue];
2872 for (UIView* view in
self.textInputViews) {
2879 if (inputView.isSecureTextEntry != isSecureTextEntry) {
2880 inputView.secureTextEntry = isSecureTextEntry;
2881 [inputView reloadInputViews];
2887 #pragma mark UIIndirectScribbleInteractionDelegate
2889 - (BOOL)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2890 isElementFocused:(UIScribbleElementIdentifier)elementIdentifier
2891 API_AVAILABLE(ios(14.0)) {
2892 return _activeView.scribbleFocusStatus == FlutterScribbleFocusStatusFocused;
2895 - (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2896 focusElementIfNeeded:(UIScribbleElementIdentifier)elementIdentifier
2897 referencePoint:(CGPoint)focusReferencePoint
2898 completion:(
void (^)(UIResponder<UITextInput>* focusedInput))completion
2899 API_AVAILABLE(ios(14.0)) {
2900 _activeView.scribbleFocusStatus = FlutterScribbleFocusStatusFocusing;
2901 [_indirectScribbleDelegate flutterTextInputPlugin:self
2902 focusElement:elementIdentifier
2903 atPoint:focusReferencePoint
2904 result:^(id _Nullable result) {
2905 _activeView.scribbleFocusStatus =
2906 FlutterScribbleFocusStatusFocused;
2907 completion(_activeView);
2911 - (BOOL)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2912 shouldDelayFocusForElement:(UIScribbleElementIdentifier)elementIdentifier
2913 API_AVAILABLE(ios(14.0)) {
2917 - (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2918 willBeginWritingInElement:(UIScribbleElementIdentifier)elementIdentifier
2919 API_AVAILABLE(ios(14.0)) {
2922 - (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2923 didFinishWritingInElement:(UIScribbleElementIdentifier)elementIdentifier
2924 API_AVAILABLE(ios(14.0)) {
2927 - (CGRect)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2928 frameForElement:(UIScribbleElementIdentifier)elementIdentifier
2929 API_AVAILABLE(ios(14.0)) {
2930 NSValue* elementValue = [_scribbleElements objectForKey:elementIdentifier];
2931 if (elementValue == nil) {
2934 return [elementValue CGRectValue];
2937 - (void)indirectScribbleInteraction:(UIIndirectScribbleInteraction*)interaction
2938 requestElementsInRect:(CGRect)rect
2940 (
void (^)(NSArray<UIScribbleElementIdentifier>* elements))completion
2941 API_AVAILABLE(ios(14.0)) {
2942 [_indirectScribbleDelegate
2943 flutterTextInputPlugin:self
2944 requestElementsInRect:rect
2945 result:^(id _Nullable result) {
2946 NSMutableArray<UIScribbleElementIdentifier>* elements =
2947 [[NSMutableArray alloc] init];
2948 if ([result isKindOfClass:[NSArray class]]) {
2949 for (NSArray* elementArray in result) {
2950 [elements addObject:elementArray[0]];
2953 valueWithCGRect:CGRectMake(
2954 [elementArray[1] floatValue],
2955 [elementArray[2] floatValue],
2956 [elementArray[3] floatValue],
2957 [elementArray[4] floatValue])]
2958 forKey:elementArray[0]];
2961 completion(elements);
2965 #pragma mark - Methods related to Scribble support
2969 if (@available(iOS 14.0, *)) {
2971 if (parentView != nil) {
2972 UIIndirectScribbleInteraction* scribbleInteraction = [[UIIndirectScribbleInteraction alloc]
2973 initWithDelegate:(id<UIIndirectScribbleInteractionDelegate>)self];
2974 [parentView addInteraction:scribbleInteraction];
2981 - (void)resetViewResponder {
2982 _viewResponder = nil;
2986 #pragma mark FlutterKeySecondaryResponder
3001 - (id)flutterFirstResponder {
3002 if (
self.isFirstResponder) {
3005 for (UIView* subView in
self.subviews) {
3006 UIView* firstResponder = subView.flutterFirstResponder;
3007 if (firstResponder) {
3008 return firstResponder;