0

我正在尝试React Native通过创建应用程序来学习。触摸图像后,我希望在当前屏幕上方放置一个新屏幕。

我想我想使用StackNavigatorafter onPress?我已经阅读过它们,但不知道如何在我当前的代码中使用它们。有任何想法吗??

const listView = ({name, picture}) => { 
       return (  
        <View style = {styles.item}>  
          <TouchableWithoutFeedback onPress={() => //new screen here!!}>  
            <ImageBackground source = {picture}  
                             resizeMode = 'cover'  
                             style={styles.image}>  
                <Text style={styles.text}>{name}</Text>  
            </ImageBackground>  
            </TouchableWithoutFeedback>  
        </View>  
      )  
};

请在评论中留下您需要的任何问题。

4

1 回答 1

0

您可以使用Createrestacknavigator.

示例应用程序.js:

import React, { Component } from "react";
import {
  createStackNavigator,
  createAppContainer,
} from "react-navigation";
import Home from "./Home.js"
import Second from "./Second.js"
...
const RootStack = createStackNavigator(
  {
    Home: {
      screen: Home
    },
    Second: {
      screen: Second
    }   
  },
  {
    initialRouteName: "Home",
    headerMode: "none"
  }
);
const AppContainer = createAppContainer(RootStack);
export default AppContainer;

示例主页.js:

 return (  
        <View style = {styles.item}>  
          <TouchableOpacity onPress={() => this.props.navigation.navigate("Second")}>  
            <ImageBackground source = {picture}  
                             resizeMode = 'cover'  
                             style={styles.image}>  
                <Text style={styles.text}>{name}</Text>  
            </ImageBackground>  
            </TouchableOpacity >  
        </View>  
      )  

有关功能的更多信息,请参阅此链接

于 2019-04-18T10:42:21.963 回答