5
5
#include " flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
6
6
7
7
#include < UIKit/UIKit.h>
8
+ #include < Foundation/Foundation.h>
8
9
9
10
static const char _kTextAffinityDownstream[] = " TextAffinity.downstream" ;
10
11
static const char _kTextAffinityUpstream[] = " TextAffinity.upstream" ;
@@ -30,9 +31,46 @@ static UIKeyboardType ToUIKeyboardType(NSDictionary* type) {
30
31
}
31
32
32
33
static UIReturnKeyType ToUIReturnKeyType (NSString * inputType) {
33
- if ([inputType isEqualToString: @" TextInputType.multiline" ])
34
+ // Where did the term "unspecified" come from? iOS has a "default" and Android
35
+ // has "unspecified." These 2 terms seem to mean the same thing but we need
36
+ // to pick just one. "unspecified" was chosen because "default" is often a
37
+ // reserved word in languages with switch statements (dart, java, etc).
38
+ if ([inputType isEqualToString: @" TextInputAction.unspecified" ])
39
+ return UIReturnKeyDefault;
40
+
41
+ if ([inputType isEqualToString: @" TextInputAction.done" ])
42
+ return UIReturnKeyDone;
43
+
44
+ if ([inputType isEqualToString: @" TextInputAction.go" ])
45
+ return UIReturnKeyGo;
46
+
47
+ if ([inputType isEqualToString: @" TextInputAction.send" ])
48
+ return UIReturnKeySend;
49
+
50
+ if ([inputType isEqualToString: @" TextInputAction.search" ])
51
+ return UIReturnKeySearch;
52
+
53
+ if ([inputType isEqualToString: @" TextInputAction.next" ])
54
+ return UIReturnKeyNext;
55
+
56
+ if (@available (iOS 9.0 , *))
57
+ if ([inputType isEqualToString: @" TextInputAction.continueAction" ])
58
+ return UIReturnKeyContinue;
59
+
60
+ if ([inputType isEqualToString: @" TextInputAction.join" ])
61
+ return UIReturnKeyJoin;
62
+
63
+ if ([inputType isEqualToString: @" TextInputAction.route" ])
64
+ return UIReturnKeyRoute;
65
+
66
+ if ([inputType isEqualToString: @" TextInputAction.emergencyCall" ])
67
+ return UIReturnKeyEmergencyCall;
68
+
69
+ if ([inputType isEqualToString: @" TextInputAction.newline" ])
34
70
return UIReturnKeyDefault;
35
- return UIReturnKeyDone;
71
+
72
+ // Present default key if bad input type is given.
73
+ return UIReturnKeyDefault;
36
74
}
37
75
38
76
static UITextAutocapitalizationType ToUITextAutocapitalizationType (NSString * inputType) {
@@ -277,14 +315,52 @@ - (void)replaceRange:(UITextRange*)range withText:(NSString*)text {
277
315
}
278
316
279
317
- (BOOL )shouldChangeTextInRange : (UITextRange*)range replacementText : (NSString *)text {
280
- if (self.returnKeyType == UIReturnKeyDone && [text isEqualToString: @" \n " ]) {
281
- [self resignFirstResponder ];
282
- [self removeFromSuperview ];
283
- [_textInputDelegate performAction: FlutterTextInputActionDone withClient: _textInputClient];
318
+ if (self.returnKeyType == UIReturnKeyDefault && [text isEqualToString: @" \n " ]) {
319
+ [_textInputDelegate performAction: FlutterTextInputActionNewline withClient: _textInputClient];
320
+ return YES ;
321
+ }
322
+
323
+ if ([text isEqualToString: @" \n " ]) {
324
+ FlutterTextInputAction action;
325
+ switch (self.returnKeyType ) {
326
+ case UIReturnKeyDefault:
327
+ action = FlutterTextInputActionUnspecified;
328
+ break ;
329
+ case UIReturnKeyDone:
330
+ action = FlutterTextInputActionDone;
331
+ break ;
332
+ case UIReturnKeyGo:
333
+ action = FlutterTextInputActionGo;
334
+ break ;
335
+ case UIReturnKeySend:
336
+ action = FlutterTextInputActionSend;
337
+ break ;
338
+ case UIReturnKeySearch:
339
+ case UIReturnKeyGoogle:
340
+ case UIReturnKeyYahoo:
341
+ action = FlutterTextInputActionSearch;
342
+ break ;
343
+ case UIReturnKeyNext:
344
+ action = FlutterTextInputActionNext;
345
+ break ;
346
+ case UIReturnKeyContinue:
347
+ action = FlutterTextInputActionContinue;
348
+ break ;
349
+ case UIReturnKeyJoin:
350
+ action = FlutterTextInputActionJoin;
351
+ break ;
352
+ case UIReturnKeyRoute:
353
+ action = FlutterTextInputActionRoute;
354
+ break ;
355
+ case UIReturnKeyEmergencyCall:
356
+ action = FlutterTextInputActionEmergencyCall;
357
+ break ;
358
+ }
359
+
360
+ [_textInputDelegate performAction: action withClient: _textInputClient];
284
361
return NO ;
285
362
}
286
- if (self.returnKeyType == UIReturnKeyDefault && [text isEqualToString: @" \n " ])
287
- [_textInputDelegate performAction: FlutterTextInputActionNewline withClient: _textInputClient];
363
+
288
364
return YES ;
289
365
}
290
366
@@ -612,7 +688,7 @@ - (void)hideTextInput {
612
688
- (void )setTextInputClient : (int )client withConfiguration : (NSDictionary *)configuration {
613
689
NSDictionary * inputType = configuration[@" inputType" ];
614
690
_view.keyboardType = ToUIKeyboardType (inputType);
615
- _view.returnKeyType = ToUIReturnKeyType (inputType [@" name " ]);
691
+ _view.returnKeyType = ToUIReturnKeyType (configuration [@" inputAction " ]);
616
692
_view.autocapitalizationType = ToUITextAutocapitalizationType (inputType[@" name" ]);
617
693
_view.secureTextEntry = [configuration[@" obscureText" ] boolValue ];
618
694
NSString * autocorrect = configuration[@" autocorrect" ];
0 commit comments