react-native - react native app在ios和android中有不同的风格
问题描述
相同的代码导致ios和android的风格不同。android 版本应该是它的样子,但在 ios 中看起来完全一样。
这个应用程序已经开发,但从未在 ios 上运行,可能他们不需要。但现在它也应该为 ios 发布。如何以最少的重构量获得相同的结果?
全名的输入域代码;
<View style={inputFieldContainerStyle}>
<Icon source={usernameIcon} />
<TextInput
style={[inputFieldStyle, textInputTextStyle]}
onChangeText={(text) => this.setState({name: text})}
accessibilityLabel="name"
editable={true}
value={this.state.name}
placeholder={'First and last name'}
placeholderTextColor="grey"
autoCorrect={false}
label="field1"
ref={(input) => {
this.inputs.field1 = input;
}}
returnKeyType={'next'}
onSubmitEditing={() => {
this.focusTheField('field2');
}}
textContentType="name"
/>
</View>
inputFieldContainerStyle: {
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
marginBottom: 15,
height: 40,
},
inputFieldStyle: {
backgroundColor: 'white',
flex: 1,
paddingLeft: 10,
paddingRight: 10,
},
textInputTextStyle:{
color: 'black',
fontSize: 16,
fontFamily: 'HelveticaNeue',
}
// THE Icon COMPONENT
<View style={[containerStyle, secondaryContainerStyle && secondaryContainerStyle]}>
<Image source={source} style={[iconStyle, secondaryIconStyle && secondaryIconStyle]} />
</View>
解决方案
您可以像这样放置一些条件样式:
textInputTextStyle:{
color: 'black',
fontSize: 16,
fontFamily: 'HelveticaNeue',
padding: Platform.os === 'ios'? 10: null
}
我不确定填充,但这只是给出一个取决于平台的样式示例。
推荐阅读
- c# - SignalR Hubs 通过依赖注入
- docker - Docker 中 Corda Settler 的错误:无法反序列化事务中索引 0 处的组 OUTPUTS_GROUP
- html - 当光标悬停在按钮上时,我想更改 Pardot 中的提交颜色
- python - Python Turtle 滚动条
- google-cloud-platform - GCP:用于环境变量格式问题的 Cloud Function app.yaml 文件
- reactjs - React、Redux 和 Firestore 可变可用性
- python - 通过从 assets 文件夹中读取图像并传递给 tensorflow 对象检测 android 来静态提供图像
- javascript - 如何通过 javascript ajax 解决“youtube 链接 cors 问题”?
- sql-server - 我的查询有 2 秒的执行时间,但我想要 0 秒的执行时间
- java - 来自视图适配器的无条件布局膨胀:应该使用 View Holder 模式 - 使应用程序崩溃