withNavigation只能在导航器的本机视图层次结构上使用

时间:2019-12-11 07:24:19

标签: reactjs react-native redux react-redux

我使用了React Native paper BottomNavigation。现在,我尝试使用“导航”选项卡中的“返回”按钮,并且收到错误消息

  

不变违反:withNavigation仅可用于导航器的视图层次结构。包装的组件无法从道具或上下文访问导航。

HomeScreen.js

import React from 'react'
import { View, StatusBar, Button} from 'react-native'
import { Subheading, withTheme } from 'react-native-paper'
import { withNavigation } from 'react-navigation';
import styles from '../assets/css/Style';  

class HomePageView extends React.Component { 
    render() {
        return (
            <View style={[styles.container]}>
                <StatusBar hidden />
                <View style={styles.row}>
                    <Subheading>Home Screen</Subheading>
                </View>
                <Button
                    title="Back"
                    onPress={() => {
                        this.props.navigation.goBack();
                    }}
                />
            </View>
        );
    }
}


function HomeScreen({ theme }) {
    const { colors } = theme
    return (<HomePageView style={[styles.container, { backgroundColor: colors.surface }]} />) 
} 


export default withNavigation(withTheme(HomeScreen)); 

1 个答案:

答案 0 :(得分:2)

我认为

  

您使用的是本机纸并且导航属于另一种   图书馆反应导航

,谢谢