Flutter iOS Embedder
FlutterTextInputPlugin.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
7 
8 #import <UIKit/UIKit.h>
9 
16 
17 typedef NS_ENUM(NSInteger, FlutterScribbleFocusStatus) {
18  // NOLINTBEGIN(readability-identifier-naming)
19  FlutterScribbleFocusStatusUnfocused,
20  FlutterScribbleFocusStatusFocusing,
21  FlutterScribbleFocusStatusFocused,
22  // NOLINTEND(readability-identifier-naming)
23 };
24 
25 typedef NS_ENUM(NSInteger, FlutterScribbleInteractionStatus) {
26  // NOLINTBEGIN(readability-identifier-naming)
27  FlutterScribbleInteractionStatusNone,
28  FlutterScribbleInteractionStatusStarted,
29  FlutterScribbleInteractionStatusEnding,
30  // NOLINTEND(readability-identifier-naming)
31 };
32 
34  : NSObject <FlutterKeySecondaryResponder, UIIndirectScribbleInteractionDelegate>
35 
36 @property(nonatomic, weak) UIViewController* viewController;
37 @property(nonatomic, weak) id<FlutterIndirectScribbleDelegate> indirectScribbleDelegate;
38 @property(nonatomic, strong)
39  NSMutableDictionary<UIScribbleElementIdentifier, NSValue*>* scribbleElements;
40 
41 - (instancetype)init NS_UNAVAILABLE;
42 + (instancetype)new NS_UNAVAILABLE;
43 
44 - (instancetype)initWithDelegate:(id<FlutterTextInputDelegate>)textInputDelegate
45  NS_DESIGNATED_INITIALIZER;
46 
47 - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result;
48 
49 /**
50  * The `UITextInput` implementation used to control text entry.
51  *
52  * This is used by `AccessibilityBridge` to forward interactions with iOS'
53  * accessibility system.
54  */
55 - (UIView<UITextInput>*)textInputView;
56 
57 /**
58  * These are used by the UIIndirectScribbleInteractionDelegate methods to handle focusing on the
59  * correct element.
60  */
61 - (void)setUpIndirectScribbleInteraction:(id<FlutterViewResponder>)viewResponder;
62 - (void)resetViewResponder;
63 - (BOOL)showEditMenu:(NSDictionary*)args API_AVAILABLE(ios(16.0));
64 - (void)hideEditMenu API_AVAILABLE(ios(16.0));
65 
66 @end
67 
68 /** An indexed position in the buffer of a Flutter text editing widget. */
69 @interface FlutterTextPosition : UITextPosition
70 
71 @property(nonatomic, readonly) NSUInteger index;
72 @property(nonatomic, readonly) UITextStorageDirection affinity;
73 
74 + (instancetype)positionWithIndex:(NSUInteger)index;
75 + (instancetype)positionWithIndex:(NSUInteger)index affinity:(UITextStorageDirection)affinity;
76 - (instancetype)initWithIndex:(NSUInteger)index affinity:(UITextStorageDirection)affinity;
77 
78 @end
79 
80 /** A range of text in the buffer of a Flutter text editing widget. */
81 @interface FlutterTextRange : UITextRange <NSCopying>
82 
83 @property(nonatomic, readonly) NSRange range;
84 
85 + (instancetype)rangeWithNSRange:(NSRange)range;
86 
87 @end
88 
89 /** A tokenizer used by `FlutterTextInputView` to customize string parsing. */
90 @interface FlutterTokenizer : UITextInputStringTokenizer
91 @end
92 
93 @interface FlutterTextSelectionRect : UITextSelectionRect
94 
95 @property(nonatomic, assign) CGRect rect;
96 @property(nonatomic) NSUInteger position;
97 @property(nonatomic, assign) NSWritingDirection writingDirection;
98 @property(nonatomic) BOOL containsStart;
99 @property(nonatomic) BOOL containsEnd;
100 @property(nonatomic) BOOL isVertical;
101 
102 + (instancetype)selectionRectWithRectAndInfo:(CGRect)rect
103  position:(NSUInteger)position
104  writingDirection:(NSWritingDirection)writingDirection
105  containsStart:(BOOL)containsStart
106  containsEnd:(BOOL)containsEnd
107  isVertical:(BOOL)isVertical;
108 
109 + (instancetype)selectionRectWithRect:(CGRect)rect position:(NSUInteger)position;
110 
111 + (instancetype)selectionRectWithRect:(CGRect)rect
112  position:(NSUInteger)position
113  writingDirection:(NSWritingDirection)writingDirection;
114 
115 - (instancetype)initWithRectAndInfo:(CGRect)rect
116  position:(NSUInteger)position
117  writingDirection:(NSWritingDirection)writingDirection
118  containsStart:(BOOL)containsStart
119  containsEnd:(BOOL)containsEnd
120  isVertical:(BOOL)isVertical;
121 
122 - (instancetype)init NS_UNAVAILABLE;
123 
124 - (BOOL)isRTL;
125 @end
126 
127 API_AVAILABLE(ios(13.0)) @interface FlutterTextPlaceholder : UITextPlaceholder
128 @end
129 
130 #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
132 #endif
133 @interface FlutterTextInputView
134  : UIView <UITextInput, UIScribbleInteractionDelegate, UIEditMenuInteractionDelegate>
135 
136 // UITextInput
137 @property(nonatomic, readonly) NSMutableString* text;
138 @property(readwrite, copy) UITextRange* selectedTextRange;
139 @property(nonatomic, strong) UITextRange* markedTextRange;
140 @property(nonatomic, copy) NSDictionary* markedTextStyle;
141 @property(nonatomic, weak) id<UITextInputDelegate> inputDelegate;
142 @property(nonatomic, strong) NSMutableArray* pendingDeltas;
143 
144 // UITextInputTraits
145 @property(nonatomic) UITextAutocapitalizationType autocapitalizationType;
146 @property(nonatomic) UITextAutocorrectionType autocorrectionType;
147 @property(nonatomic) UITextSpellCheckingType spellCheckingType;
148 @property(nonatomic) BOOL enablesReturnKeyAutomatically;
149 @property(nonatomic) UIKeyboardAppearance keyboardAppearance;
150 @property(nonatomic) UIKeyboardType keyboardType;
151 @property(nonatomic) UIReturnKeyType returnKeyType;
152 @property(nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry;
153 @property(nonatomic, getter=isEnableDeltaModel) BOOL enableDeltaModel;
154 @property(nonatomic) UITextSmartQuotesType smartQuotesType API_AVAILABLE(ios(11.0));
155 @property(nonatomic) UITextSmartDashesType smartDashesType API_AVAILABLE(ios(11.0));
156 @property(nonatomic, copy) UITextContentType textContentType API_AVAILABLE(ios(10.0));
157 
158 @property(nonatomic, weak) UIAccessibilityElement* backingTextInputAccessibilityObject;
159 
160 // Scribble Support
161 @property(nonatomic, weak) id<FlutterViewResponder> viewResponder;
162 @property(nonatomic) FlutterScribbleFocusStatus scribbleFocusStatus;
163 @property(nonatomic, strong) NSArray<FlutterTextSelectionRect*>* selectionRects;
164 
165 @property(nonatomic, strong) UIEditMenuInteraction* editMenuInteraction API_AVAILABLE(ios(16.0));
168 
169 - (instancetype)init NS_UNAVAILABLE;
170 + (instancetype)new NS_UNAVAILABLE;
171 - (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE;
172 - (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
173 - (instancetype)initWithOwner:(FlutterTextInputPlugin*)textInputPlugin NS_DESIGNATED_INITIALIZER;
174 
175 // TODO(louisehsu): These are being exposed to support Share in FlutterPlatformPlugin
176 // Consider moving that feature into FlutterTextInputPlugin to avoid exposing extra methods
177 - (CGRect)localRectFromFrameworkTransform:(CGRect)incomingRect;
178 - (CGRect)caretRectForPosition:(UITextPosition*)position;
179 @end
180 
182 @property(nonatomic, readonly) id flutterFirstResponder;
183 @end
184 
185 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERTEXTINPUTPLUGIN_H_
caretRectForPosition
CGRect caretRectForPosition
Definition: FlutterTextInputPlugin.h:178
selectionRects
NSArray< FlutterTextSelectionRect * > * selectionRects
Definition: FlutterTextInputPlugin.h:163
keyboardType
UIKeyboardType keyboardType
Definition: FlutterTextInputPlugin.h:150
returnKeyType
UIReturnKeyType returnKeyType
Definition: FlutterTextInputPlugin.h:151
FlutterTextInputDelegate-p
Definition: FlutterTextInputDelegate.h:37
FlutterTextInputPlugin::indirectScribbleDelegate
id< FlutterIndirectScribbleDelegate > indirectScribbleDelegate
Definition: FlutterTextInputPlugin.h:37
backingTextInputAccessibilityObject
UIAccessibilityElement * backingTextInputAccessibilityObject
Definition: FlutterTextInputPlugin.h:158
keyboardAppearance
UIKeyboardAppearance keyboardAppearance
Definition: FlutterTextInputPlugin.h:149
isScribbleAvailable
BOOL isScribbleAvailable
Definition: FlutterTextInputPlugin.h:167
FlutterTextInputDelegate.h
API_AVAILABLE
UITextSmartQuotesType smartQuotesType API_AVAILABLE(ios(11.0))
FlutterTokenizer
Definition: FlutterTextInputPlugin.h:90
FlutterChannels.h
secureTextEntry
BOOL secureTextEntry
Definition: FlutterTextInputPlugin.h:152
resetScribbleInteractionStatusIfEnding
void resetScribbleInteractionStatusIfEnding
Definition: FlutterTextInputPlugin.h:166
FlutterTextRange
Definition: FlutterTextInputPlugin.h:81
autocapitalizationType
UITextAutocapitalizationType autocapitalizationType
Definition: FlutterTextInputPlugin.h:145
initWithFrame
instancetype initWithFrame
Definition: FlutterTextInputPlugin.h:172
FlutterTextPlaceholder
Definition: FlutterTextInputPlugin.mm:728
autocorrectionType
UITextAutocorrectionType autocorrectionType
Definition: FlutterTextInputPlugin.h:146
-[FlutterTextInputPlugin textInputView]
UIView< UITextInput > * textInputView()
Definition: FlutterTextInputPlugin.mm:2387
initWithOwner
instancetype initWithOwner
Definition: FlutterTextInputPlugin.h:173
enablesReturnKeyAutomatically
BOOL enablesReturnKeyAutomatically
Definition: FlutterTextInputPlugin.h:148
viewController
FlutterViewController * viewController
Definition: FlutterTextInputPluginTest.mm:92
-[FlutterTextInputPlugin resetViewResponder]
void resetViewResponder()
Definition: FlutterTextInputPlugin.mm:3038
FlutterTextInputView
Definition: FlutterTextInputPlugin.mm:802
UIView(FindFirstResponder)
Definition: FlutterTextInputPlugin.h:181
FlutterTextInputPlugin::scribbleElements
NSMutableDictionary< UIScribbleElementIdentifier, NSValue * > * scribbleElements
Definition: FlutterTextInputPlugin.h:39
enableDeltaModel
BOOL enableDeltaModel
Definition: FlutterTextInputPlugin.h:153
FlutterViewResponder.h
selectedTextRange
API_AVAILABLE(ios(13.0)) @interface FlutterTextPlaceholder UITextRange * selectedTextRange
Definition: FlutterTextInputPlugin.h:127
FlutterMethodCall
Definition: FlutterCodecs.h:220
pendingDeltas
NSMutableArray * pendingDeltas
Definition: FlutterTextInputPlugin.h:142
FlutterTextInputPlugin
Definition: FlutterTextInputPlugin.h:33
localRectFromFrameworkTransform
CGRect localRectFromFrameworkTransform
Definition: FlutterTextInputPlugin.h:177
FlutterTextPosition::affinity
UITextStorageDirection affinity
Definition: FlutterTextInputPlugin.h:72
FlutterResult
void(^ FlutterResult)(id _Nullable result)
Definition: FlutterChannels.h:194
FlutterIndirectScribbleDelegate.h
initWithCoder
instancetype initWithCoder
Definition: FlutterTextInputPlugin.h:171
inputDelegate
id< UITextInputDelegate > inputDelegate
Definition: FlutterTextInputPlugin.h:141
viewResponder
id< FlutterViewResponder > viewResponder
Definition: FlutterTextInputPlugin.h:161
scribbleFocusStatus
FlutterScribbleFocusStatus scribbleFocusStatus
Definition: FlutterTextInputPlugin.h:162
NS_UNAVAILABLE
instancetype init NS_UNAVAILABLE
Definition: FlutterTextInputPlugin.h:169
FlutterTextPosition
Definition: FlutterTextInputPlugin.h:69
FlutterViewResponder-p
Definition: FlutterViewResponder.h:15
FLUTTER_DARWIN_EXPORT
#define FLUTTER_DARWIN_EXPORT
Definition: FlutterMacros.h:14
text_editing_delta.h
FlutterTextPosition::index
NSUInteger index
Definition: FlutterTextInputPlugin.h:71
FlutterKeySecondaryResponder.h
markedTextStyle
NSDictionary * markedTextStyle
Definition: FlutterTextInputPlugin.h:140
FlutterTextSelectionRect
Definition: FlutterTextInputPlugin.h:93
NS_ENUM
typedef NS_ENUM(NSInteger, FlutterScribbleFocusStatus)
Definition: FlutterTextInputPlugin.h:17
spellCheckingType
UITextSpellCheckingType spellCheckingType
Definition: FlutterTextInputPlugin.h:147
markedTextRange
UITextRange * markedTextRange
Definition: FlutterTextInputPlugin.h:139