[React Native] Prevent the On-screen Keyboard from Covering up Text Inputs
When you bring up the on screen keyboard in a mobile app, it will cover any text input or buttons on the bottom half of the screen, which can be frustrating for users. There are a few common ways to deal with this in React Native - and this video shows the following solutions:
First, you can use the built in KeyboardAvoidingView
to move components around when the keyboard comes on screen. It has the advantage to being built in to React Native already - but it can be overly complicated to get this approach to work consistently across both iOS and Android.
There is also a third party library called KeyboardAwareScrollView
, which will allow your entire view to scroll, and will keep the currently selected text inputs up and out of the way of the keyboard.
Install:
- npm i -D react-native-keyboard-aware-scroll-view
Use:
- import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
- export default class App extends Component {
- render() {
- return (
- <KeyboardAwareScrollView
- style={{ flex: 1 }}
- >
- <View style={styles.loginHeader}>
- <Text style={styles.headerText}>App Name</Text>
- </View>
- <View style={styles.loginInputs}>
- <Text style={styles.label}>Username</Text>
- <TextInput
- placeholder="Username"
- style={styles.input}
- />
- <Text style={styles.label}>Password</Text>
- <TextInput
- placeholder="Password"
- style={styles.input}
- secureTextEntry={true}
- />
- <TouchableOpacity style={styles.loginButton}>
- <Text style={styles.loginText}>Login</Text>
- </TouchableOpacity>
- </View>
- </KeyboardAwareScrollView>
- );
- }
- }
[React Native] Prevent the On-screen Keyboard from Covering up Text Inputs的更多相关文章
- Apple & iOS & Device Screen Sizes and Orientations & React Native
Apple & iOS & Device Screen Sizes and Orientations & React Native iOS devices https://de ...
- React Native(ios)项目中logo,启动屏设置
由于logo和启动屏尺寸多,react native(ios)中没有命令可以自动生成各种的尺寸,所以可以使用以下办法:在ionic项目中生成(使用命令:ionic resources)后,再粘贴到re ...
- React Native视频播放(iOS)
网站链接:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/learn-react-native-video/ React Nativ ...
- 如何用 React Native 创建一个iOS APP?
诚然,React Native 结合了 Web 应用和 Native 应用的优势,可以使用 JavaScript 来开发 iOS 和 Android 原生应用.在 JavaScript 中用 Reac ...
- React Native 之 项目实战(一)
前言 本文有配套视频,可以酌情观看. 文中内容因各人理解不同,可能会有所偏差,欢迎朋友们联系我. 文中所有内容仅供学习交流之用,不可用于商业用途,如因此引起的相关法律法规责任,与我无关. 如文中内容对 ...
- React Native 系列(八) -- 导航
前言 本系列是基于React Native版本号0.44.3写的.我们都知道,一个App不可能只有一个不变的界面,而是通过多个界面间的跳转来呈现不同的内容.那么这篇文章将介绍RN中的导航. 导航 什么 ...
- React Native 系列(九) -- Tab标签组件
前言 本系列是基于React Native版本号0.44.3写的.很多的App都使用了Tab标签组件,例如QQ,微信等等,就是切换不同的选项,显示不同的内容.那么这篇文章将介绍RN中的Tab标签组件. ...
- React Native填坑之旅 -- 使用react-navigation代替Navigator
Navigator已经被React Native废弃了.也许你可以在另外的一个依赖库里react-native-deprecated-custom-components里找到.不过既然官方推荐的是re ...
- React Native学习(三)—— 使用导航器Navigation跳转页面
本文基于React Native 0.52 参考文档https://reactnavigation.org/docs/navigators/navigation-prop 一.基础 1.三种类型 Ta ...
随机推荐
- hashtable的用法
C#中哈希表(HashTable)的用法详解 1. 哈希表(HashTable)简述 在.NET Framework中,Hashtable是System.Collections命名空间提供的一个容器 ...
- MySQL 8.*版本 修改root密码
MySQL .*版本 修改root密码 查看版本:select version() from dual; 1.6. 登录mysql: 登录mysql:(因为之前没设置密码,所以密码为空,不用输入密码, ...
- Java软件开发中迭代的含义
软件开发中,各个开发阶段不是顺序执行的,而各个阶段都进行迭代并行执行的,然后在进入下一个阶段的开发. 这样对于开发中的需求变化,及人员变动都能得到更好的适应. 软件开发过程汇总迭代模型如下图所示:
- 在网页中引用DWG控件,交互绘图,和响应鼠标点击对象的方法
在网页中引用DWG控件,交互绘图,和响应鼠标点击对象的方法 [MXDRAW CAD控件文档] 下面帮助的完整例子,在控件安装目录的Sample\Ie\iedemo.htm中. 1. 主要用到 ...
- Rest 参数(...)
javascript 之Rest 参数(...) ES6 Rest参数 Rest就是为解决传入的参数数量不一定, rest parameter(Rest 参数) 本身就是数组,数组的相关的方法都可以用 ...
- 洛谷——P4071 [SDOI2016]排列计数(错排+组合数学)
P4071 [SDOI2016]排列计数 求有多少种长度为 n 的序列 A,满足以下条件: 1 ~ n 这 n 个数在序列中各出现了一次 若第 i 个数 A[i] 的值为 i,则称 i 是稳定的.序列 ...
- 「 HDU P2089 」 不要62
和 HDOJ 3555 一样啊,只不过需要多判断个 ‘4’ 我有写 3555 直接去看那篇吧 这里只放代码 #include <iostream> #include <cstring ...
- VS C#报错CS1056意外的字符"(Unexpected Character")
今天重装了下VS2017,再打开之前的项目发现运行不了了,报错如图 解决方法: 找到.NETFramework,Version=v4.5.2.AssemblyAttributes.cs这个文件删除就好 ...
- buf.writeUInt8()函数详解
buf.writeUInt8(value, offset[, noAssert]) value {Number} 需要被写入到 Buffer 的字节 offset {Number} 0 <= o ...
- LINUX-RPM 包 - (Fedora, Redhat及类似系统)
rpm -ivh package.rpm 安装一个rpm包 rpm -ivh --nodeeps package.rpm 安装一个rpm包而忽略依赖关系警告 rpm -U package.rpm 更新 ...