我有一个AccountScreen功能。在此屏幕上,我希望能够navigate.goBack()
。我尝试按照指南here进行操作,以了解如何返回上一屏幕,但出现错误。
这是我的代码:
AccountScreen.js
const BackButton = styled.Button`
`;
function AccountScreen({doThis}) {
return(
<Root>
<BackButton title="" onPress={() => doThis} />
<Text>Account</Text>
</Root>
)
};
export default AccountScreen;
navigations.js
const createProfileDrawer = ({navigation}) =>
<Drawer.Navigator>
<Drawer.Screen name="Profile" component={ProfileScreen}/>
<Drawer.Screen name="Account"
component={AccountScreen(navigation.goBack())} />
</Drawer.Navigator>
因此,当我尝试像这样传递它时,出现错误The action 'GO_BACK' was not handled by any navigator.
是否可以传递像这样的函数?
答案 0 :(得分:0)
尝试进行以下更改:
在AccountScreen.js
中:
import { useNavigation } from '@react-navigation/native';
function AccountScreen() {
const navigation = useNavigation();
return(
<Root>
<BackButton title="" onPress={() => navigation.openDrawer()} />
在navigations.js
中:
<Drawer.Screen name="Account" component={AccountScreen} />
请注意,您想要执行的操作可能不是“ goBack”,而是“ openDrawer”。