简体   繁体   中英

Keyboard Hiding in react-native

I just followed the answer from the link react-native: hide keyboard

But the keyboard is coming as flash for fraction of seconds then it is dismissing. Is there is a way to avoid keyboard totally.

This helped me:

import { Keyboard } from 'react-native'

// Hide that keyboard!
Keyboard.dismiss();

Correct way is to dismiss View with TouchableWithoutFeedback and calling Keyboard.dismiss()

import {Keyboard} from 'react-native'

<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
   <View style={styles.container}>
      <TextInput keyboardType='numeric'/>
   </View>
</TouchableWithoutFeedback>

You can use Keyboard.dismiss() for keyboard hide.

import React from "react";
import {
  Keyboard,
  StyleSheet,
  View,
  TextInput,
  TouchableOpacity
} from "react-native";

export default function App() {
  return (
    <TouchableOpacity  onPress={() => Keyboard.dismiss()}>
      <View style={styles.MainContainer}>
        <TextInput
          style={styles.textinput}
          placeholder="Enter Your Name"
        />
      </View>
    </TouchableOpacity>
  );
}

const styles = StyleSheet.create({
  MainContainer: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center"
  },
  text: {
    fontSize: 28,
    textAlign: "center"
  },
  textinput: {
    paddingVertical: 12,
    margin: 8,
    borderRadius: 7,
    backgroundColor: "#F9FBE7",
    borderWidth: 2,
    borderColor: "#000000",
    textAlign: "center"
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM