mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
iOS: Fix InputAccessoryView disappearing when inputAccessoryViewID exists
Summary: InputAccessoryView disappears on Fabric (not Paper) when the text prop changes. Changelog: [Fabric] [iOS] Fix InputAccessoryView disappearing when inputAccessoryViewID exists Differential Revision: D27721549 fbshipit-source-id: 163dfcf0a8d5226453f4de356650a6ba82bee10b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
69a48ec9d4
commit
d90253da36
@@ -435,6 +435,14 @@ using namespace facebook::react;
|
||||
|
||||
- (void)setDefaultInputAccessoryView
|
||||
{
|
||||
// InputAccessoryView component sets the inputAccessoryView when inputAccessoryViewID exists
|
||||
if (_backedTextInputView.inputAccessoryViewID) {
|
||||
if (_backedTextInputView.isFirstResponder) {
|
||||
[_backedTextInputView reloadInputViews];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
UIKeyboardType keyboardType = _backedTextInputView.keyboardType;
|
||||
|
||||
// These keyboard types (all are number pads) don't have a "Done" button by default,
|
||||
|
||||
@@ -23,6 +23,7 @@ const {
|
||||
Switch,
|
||||
Alert,
|
||||
} = require('react-native');
|
||||
import type {KeyboardType} from 'react-native/Libraries/Components/TextInput/TextInput';
|
||||
|
||||
const TextInputSharedExamples = require('./TextInputSharedExamples.js');
|
||||
|
||||
@@ -41,7 +42,10 @@ class WithLabel extends React.Component<$FlowFixMeProps> {
|
||||
}
|
||||
}
|
||||
|
||||
class TextInputAccessoryViewExample extends React.Component<{...}, *> {
|
||||
class TextInputAccessoryViewChangeTextExample extends React.Component<
|
||||
{...},
|
||||
*,
|
||||
> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {text: 'Placeholder Text'};
|
||||
@@ -51,6 +55,7 @@ class TextInputAccessoryViewExample extends React.Component<{...}, *> {
|
||||
const inputAccessoryViewID = 'inputAccessoryView1';
|
||||
return (
|
||||
<View>
|
||||
<Text>Set InputAccessoryView with ID & reset text:</Text>
|
||||
<TextInput
|
||||
style={styles.default}
|
||||
inputAccessoryViewID={inputAccessoryViewID}
|
||||
@@ -70,6 +75,69 @@ class TextInputAccessoryViewExample extends React.Component<{...}, *> {
|
||||
}
|
||||
}
|
||||
|
||||
class TextInputAccessoryViewChangeKeyboardExample extends React.Component<
|
||||
{...},
|
||||
*,
|
||||
> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {text: '', keyboardType: 'default'};
|
||||
}
|
||||
|
||||
_switchKeyboard = () => {
|
||||
this.setState({
|
||||
keyboardType:
|
||||
this.state.keyboardType === 'default' ? 'number-pad' : 'default',
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const inputAccessoryViewID = 'inputAccessoryView2';
|
||||
return (
|
||||
<View>
|
||||
<Text>Set InputAccessoryView with ID & switch keyboard:</Text>
|
||||
<TextInput
|
||||
style={styles.default}
|
||||
inputAccessoryViewID={inputAccessoryViewID}
|
||||
onChangeText={text => this.setState({text})}
|
||||
value={this.state.text}
|
||||
keyboardType={this.state.keyboardType}
|
||||
returnKeyType="done"
|
||||
/>
|
||||
<InputAccessoryView nativeID={inputAccessoryViewID}>
|
||||
<View style={{backgroundColor: 'white'}}>
|
||||
<Button onPress={this._switchKeyboard} title="Switch Keyboard" />
|
||||
</View>
|
||||
</InputAccessoryView>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TextInputAccessoryViewDefaultDoneButtonExample extends React.Component<
|
||||
$ReadOnly<{|
|
||||
keyboardType: KeyboardType,
|
||||
|}>,
|
||||
*,
|
||||
> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {text: ''};
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<TextInput
|
||||
style={styles.default}
|
||||
onChangeText={text => this.setState({text})}
|
||||
value={this.state.text}
|
||||
keyboardType={this.props.keyboardType}
|
||||
returnKeyType="done"
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RewriteExampleKana extends React.Component<$FlowFixMeProps, any> {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@@ -268,9 +336,36 @@ exports.examples = ([
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Keyboard Accessory View',
|
||||
title: 'Keyboard Input Accessory View',
|
||||
render: function(): React.Node {
|
||||
return <TextInputAccessoryViewExample />;
|
||||
return (
|
||||
<View>
|
||||
<TextInputAccessoryViewChangeTextExample />
|
||||
<TextInputAccessoryViewChangeKeyboardExample />
|
||||
</View>
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Default Input Accessory View with returnKeyType = 'done'",
|
||||
render: function(): React.Node {
|
||||
const keyboardTypesWithDoneButton = [
|
||||
'number-pad',
|
||||
'phone-pad',
|
||||
'decimal-pad',
|
||||
'ascii-capable-number-pad',
|
||||
];
|
||||
const examples = keyboardTypesWithDoneButton.map(type => {
|
||||
return (
|
||||
<WithLabel key={'keyboardType: ' + type} label={type}>
|
||||
<TextInputAccessoryViewDefaultDoneButtonExample
|
||||
key={type}
|
||||
keyboardType={type}
|
||||
/>
|
||||
</WithLabel>
|
||||
);
|
||||
});
|
||||
return <View>{examples}</View>;
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user