有没有办法在视图内实现堆栈导航?

IT技术 reactjs react-native navigation
2022-07-30 00:36:21

我正在为我的class创建一个基本的 React Native 应用程序,但遇到了问题。我正在尝试在我的视图中实现堆栈导航,但由于某种原因它没有显示蓝色堆栈按钮。有可能这样做吗?

import React,{Component} from 'react';
import {View, Text, StyleSheet, Image} from 'react-native';
import { createStackNavigator } from '@react-navigation/stack';
import Home from '../views/Home.js'

let stack = createStackNavigator();

class Account extends Component{
    render(){
        return(
            <View style = {styles.container} >
                <Text style = {styles.PageHeader}>TRENDZ</Text>
                <Text style = {styles.PageSubHeader}> Online Store</Text>
                <Image style = {styles.AccImage} source={require('../../assets/login/login.jpg')} {...this.props} />
                        <stack.Navigator>
                            <stack.Screen name = 'Home' component = {Home} />
                        </stack.Navigator>
            </View>
        )
    }
}

const styles = StyleSheet.create({
    container: {
        marginTop: 20,
    },
    AccImage: {
        height:600,
        width: null
    },
    PageHeader: {
        fontWeight: 'bold',
        fontSize: 70,
        textAlign: 'center',
        color: 'orange'
    },
    PageSubHeader: {
        textAlign: 'center',
        fontSize: 25,
        paddingBottom: 20
    }
})

export default Account;
1个回答

那是不可能的。您只能Stack.Navigator在导航器文件中创建。Stack.Navigator在导航器文件中创建您的,然后调用您想要进入的Àccount屏幕this.props.navigation.navigate('Name of the screen you want to navigate')

等待您的反馈 Thx :)。如有任何疑问,请随时提问。