Skip to content

Commit

Permalink
support returnKeyType (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryleunghk authored Dec 3, 2021
1 parent 2e756f0 commit 5f6924e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
35 changes: 35 additions & 0 deletions ios/Classes/NativeTextInput.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ - (instancetype)initWithFrame:(CGRect)frame
_textView.backgroundColor = UIColor.clearColor;
_textView.keyboardAppearance = [self keyboardAppearanceFromString:args[@"keyboardAppearance"]];
_textView.keyboardType = [self keyboardTypeFromString:args[@"keyboardType"]];
_textView.returnKeyType = [self returnKeyTypeFromString:args[@"returnKeyType"]];
_textView.textAlignment = [self textAlignmentFromString:args[@"textAlign"]];
_textView.autocapitalizationType = [self textAutocapitalizationTypeFromString:args[@"textCapitalization"]];
_textView.textContainer.lineBreakMode = NSLineBreakByCharWrapping;
Expand Down Expand Up @@ -162,6 +163,40 @@ - (UIKeyboardType)keyboardTypeFromString:(NSString*)keyboardType {
return UIKeyboardTypeDefault;
}

- (UIReturnKeyType)returnKeyTypeFromString:(NSString *)returnKeyType {
if (!returnKeyType || [returnKeyType isKindOfClass:[NSNull class]]) {
return UIReturnKeyDefault;
}

if ([returnKeyType isEqualToString:@"ReturnKeyType.defaultAction"]) {
return UIReturnKeyDefault;
} else if ([returnKeyType isEqualToString:@"ReturnKeyType.go"]) {
return UIReturnKeyGo;
} else if ([returnKeyType isEqualToString:@"ReturnKeyType.google"]) {
return UIReturnKeyGoogle;
} else if ([returnKeyType isEqualToString:@"ReturnKeyType.join"]) {
return UIReturnKeyJoin;
} else if ([returnKeyType isEqualToString:@"ReturnKeyType.next"]) {
return UIReturnKeyNext;
} else if ([returnKeyType isEqualToString:@"ReturnKeyType.route"]) {
return UIReturnKeyRoute;
} else if ([returnKeyType isEqualToString:@"ReturnKeyType.search"]) {
return UIReturnKeySearch;
} else if ([returnKeyType isEqualToString:@"ReturnKeyType.send"]) {
return UIReturnKeySend;
} else if ([returnKeyType isEqualToString:@"ReturnKeyType.yahoo"]) {
return UIReturnKeyYahoo;
} else if ([returnKeyType isEqualToString:@"ReturnKeyType.done"]) {
return UIReturnKeyDone;
} else if ([returnKeyType isEqualToString:@"ReturnKeyType.emergencyCall"]) {
return UIReturnKeyEmergencyCall;
} else if ([returnKeyType isEqualToString:@"ReturnKeyType.continueAction"]) {
return UIReturnKeyContinue;
}

return UIReturnKeyDefault;
}

- (UITextAutocapitalizationType)textAutocapitalizationTypeFromString:(NSString *)textCapitalization {
if (!textCapitalization || [textCapitalization isKindOfClass:[NSNull class]]) {
return UITextAutocapitalizationTypeNone;
Expand Down
27 changes: 23 additions & 4 deletions lib/flutter_native_text_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

enum ReturnKeyType {
defaultAction,
go,
google,
join,
next,
route,
search,
send,
yahoo,
done,
emergencyCall,
continueAction,
}

enum TextContentType {
name,
namePrefix,
Expand Down Expand Up @@ -82,6 +97,7 @@ class NativeTextInput extends StatefulWidget {
this.minLines = 1,
this.placeholder,
this.placeholderStyle,
this.returnKeyType = ReturnKeyType.defaultAction,
this.style,
this.textAlign = TextAlign.start,
this.textCapitalization = TextCapitalization.none,
Expand Down Expand Up @@ -109,6 +125,8 @@ class NativeTextInput extends StatefulWidget {

final int minLines;

final ReturnKeyType returnKeyType;

final String? placeholder;

final TextStyle? placeholderStyle;
Expand Down Expand Up @@ -204,15 +222,16 @@ class _NativeTextInputState extends State<NativeTextInput> {

Map<String, dynamic> _buildCreationParams(BoxConstraints constraints) {
Map<String, dynamic> params = {
"width": constraints.maxWidth,
"text": _effectiveController.text,
"maxLines": widget.maxLines,
"placeholder": widget.placeholder ?? "",
"returnKeyType": widget.returnKeyType.toString(),
"text": _effectiveController.text,
"textAlign": widget.textAlign.toString(),
"textCapitalization": widget.textCapitalization.toString(),
"textContentType": widget.textContentType?.toString(),
"keyboardAppearance": widget.keyboardAppearance.toString(),
"keyboardType": widget.keyboardType.toString(),
"textAlign": widget.textAlign.toString(),
"maxLines": widget.maxLines,
"width": constraints.maxWidth,
};

if (widget.style != null && widget.style?.fontSize != null) {
Expand Down

0 comments on commit 5f6924e

Please sign in to comment.