React native开发iOS与Android兼容适配常见问题

页面样式

1.border引发的样式差异

php 复制代码
 <TouchableOpacity style={styles.saveButton}>
    <Text onPress={handleSave} style={styles.saveButtonText}>
        {strings('saveBtn')}
    </Text>
 </TouchableOpacity>
 const styles = StyleSheet.create({
    saveButtonText: {
        fontSize: 16,
        color: AppColors.white_100,
        paddingHorizontal: 40,
        paddingVertical: 7,
        backgroundColor: AppColors.blue_btn,
        borderRadius: 18,
        overflow: 'hidden',//这是关键代码,没有这个属性的设置在iOS的展示中按钮不会展示圆角
    }
});

2.FlatList引发的样式差异

ini 复制代码
<FlatList
   ....
    removeClippedSubviews={false}//这是关键代码,没有这个属性的设置在iOS的展示中列表需要下拉下才会展示数据
    ...
/>

3.使用弹性布局或者百分比适配小屏手机中的UI展示

事件行为

1.input的处理

javascript 复制代码
import {  KeyboardAvoidingView } from 'react-native';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
....
 return Platform.OS === 'ios' ? (
            <KeyboardAvoidingView behavior={Platform.OS === 'ios' ? 'padding' : 'height'}>
            //你的input
            </KeyboardAvoidingView>
        ) : (
            <View>
                <KeyboardAwareScrollView keyboardShouldPersistTaps={'handled'}>
                   //你的input
                </KeyboardAwareScrollView>
            </View>
        );

如果不使用以上的包裹使用的Input使用时部分机型会有键盘遮盖input框的问题出现

相关推荐
小牛itbull1 小时前
【译】为什么我使用 React 重构了 WordPress?
前端·react.js·重构
用户298698530141 小时前
在 React 中拆分 Excel 文件:从工作表到行列的实践
javascript·react.js·excel
名字还没想好☜2 小时前
React 受控与非受控组件:表单场景怎么选
前端·javascript·react.js·react·表单·受控组件
YFF菲菲兔1 天前
React 事件系统:addTrappedEventListener
react.js
小妖6661 天前
React input 输入卡顿问题
前端·javascript·react.js
小二·2 天前
React 19 + Next.js 15 现代前端开发实战:App Router / Server Components / 流式渲染
前端·javascript·react.js
YFF菲菲兔2 天前
React 事件系统:listenToAllSupportedEvents
react.js
光影少年2 天前
RN 渲染原理:不依赖WebView,原生控件渲染
前端·react native·react.js·前端框架
LaughingZhu3 天前
智能体经典范式构建:ReAct、Plan-and-Solve 与 Reflection
前端·react.js·前端框架