繁体   English   中英

React Native 键盘显示但似乎无法检测输入(Android)

[英]React Native Keyboard Shows But Doesn't Appear to Detect Input (Android)

我正在尝试在 React Native 中设置一些输入,如下面的代码所示,但是我有一个奇怪的错误,我可以单击输入框,显示键盘,但是如果我单击键盘,它不会做任何事情,我什至不能按 shift 或打开数字部分。 例如,当我更改“名称”状态时,问题肯定不会显示值,因为它会发生变化。

为什么我的 React Native 中的键盘完全没有响应?

编辑:所以如果我在网络版本中运行它,输入完全正常并且一切正常,我的键盘只是在应用程序的 Expo Go 构建中不起作用,有人可以帮忙吗?

import { useState } from "react";
import {
  Button,
  StyleSheet,
  TextInput,
  ScrollView,
  ActivityIndicator,
  View,
} from "react-native";
import firebase from "../database/firebaseDb";

const AddUserScreen = () => {
  const [dbRef, setDbRef] = useState(firebase.firestore().collection("users"));
  const [name, setName] = useState("namehi");
  const [email, setEmail] = useState("");
  const [mobile, setMobile] = useState("");
  const [isLoading, setIsLoading] = useState(false);

  const storeUser = () => {
    if (name === "") {
      alert("Please fill in at least your name.");
    } else {
      setIsLoading(true);
      dbRef
        .add({
          name: name,
          email: email,
          mobile: mobile,
        })
        .then((res) => {
          setName("");
          setEmail("");
          setMobile("");
          setIsLoading(false);
          this.props.navigation.navigate("UserScreen");
        })
        .catch((err) => {
          console.error("Error found: ", err);
          setIsLoading(false);
        });
    }
  };

  if (isLoading) {
    return (
      <View style={styles.preloader}>
        <ActivityIndicator size="large" color="#9E9E9E" />
      </View>
    );
  }

  return (
    <ScrollView style={styles.container}>
      <View style={styles.inputGroup}>
        <TextInput
          placeholder={"Name"}
          value={name}
          onChangeText={(val) => {
            console.log(val); // <<<<<<<< This console.log doesn't fire at all
            setName("it worked");
          }}
        />
      </View>
      <View style={styles.inputGroup}>
        <TextInput
          multiline={true}
          numberOfLines={4}
          placeholder={"Email"}
          value={email}
          onChangeText={setEmail}
        />
      </View>
      <View style={styles.inputGroup}>
        <TextInput
          placeholder={"Mobile"}
          value={mobile}
          onChangeText={setMobile}
        />
      </View>
      <View style={styles.button}>
        <Button title="Add User" onPress={() => storeUser()} color="#19AC52" />
      </View>
    </ScrollView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 35,
  },
  inputGroup: {
    flex: 1,
    padding: 0,
    marginBottom: 15,
    borderBottomWidth: 1,
    borderBottomColor: "#cccccc",
  },
  preloader: {
    left: 0,
    right: 0,
    top: 0,
    bottom: 0,
    position: "absolute",
    alignItems: "center",
    justifyContent: "center",
  },
});
export default AddUserScreen;

你必须使用箭头函数来调用 setEmail

const onChangeEmailHandler = (t) => {
 setEmail(t)
}
.
.
.
 <TextInput
          multiline={true}
          numberOfLines={4}
          placeholder={"Email"}
          value={email}
          onChangeText={onChangeEmailHandler}
        />

最终,在我的手机上多次卸载并重新安装该应用程序后,这开始为我工作,这似乎是 Expo Go 而不是代码的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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