zoukankan      html  css  js  c++  java
  • [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: {
         '80%',
        paddingVertical: 10,
        paddingHorizontal: 5,
        borderRadius: 3,
        backgroundColor: '#ffffff70',
        marginVertical: 5,
      },
    });
    
    export default App;
  • 相关阅读:
    springmvc 注解式开发 处理器方法的返回值
    springmvc 注解式开发 接收请求参数
    【洛谷P1379】八数码难题 状压bfs
    【模板】ST表
    【POJ1741】Tree
    【洛谷P1073】最优贸易
    【POJ3662】Telephone Lines dij + 二分答案
    【模板】spfa
    【洛谷P2384】最短乘积路径
    【bzoj2038】小Z的袜子
  • 原文地址:https://www.cnblogs.com/Answer1215/p/8285344.html
Copyright © 2011-2022 走看看