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