【问题标题】:React Native Can't focus in TextInputReact Native 无法在 TextInput 中聚焦
【发布时间】:2017-08-07 18:15:42
【问题描述】:
class Main extends Component {
    constructor(props) {
        super(props)
        this.state = {
            id: '',
            password: '',
        }
        console.log('yes')
        this._handleTextChange = this._handleTextChange.bind(this)
    }

    _handleTextChange(id, text) {
        console.log(text)
        var newState = Object.assign({}, this.state);
        var newState = Object.assign({}, this.state);
        newState[id] = text
        this.setState(newState)
    }

    render() {
        console.log('ass')
        return (
            <View style={MainStyle.justFlexOne}>
                <View style={MainStyle.coverImageWrapper}>
                    <Image source={require('../assets/images/cursive.jpg')} style={MainStyle.coverImage}/>
                </View>
                <View style={MainStyle.mainBackground}>
                    <TouchableHighlight>
                        <Text style={MainStyle.bigFontDefault}>
                            Comma
                        </Text>
                    </TouchableHighlight>
                    <TextInput
                        style={MainStyle.TextInputs}
                        value={this.state.id}
                        editable={true}
                        onChangeText={(text) => {console.log('asdf');this.setState({id:text})}}
                        placeholder='text'
                    />
                </View>
            </View>
        )

    }
}

const MainStyle = StyleSheet.create({
    justFlexOne: {
        flex: 1,
    },
    mainBackground: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: 'transparent',
    },
    bigFontDefault: {
        color: '#fafafa',
        fontSize: 60,
        textShadowOffset: {width: 0, height: 1},
        textShadowRadius: 8,
        textShadowColor: 'rgba(21,42,55,0.4)',
        fontFamily: 'Optima-Italic',
        fontWeight: '500',

    },
    coverImageWrapper: {
        position: 'absolute',
        top: 0, left: 0, bottom: 0, right: 0,
    },
    coverImage: {
        flex: 1,
        width: null,
        height: null,
        resizeMode: 'cover',
    },
    textInputs: {
        height: 40,
        width: 200,
        color: '#fcc439',
        backgroundColor: 'rgba(0,0,0,0.4)',
        borderColor: '#fcc439',
    }
})

问题是,我无法在 XCode(版本 8.2.1)操作的 iOS Simulator 上专注于 TextInput。(这意味着我无法在输入中输入某些字符。)我已经完成了我可以使用 mac 键盘、触控板甚至苹果鼠标来处理(如单击、输入等)。尽管连接硬件键盘已打开。

StyleSheet 也不能​​在 TextInput 上工作。(它在其他组件上也能正常工作。)

我该如何解决这个问题??

【问题讨论】:

    标签: react-native ios-simulator


    【解决方案1】:

    改变

    style={MainStyle.TextInputs}
    

    style={MainStyle.textInputs}
    

    【讨论】:

    • 谢谢,请原谅我的粗心。
    • 여기서 한국인을 다 만나네요。 ㅎㅎ 감사합니다 :)
    • 这解决了焦点问题吗?我遇到了同样的问题,但我认为这与样式无关。
    • 原来输入根本没有显示,我没有给它一个高度。在 Android 上没有固定高度也可以正常工作。
    猜你喜欢
    • 2022-07-06
    • 2020-06-06
    • 2017-07-11
    • 1970-01-01
    • 2019-04-12
    • 2021-11-01
    • 2016-03-09
    • 2020-09-05
    • 2020-10-04
    相关资源
    最近更新 更多