Skip to content

Commit

Permalink
implemented showSoftInputOnFocus for iOS (#28834)
Browse files Browse the repository at this point in the history
Summary:
`showSoftInputOnFocus` was added in #25028, but it was only added for Android. There was a lot of discussion on the original issue being addressed (#14045), that there is a need for this on iOS as well. The issue with iOS was brought up again on #27243.

On a related note, when searching this repo's issues for `showSoftInputOnFocus`, it appears that there are several closed issues that claim that the Android implementation doesn't work (#25685, #25687, #26643). So perhaps the Android implementation needs to be looked at as well (I myself have not gotten around to confirming whether it works or not)

## Changelog

[iOS] [Added] - Add showSoftInputOnFocus to TextInput
Pull Request resolved: #28834

Test Plan:
You'd use this just like you would in the Android implementation:
```jsx
<TextInput showSoftInputOnFocus={false} />
```

## GIFs
### Before change
![May-04-2020 20-52-49](https://user-images.githubusercontent.com/4932784/81034028-9d89cf80-8e4a-11ea-906c-64f62504f80c.gif)

### After change
![May-04-2020 20-54-27](https://user-images.githubusercontent.com/4932784/81034035-a11d5680-8e4a-11ea-918e-119a1c9e2a19.gif)

Differential Revision: D21418763

Pulled By: shergin

fbshipit-source-id: 561e72fc2cf16b30446132f6b96b8aa2b4a92daf
  • Loading branch information
gurs1kh authored and facebook-github-bot committed May 11, 2020
1 parent 797367c commit d54113d
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ export type NativeProps = $ReadOnly<{|
/**
* When `false`, it will prevent the soft keyboard from showing when the field is focused.
* Defaults to `true`.
* @platform android
*/
showSoftInputOnFocus?: ?boolean,

Expand Down
1 change: 0 additions & 1 deletion Libraries/Components/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ type AndroidProps = $ReadOnly<{|
/**
* When `false`, it will prevent the soft keyboard from showing when the field is focused.
* Defaults to `true`.
* @platform android
*/
showSoftInputOnFocus?: ?boolean,
|}>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,6 @@ module.exports = {
/**
* When `false`, it will prevent the soft keyboard from showing when the field is focused.
* Defaults to `true`.
* @platform android
*/
showSoftInputOnFocus: PropTypes.bool,
};
1 change: 1 addition & 0 deletions Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign, readonly) BOOL textWasPasted;
@property (nonatomic, assign) UIEdgeInsets textContainerInset;
@property (nonatomic, strong, nullable) UIView *inputAccessoryView;
@property (nonatomic, strong, nullable) UIView *inputView;
@property (nonatomic, weak, nullable) id<RCTBackedTextInputDelegate> textInputDelegate;
@property (nonatomic, readonly) CGSize contentSize;
@property (nonatomic, strong, nullable) NSDictionary<NSAttributedStringKey,id> *defaultTextAttributes;
Expand Down
1 change: 1 addition & 0 deletions Libraries/Text/TextInput/RCTBaseTextInputView.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy, nullable) NSAttributedString *attributedText;
@property (nonatomic, copy) NSString *inputAccessoryViewID;
@property (nonatomic, assign) UIKeyboardType keyboardType;
@property (nonatomic, assign) BOOL showSoftInputOnFocus;

/**
Sets selection intext input if both start and end are within range of the text input.
Expand Down
11 changes: 11 additions & 0 deletions Libraries/Text/TextInput/RCTBaseTextInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,17 @@ - (void)setKeyboardType:(UIKeyboardType)keyboardType
}
}

- (void)setShowSoftInputOnFocus:(BOOL)showSoftInputOnFocus
{
if (showSoftInputOnFocus) {
// Resets to default keyboard.
self.backedTextInputView.inputView = nil;
} else {
// Hides keyboard, but keeps blinking cursor.
self.backedTextInputView.inputView = [[UIView alloc] init];
}
}

#pragma mark - RCTBackedTextInputDelegate

- (BOOL)textInputShouldBeginEditing
Expand Down
1 change: 1 addition & 0 deletions Libraries/Text/TextInput/RCTBaseTextInputViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ @implementation RCTBaseTextInputViewManager
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
RCT_EXPORT_VIEW_PROPERTY(keyboardType, UIKeyboardType)
RCT_EXPORT_VIEW_PROPERTY(showSoftInputOnFocus, BOOL)
RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber)
RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL)
RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection)
Expand Down
12 changes: 12 additions & 0 deletions RNTester/js/examples/TextInput/TextInputExample.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,4 +707,16 @@ exports.examples = ([
);
},
},
{
title: 'showSoftInputOnFocus',
render: function(): React.Node {
return (
<View>
<WithLabel label="showSoftInputOnFocus: false">
<TextInput showSoftInputOnFocus={false} style={[styles.default]} />
</WithLabel>
</View>
);
},
},
]: Array<RNTesterExampleModuleItem>);
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ class TextInputTraits final {
*/
KeyboardType keyboardType{KeyboardType::Default};

/*
* iOS & Android
* Default value: `true`.
*/
bool showSoftInputOnFocus{true};

/*
* Some values iOS- or Android-only (inherently particular-OS-specific)
* Default value: `Default`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ static TextInputTraits convertRawProp(
"keyboardType",
sourceTraits.keyboardType,
defaultTraits.keyboardType);
traits.showSoftInputOnFocus = convertRawProp(
rawProps,
"showSoftInputOnFocus",
sourceTraits.showSoftInputOnFocus,
defaultTraits.showSoftInputOnFocus);
traits.returnKeyType = convertRawProp(
rawProps,
"returnKeyType",
Expand Down

0 comments on commit d54113d

Please sign in to comment.