Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native React native TextInput isFocused方法_React Native - Fatal编程技术网

React native React native TextInput isFocused方法

React native React native TextInput isFocused方法,react-native,React Native,我想动态更改背景图像。我试图知道TextInput是否以这种方式聚焦。我还尝试了this.text.current.isFocused()。但这对我没有帮助。有人知道吗 text={}; renderDrawerContent(){ let image = this.text.isFocused() ? require('../assets/images/gyzyl.png') : require('../assets/images/BlackBack.jpg');

我想动态更改背景图像。我试图知道TextInput是否以这种方式聚焦。我还尝试了
this.text.current.isFocused()
。但这对我没有帮助。有人知道吗

text={};


renderDrawerContent(){
  let  image = this.text.isFocused() ?  require('../assets/images/gyzyl.png') : require('../assets/images/BlackBack.jpg');
        return(
            <Container style={styles.containerDrawer}>
               <ImageBackground
                source={image}
                style={{flex:1}}
                resizeMode={'cover'}
                 >

                   <Content style={{ paddingTop: 0, }}>
                       <View style={{paddingTop: 20}}>
                           <View style={{flexDirection:'column' , marginVertical:5 ,padding:15}}>
                               <Text style={styles.search}>Search</Text>
                               <TextInput ref={ref => this.text=ref} autotFocus={this.state.Focused} underlineColorAndroid={'white'} placeholder='Cinema, Theatre, Concert ...' placeholderTextColor = '#fff' style={{color: '#fff', fontSize: 16 ,flex:1 , borderBottomColor: '#fff'}} />
                           </View>
                       </View>

                   </Content>


                </ImageBackground>
            </Container>

        );
}


text={};
renderDrawerContent(){
让image=this.text.isFocused()?require('../assets/images/gyzyl.png'):require('../assets/images/BlackBack.jpg');
返回(
搜寻
this.text=ref}autotofocus={this.state.Focused}underlineColorAndroid={'white'}占位符='电影院、剧院、音乐会……'占位符textcolor=''#fff'风格={{{color:'#fff',fontSize 16,flex:1,borderBottomColor:'#fff'}/>
);
}

您可以使用textinput中的onFocus事件与onBlur一起执行此操作。 使用此方法,您应该向状态对象添加一个值,用于跟踪输入是否聚焦

<TextInput onFocus={()=> this.setState({inputFocused: true})} onBlur={()=> this.setState({inputFocused: false})}/>
this.setState({inputFocused:true})onBlur={()=>this.setState({inputFocused:false})}/>
然后使用inputFocused检查输入是否聚焦