我想在 IOS上使用没有任何功能的KeyboardAwareScrollView,并给出下面的 android代码. I know that I need to use Platform.OS === ‘ios’ ? : BUT I DON’T UNDERSTAND HOW TO REALISE IT. Please help me render(){ return( Keyboa
I know that I need to use Platform.OS === ‘ios’ ? :
BUT I DON’T UNDERSTAND HOW TO REALISE IT. Please help me
render(){ return( <KeyboardAwareScrollView extraScrollHeight={100} enableOnAndroid={true} keyboardShouldPersistTaps='handled' > <TextInput style={styles.inputContainerStyle} label="Username" value={this.state.username} onChangeText={username => this.setState({ username })} /> </KeyboardAwareScrollView> ) }
What I’ve tried below: (But it doesn’t work)
<KeyboardAwareScrollView Platform.OS === 'android' ? ( extraScrollHeight={100} enableOnAndroid={true} keyboardShouldPersistTaps='handled' ) : null >您可以同时使用JSX prop spread和三元表达式:
<KeyboardAwareScrollView { ...(Platform.OS === 'android' ? { extraScrollHeight={100} enableOnAndroid={true} keyboardShouldPersistTaps='handled' } : {}) } >
我强烈建议不要这样做所有内联,因为它很难阅读.你可以使用Platform.select做一些有点可读(和声明)的事情:
const keyboardProps = Platform.select({ android: { … }, ios: {}, }); … <KeyboardAwareScrollView {...keyboardProps}>