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框的问题出现

相关推荐
Highcharts.js9 小时前
Highcharts 集成到 React 或 Vue 项目中时,如何高效地使用 TypeScript技巧?
vue.js·人工智能·react.js·typescript·前端框架·highcharts
hhhjhl1 天前
React Native 三方库「react-native-sha256」的鸿蒙化适配指南
react native·华为·harmonyos
2601_949970691 天前
React Native 三方库「react-native-version-check」的鸿蒙化适配指南
react native·华为·harmonyos
hhhjhl1 天前
React Native 三方库「react-native-proximity」的鸿蒙化适配指南
react native·华为·harmonyos
2601_949970691 天前
React Native 三方库「react-native-media-notification」的鸿蒙化适配指南
react native·华为·harmonyos
liuchangng1 天前
React 19 + Vite 6 实战:从教材 PDF 到 866 词间隔重复单词 App
前端·react.js·pdf·vite·开源项目
GitCode官方1 天前
从大语言模型到具身智能:百度百舸 LoongForge 入驻 AtomGit
人工智能·react native·百度·harmonyos·atomgit
鸿蒙开发2 天前
Three.js 首帧卡顿排查:compileAsync 之后,为什么还会停一下?
react.js·three.js
小李科技2 天前
【性能优化】事件委托:目标定位与 React/Vue 实战
前端·vue.js·react.js·面试·性能优化·前端框架
csj502 天前
前端基础之《React(16)—Modal组件封装》
前端·react.js