简体   繁体   English

TouchableOpacity 不适用于 expo 以进行本机反应

[英]TouchableOpacity not working on expo for react native

Am working on this login page where I had to use TouchableOpacity on a this text "Already have an account? Sign in instead."正在这个登录页面上工作,我必须在此文本上使用 TouchableOpacity“已经有一个帐户?请改为登录。” to send me to the singin screen and for some reason it didn't work so naturally I thought I had an error in my code and after hours of debugging I had the idea to make a simple button with the same functionality and it works for am wondering is there something wrong with TouchableOpacity on expo or there is somekind of logic error i missed.将我发送到 singin 屏幕,但由于某种原因它不能正常工作,我认为我的代码有错误,经过数小时的调试,我有了制作一个具有相同功能的简单按钮的想法想知道 expo 上的 TouchableOpacity 是否有问题,或者我错过了某种逻辑错误。

here is the code i used:这是我使用的代码:

From my signup screen:从我的注册屏幕:

return (
    <View style={styles.container}>
      <NavigationEvents onWillBlur={clearErrorMessage} />
      <AuthForm
        headerText="Sign Up for Tracker"
        errorMessage={state.errorMessage}
        submitButtonText="Sign Up"
        onSubmit={signup}
      />
      <NavLink
        routeName="Signin"
        text="Already have an account? Sign in instead!"
      />
    </View>
  );

from the Navlink component:来自 Navlink 组件:

return (
    <>
      <TouchableOpacity onPress={() => navigation.navigate(routeName)}>
        <Spacer>
          <Text style={styles.link}>{text}</Text>
        </Spacer>
      </TouchableOpacity>
      <Button
        title="go to sing in"
        onPress={() => {
          navigation.navigate("Singin");
        }}
      />
    </>
  );

This routeName is not a name.routeName不是名称。 You said that you had the idea to make a simple button with the same functionality and it works.你说你有想法制作一个具有相同功能的简单按钮并且它可以工作。 It works is because you give the right routename as "Singin"它有效是因为您将正确的routename为“Singin”

So you just replace所以你只需更换

<TouchableOpacity onPress={() => navigation.navigate(routeName)}>

with

<TouchableOpacity onPress={() => navigation.navigate("Singin")}>

should be work.应该是工作。

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

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