输入失去对开始输入主题的关注

Nik*_*hal 6 react-native react-native-android react-native-ios

我正在尝试开发一个react-native应用程序,以设计一个自定义主题组件,并使用将该屏幕包含在主题中this.props.child。问题是屏幕上的输入字段失去焦点,并且在键入每个字符后键盘都被关闭,因为onChange我正在更新状态变量,这可能会重新呈现整个主题。

我已经尝试过在Github上提供许多解决方案,例如将唯一键传递给输入字段,但是它们不起作用。

这是我的主题组件的样子:

import Header from './header'
import footer from './footer'

export default class Theme extends Component {

    render() {
        //------this is my header component----
        <Header/>
        <View>
        //------this is my Body  in which i include my sceen content----
        {this.props.children}
        </View>

         //------this is my footer component----
        <footer/>
    }
}
Run Code Online (Sandbox Code Playgroud)

这是带有输入字段的屏幕:

import Theme from "../../components/Theme";
import { Input, Button } from "react-native-elements";

export default  class ChangePassword extends Component {

    constructor(props) {

    super(props);
    this.state = {

        inputs:{
            old_password : {value:null, errorMesssage:""}

        }
    }
}


 setValues = async (key, value) => {

    let { inputs } = this.state;

      inputs[key]["value"] = value;
      inputs[key]["errorMessage"] = "";


      await this.setState({ inputs });


  }

    render(){

    let {inputs}=this.state;
    return(
            <Theme>

            <Input
                    key="Current_password"
                    ref="Current_password"
                    containerStyle={styles.containerStyle}
                    inputContainerStyle={styles.inputContainer}
                    label="Current password"
                    value={inputs.old_password.value}
                    errorMessage={inputs.old_password.errorMessage}
                    errorStyle={styles.inputErrorStyle}
                    secureTextEntry={true}
                    autoFocus={true}
                    onChangeText={(val) => {
                    this.setValues("old_password", val);
                    }}

                />


            </Theme>
    )

    }

}
Run Code Online (Sandbox Code Playgroud)

请帮助我解决问题,我想onChangeText在不关闭键盘的情况下更新状态变量。

小智 0

生命周期钩子 - shouldComponentUpdate 怎么样,您可以在其中决定组件何时应该重新渲染?