Skip to content

Commit d54113d

Browse files
gurs1khfacebook-github-bot
authored andcommitted
implemented showSoftInputOnFocus for iOS (#28834)
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
1 parent 797367c commit d54113d

File tree

10 files changed

+37
-3
lines changed

10 files changed

+37
-3
lines changed

Libraries/Components/TextInput/AndroidTextInputNativeComponent.js

-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ export type NativeProps = $ReadOnly<{|
183183
/**
184184
* When `false`, it will prevent the soft keyboard from showing when the field is focused.
185185
* Defaults to `true`.
186-
* @platform android
187186
*/
188187
showSoftInputOnFocus?: ?boolean,
189188

Libraries/Components/TextInput/TextInput.js

-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ type AndroidProps = $ReadOnly<{|
408408
/**
409409
* When `false`, it will prevent the soft keyboard from showing when the field is focused.
410410
* Defaults to `true`.
411-
* @platform android
412411
*/
413412
showSoftInputOnFocus?: ?boolean,
414413
|}>;

Libraries/DeprecatedPropTypes/DeprecatedTextInputPropTypes.js

-1
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,6 @@ module.exports = {
616616
/**
617617
* When `false`, it will prevent the soft keyboard from showing when the field is focused.
618618
* Defaults to `true`.
619-
* @platform android
620619
*/
621620
showSoftInputOnFocus: PropTypes.bool,
622621
};

Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
2020
@property (nonatomic, assign, readonly) BOOL textWasPasted;
2121
@property (nonatomic, assign) UIEdgeInsets textContainerInset;
2222
@property (nonatomic, strong, nullable) UIView *inputAccessoryView;
23+
@property (nonatomic, strong, nullable) UIView *inputView;
2324
@property (nonatomic, weak, nullable) id<RCTBackedTextInputDelegate> textInputDelegate;
2425
@property (nonatomic, readonly) CGSize contentSize;
2526
@property (nonatomic, strong, nullable) NSDictionary<NSAttributedStringKey,id> *defaultTextAttributes;

Libraries/Text/TextInput/RCTBaseTextInputView.h

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ NS_ASSUME_NONNULL_BEGIN
5151
@property (nonatomic, copy, nullable) NSAttributedString *attributedText;
5252
@property (nonatomic, copy) NSString *inputAccessoryViewID;
5353
@property (nonatomic, assign) UIKeyboardType keyboardType;
54+
@property (nonatomic, assign) BOOL showSoftInputOnFocus;
5455

5556
/**
5657
Sets selection intext input if both start and end are within range of the text input.

Libraries/Text/TextInput/RCTBaseTextInputView.m

+11
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,17 @@ - (void)setKeyboardType:(UIKeyboardType)keyboardType
302302
}
303303
}
304304

305+
- (void)setShowSoftInputOnFocus:(BOOL)showSoftInputOnFocus
306+
{
307+
if (showSoftInputOnFocus) {
308+
// Resets to default keyboard.
309+
self.backedTextInputView.inputView = nil;
310+
} else {
311+
// Hides keyboard, but keeps blinking cursor.
312+
self.backedTextInputView.inputView = [[UIView alloc] init];
313+
}
314+
}
315+
305316
#pragma mark - RCTBackedTextInputDelegate
306317

307318
- (BOOL)textInputShouldBeginEditing

Libraries/Text/TextInput/RCTBaseTextInputViewManager.m

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ @implementation RCTBaseTextInputViewManager
5252
RCT_EXPORT_VIEW_PROPERTY(blurOnSubmit, BOOL)
5353
RCT_EXPORT_VIEW_PROPERTY(clearTextOnFocus, BOOL)
5454
RCT_EXPORT_VIEW_PROPERTY(keyboardType, UIKeyboardType)
55+
RCT_EXPORT_VIEW_PROPERTY(showSoftInputOnFocus, BOOL)
5556
RCT_EXPORT_VIEW_PROPERTY(maxLength, NSNumber)
5657
RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL)
5758
RCT_EXPORT_VIEW_PROPERTY(selection, RCTTextSelection)

RNTester/js/examples/TextInput/TextInputExample.ios.js

+12
Original file line numberDiff line numberDiff line change
@@ -707,4 +707,16 @@ exports.examples = ([
707707
);
708708
},
709709
},
710+
{
711+
title: 'showSoftInputOnFocus',
712+
render: function(): React.Node {
713+
return (
714+
<View>
715+
<WithLabel label="showSoftInputOnFocus: false">
716+
<TextInput showSoftInputOnFocus={false} style={[styles.default]} />
717+
</WithLabel>
718+
</View>
719+
);
720+
},
721+
},
710722
]: Array<RNTesterExampleModuleItem>);

ReactCommon/fabric/components/textinput/iostextinput/primitives.h

+6
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ class TextInputTraits final {
180180
*/
181181
KeyboardType keyboardType{KeyboardType::Default};
182182

183+
/*
184+
* iOS & Android
185+
* Default value: `true`.
186+
*/
187+
bool showSoftInputOnFocus{true};
188+
183189
/*
184190
* Some values iOS- or Android-only (inherently particular-OS-specific)
185191
* Default value: `Default`.

ReactCommon/fabric/components/textinput/iostextinput/propsConversions.h

+5
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ static TextInputTraits convertRawProp(
8888
"keyboardType",
8989
sourceTraits.keyboardType,
9090
defaultTraits.keyboardType);
91+
traits.showSoftInputOnFocus = convertRawProp(
92+
rawProps,
93+
"showSoftInputOnFocus",
94+
sourceTraits.showSoftInputOnFocus,
95+
defaultTraits.showSoftInputOnFocus);
9196
traits.returnKeyType = convertRawProp(
9297
rawProps,
9398
"returnKeyType",

0 commit comments

Comments
 (0)