我正在使用 KeyboardAvoidingView,如果平台是 IOS,我想将一个 Prop “行为”传递给它,如果是 android,则没有。我不想为此编写两个单独的 JSX 组件声明。有没有办法决定是否通过 Prop 。此外,react-native 的文档没有提及我本可以有条件地设置的行为 Prop 的任何默认值。
Based on the platform the component should be declared the following way
FOR IOS
<KeyboardAvoidingView behavior="padding" style={modalContainer} >
{this.props.children} //I've lots of children here and they're composed inside of the keyboardavoidingview and i'm not using this.props.children as they're in the same parent component
</KeyBoardAvoidingView>
FOR ANDROID
<KeyboardAvoidingView style={modalContainer} >
{this.props.children}
</KeyBoardAvoidingView>
最佳答案
您可以通过传递 value
或 undefined
<KeyboardAvoidingView behavior={platform="android"? "padding": undefined} style={modalContainer} >
{this.props.children}
</KeyBoardAvoidingView>
关于javascript - 如何动态决定是否将 Prop 传递给 react 组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48822490/