当前位置: 首页 > news >正文

React Native键盘的两种适配方案

方案一:

import {KeyboardAvoidingView} from 'react-native';
import {useHeaderHeight} from '@react-navigation/elements';const headerHeight = useHeaderHeight();<KeyboardAvoidingViewbehavior={'padding'}keyboardVerticalOffset={headerHeight}style={styles.container}> 
{children}
</KeyboardAvoidingView>

headerHeight为导航栏高度,导航栏依赖:@react-navigation/native

方案二:


import {SafeAreaView} from 'react-native-safe-area-context';<SafeAreaViewmode="padding"edges={{top: 'off', bottom: 'additive'}}style={{backgroundColor: white}}>
{children}</SafeAreaView>

前置依赖:react-native-safe-area-context

off:关闭安全区适配

additive:增加安全区适配

总结:

方案一:采用的是避让逻辑,通过KeyboardAvoidingView组件将视图上移;

方案二:采用的是占位逻辑,通过获取Keyboard高度,在显示Keyboard时,在视图底部填充等高空白视图。


http://www.mrgr.cn/news/14939.html

相关文章:

  • Qt详解QTcpSocket TCP客户端
  • 【LeetCode】搜索旋转排序数组[python]
  • 微信小程序uni :class不支持xxx语法
  • 机器学习/数据分析--通俗语言带你入门随机森林,并用随机森林进行天气分类预测(Accuracy为0.92)
  • Electron 项目实战 03: 实现一个截图功能
  • 【DSP+FPGA】基于2 个TMS320C6678+ XC7VX690T FPGA 的6U VPX 总线架构的高性能实时信号处理平台
  • C++学习/复习补充记录 --- 图论(深搜,广搜)
  • JVM性能监控实用工具jconsole与jvisualvm
  • okhttp异步请求连接阻塞问题排查
  • Microsoft 将在 CrowdStrike 服务中断后举办 Windows 安全峰会
  • 2024前端面试题分享
  • python 实现一个简单的网页爬虫程序
  • 基于 XILINX FPGA 的 Cameralink Full 模式相机采集系统技术实施方案研究报告
  • Mybatis部分笔记二——Spring:
  • elasticsearch存入数据嵌入式数据解决扁平化查询问题
  • 告别繁琐,拥抱简单!用户好评如潮的录屏软件
  • app抓包环境的搭建详细教程
  • chapter09-项目——(房屋出租系统)——day11
  • vue打印数据
  • 深入理解DPO(Direct Preference Optimization)算法