【问题标题】:Is there a way to implement Stack Navigation inside view?有没有办法在视图内实现堆栈导航?
【发布时间】:2021-04-18 05:40:37
【问题描述】:

我正在为我的班级创建一个基本的 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;

【问题讨论】:

    标签: reactjs react-native navigation


    【解决方案1】:

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

    等待您的反馈谢谢 :)。有任何疑问欢迎随时提问。

    【讨论】:

    • 谢谢,它成功了。我想知道为什么我不能将 Navigator 放在 View 中。知道为什么吗?
    • 不客气!它不起作用,因为组件&lt;Stack.Navigator/&gt; 仅在您“注册”应用程序将拥有的屏幕的组件中工作,通常您将Navigation.Container 放在其中。更多细节可以在 react 导航的docs 看到。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-29
    • 2011-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多