2

I'm using the <InputText> of react-native-paper for my app. And i'm using the autofocus property everytime I switch from a view to another, so i can type directly when I arrive on the screen.

But the problem is the keyboard appears randomly ... Sometimes the keyboard comes alone and sometimes I have to tap in the input to reveal the keyboard...

This is an example of the Input I use everywhere :

<TextInput
                    label="Article"
                    value={this.state.article}
                    onChangeText={article => this.setState({article})}
                    onSubmitEditing={this.submitStepSaisie1}
                    autoFocus
                    style={{backgroundColor: 'transparent'}}
                />

I tried using ref like this, in my constructor :

constructor(props) {

    super(props);
    this.fieldOne = React.createRef();
    this.fieldTwo = React.createRef();
}

And on my TextInput :

<TextInput ref={this.fieldOne} />

But when I call the this.fieldOne.current.focus() it returnes me the following error : Cannot read property 'focus' of null.

Do you guys have a trick ? Thanks !

Thibault Dumas
  • 1,060
  • 2
  • 10
  • 21

1 Answers1

0
import { TextInput as NativeTextInput } from 'react-native';

<TextInput
  label="Article"
  value={this.state.article}
  onChangeText={article => this.setState({article})}
  onSubmitEditing={this.submitStepSaisie1}
  autoFocus
  style={{backgroundColor: 'transparent'}}
  render={(props) => <NativeTextInput {...props} ref={this.fieldOne}>}
/>

I dont have the time to test this but this might work.

elvis_ferns
  • 524
  • 6
  • 14