将本机重定向反应到具有类的另一页面

时间:2019-12-07 05:14:06

标签: react-native

//PostImageScreen.js

import * as ImagePicker from "expo-image-picker";

const firebase = require("firebase");
require("firebase/firestore");

export default class PostScreen extends React.Component {
    state = {
        text: "",
        image: null
    };

    componentDidMount() {
        this.getPhotoPermission();
    }
   //etc...
   
   
   
   
//ImagesScreen.js

import PostScreen from "./PostImageScreen";
import { createStackNavigator } from "react-navigation-stack";

const redirects = createStackNavigator({
  Post: { screen: PostScreen }
});

export default class ImagesScreen extends React.Component {

  // buttonPressed = async () => {
  buttonPressed = () => {
      this.props.navigation.navigate('Post');
  };

  render() {
    const { navigate } = this.props.navigation;
    return (

  <Background>
    
    <Header>Image Display Screen</Header>
    
    <Button mode="outlined" onPress={() => logoutUser()}>
      Logout
    </Button>
    <ActionButton buttonColor="#1E73C1" onPress={() => navigate('Post')}>
          </ActionButton>
  </Background>
    )
  }

所以现在我没有收到来自按钮的响应,只是对解决方法感到好奇?以前,ImagesScreen是一个函数,我将其转换为类以尝试使用堆栈导航器,但仍无法解决。

我只希望ActionButton重定向到PostImageScreen,以便我可以添加带有注释的图像,然后发布它。该发布有效,经过重新测试后才遇到重定向问题。

跟进*** 也尝试过此操作,并且在按下按钮时仍然没有任何结果。

const ImagesScreen = ({ navigation }) => {

  
    return (

  <Background>
    
    <Header>Image Display Screen</Header>
    
    <Button mode="outlined" onPress={() => logoutUser()}>
      Logout
    </Button>
    {/* <ActionButton buttonColor="#1E73C1" onPress={() => navigate('Post')}>
          </ActionButton> */}
          <TouchableOpacity
          onPress={() => navigation.navigate("PostImageScreen")}
        >
          <Text >Add an Image</Text>
        </TouchableOpacity>
  </Background>
    )
}

export default memo(ImagesScreen);

1 个答案:

答案 0 :(得分:0)

没关系了!

我在stacknavigator中有一个Switch导航器,它可以控制我的用户身份验证,然后在登录时切换到选项卡导航。该导航阻止了我的导航调用!

4个小时,但我终于明白了,谢谢上帝哈哈。