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;
  • 相关阅读:
    2-反向调试
    1-断点调试
    gdb基础用法
    protobuf学习手册(上)
    1024 科学计数法 (20 分)
    1023 组个最小数 (20 分)
    1018 锤子剪刀布 (20 分)
    1015 德才论 (25 分)
    1020 月饼 (25 分)
    1019 数字黑洞 (20 分)
  • 原文地址:https://www.cnblogs.com/Answer1215/p/8285344.html
Copyright © 2011-2022 走看看