Only blur input when index changes on transition start (Fixes #4148)

This commit is contained in:
Brent Vatne 2018-05-07 11:47:56 -07:00
parent 39d5714ac0
commit 6499f02157
2 changed files with 13 additions and 6 deletions

View File

@ -24,9 +24,9 @@ class ScreenOne extends React.Component {
}
class ScreenTwo extends React.Component {
static navigationOptions = {
title: 'Screen w/ Input',
};
static navigationOptions = ({ navigation }) => ({
title: navigation.getParam('inputValue', 'Screen w/ Input'),
});
componentDidMount() {
InteractionManager.runAfterInteractions(() => {
@ -41,6 +41,7 @@ class ScreenTwo extends React.Component {
<View style={{ alignSelf: 'center', paddingVertical: 20 }}>
<TextInput
ref={c => (this._textInput = c)}
onChangeText={inputValue => navigation.setParams({ inputValue })}
style={{
backgroundColor: 'white',
height: 24,

View File

@ -39,10 +39,16 @@ export default Navigator =>
};
_handleTransitionStart = (transitionProps, prevTransitionProps) => {
const currentField = TextInput.State.currentlyFocusedField();
if (currentField) {
TextInput.State.blurTextInput(currentField);
// TODO: We should not even have received the transition start event
// in the case where the index did not change, I believe. We
// should revisit this after 2.0 release.
if (transitionProps.index !== prevTransitionProps.index) {
const currentField = TextInput.State.currentlyFocusedField();
if (currentField) {
TextInput.State.blurTextInput(currentField);
}
}
this.props.onTransitionStart &&
this.props.onTransitionStart(transitionProps, prevTransitionProps);
};