[React Native] Dismiss the Keyboard in React Native
In this lesson you will learn how create a re-usable component that gives the user the ability to dismiss the keyboard whenever they tap outside of a TextInput. To accomplish this we'll take a look at the TouchableWithoutFeedback
component and the Keyboard
API.
The whole idea for dismiss keyboard is calling:
Keyboard.dismiss()
So build a High-Order-component, which wraps the actually inputs element, when click happens outside the inputs, close the keyboard.
import React from 'react';
import { View, TextInput, StyleSheet, Keyboard, TouchableWithoutFeedback } from 'react-native'; const DismissKeyboard = ({ children }) => (
<TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
{children}
</TouchableWithoutFeedback>
); const App = () => (
<DismissKeyboard>
<View style={styles.container}>
<TextInput
style={styles.input}
placeholder="email"
keyboardType="numeric"
/>
<TextInput
style={styles.input}
placeholder="password"
/>
</View>
</DismissKeyboard>
); const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#2374AB',
},
input: {
width: '80%',
paddingVertical: 10,
paddingHorizontal: 5,
borderRadius: 3,
backgroundColor: '#ffffff70',
marginVertical: 5,
},
}); export default App;
[React Native] Dismiss the Keyboard in React Native的更多相关文章
- React Native是一套使用 React 构建 Native app 的编程框架
React Native是一套使用 React 构建 Native app 的编程框架 React Native at first sight what is React Native? 跟据官方的描 ...
- React学习笔记-1-什么是react,react环境搭建以及第一个react实例
什么是react?react的官方网站:https://facebook.github.io/react/下图这个就是就是react的标志,非常巧合的是他和我们的github的编辑器Atom非常相似. ...
- weblogic.nodemanager.common.ConfigException: Native version is enabled but nodemanager native library could not be loaded 解决办法
近日在一个原本工作正常的weblogic web server(操作系统为redhat 64位系统)上折腾安装redis/hadoop等东东,yum install了一堆第3方类库后,重启weblog ...
- React系列(一):React入门
React简介 1.由来 React是有Facebook开发出来用于构建前端界面的JS组件库,由于其背后的强大背景,使得这款库在技术开发上完全没有问题. 2.React的优势 解决大规模项目开发中数据 ...
- react.js 从零开始(七)React (虚拟)DOM
React 元素 React 中最主要的类型就是 ReactElement.它有四个属性:type,props,key 和ref.它没有方法,并且原型上什么都没有. 可以通过 React.create ...
- 如何使用TDD和React Testing Library构建健壮的React应用程序
如何使用TDD和React Testing Library构建健壮的React应用程序 当我开始学习React时,我努力的一件事就是以一种既有用又直观的方式来测试我的web应用程序. 每次我想测试它时 ...
- React环境配置(第一个React项目)
使用Webpack构建React项目 1. 使用NPM配置React环境 NPM及React安装自行百度 首先创建一个文件夹,the_first_React 进入到创建好的目录,npm init,然后 ...
- React入门介绍(2)- React Component-React组件
React Component-React组件 允许用户自由封装组件是React非常突出的特性,用户可将自己创建的组件像普通的HTML标签一样插入页面,React.CreateClass方法就是用来创 ...
- react的类型检查PropTypes自React v15.5起已弃用,请使用prop-types
最近使用React的类型检查PropTypes时,遇到错误:TypeError: Cannot read property 'array' of undefined 看了下自己的React版本: ...
随机推荐
- 紫书 例题8-1 UVa 120(构造法)
#include<cstdio> #include<iostream> #include<sstream> #include<algorithm> #d ...
- [WPF] 圆形等待效果
原文:[WPF] 圆形等待效果 自己做着玩儿的,留着以后用,效果类似下面的 GIF 动画. <Grid Width="35" Height="35"> ...
- 异构关系数据库(MySql与Oracle)之间的数据类型转换参考
一.MySQL到Oracle的数据类型的转变: 编号 MySQL ToOracle Oracle 1 GEOMETRY BLOB BLOB 2 GEOMETRYCOLLECTION BLOB BLOB ...
- oracle 表空间Tablespaces
1.表空间 一个数据库可以有多个表空间,一个表空间里可以有多个表.表空间就是存多个表的物理空间: 可以指定表空间的大小位置等. 创建表空间:create tablespace ts1 datafile ...
- servlet调用的几种方式
參见 文库/java/javaEE全新学习教程2.2节 1.通过URL调用 2通过提交表单 3超链接 4 javascript写一个函数,调用这个函数 1,首先在project的WebRoot目录下建 ...
- CF 567C(Geometric Progression-map)
C. Geometric Progression time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 51nod-1346: 递归
[传送门:51nod-1346] 简要题意: 给出一个式子a[i][j]=a[i-1][j]^a[i][j-1] 给出a[1][i],a[i][1](2<=i<=131172) 有n个询问 ...
- iOS对象方法和类方法的区别与调用方式
作为一个iOS程序员初学者,会搞不清楚对象方法和类方法的区别 -(void)duixiangfangfa ; +(void)leifangfa; - 代表实例方法,它在类的一个具体实例范围内执行,也就 ...
- 一题多解(一) —— list(Python)判空(以及 is 与 == 的区别)
>> l = [] 1. == >> l == [] True 2. not >> not l True 3. 注意 is 与 == 的区别 >> l ...
- Redis-1-安装
Redis-1-安装 标签(空格分隔): linux,redis 下载 cd /usr/local/src/ wget http://download.redis.io/releases/redis- ...