<TouchableWithoutFeedback>
navigateToRentable = () => {
console.log('in navigateToRentable');
this.props
.navigation
.dispatch(StackActions.reset({
index: 0,
actions: [
NavigationActions.navigate({
routeName: 'Rent',
actions: [
NavigationActions.navigate({
routeName: 'Rentable',
}),
]
}),
],
}))
}
in navigateToRentable
在我的控制台中,所以我知道方法正在启动,但是没有其他事情发生-控制台中没有其他输出。
摄影师.js
import React from 'react';
import { StyleSheet, Text, View, Alert, Permissions, Linking, TouchableOpacity, Platform, ImageStore, Dimensions } from 'react-native';
import { createStackNavigator } from 'react-navigation';
import RentScreenNavigator from './RentScreenNavigator';
import RentScreen from '../pages/RentScreen';
import CameraScreen from '../pages/CameraScreen';
import RentableScreen from '../pages/RentableScreen';
export default CameraNavigator = createStackNavigator(
{
OpenCamera: {
screen: CameraScreen,
navigationOptions: ({ navigation }) => ({
header: null
}),
},
RentDetails: {
screen: RentScreen,
navigationOptions: ({ navigation }) => ({
header: null
}),
},
Rentable: {
screen: RentableScreen,
navigationOptions: ({ navigation }) => ({
header: null
}),
}
},
{
initialRouteName: 'Rent',
},
);
CameraScreenNavigator.js公司
import React from 'react';
import { StyleSheet, Text, View, Alert, Permissions, Linking, TouchableOpacity, Platform, ImageStore, Dimensions } from 'react-native';
import { createStackNavigator } from 'react-navigation';
import CameraNavigator from './CameraNavigator';
export default class CameraScreenNavigator extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<CameraNavigator/>
)
}
};
应用程序.js
import React from 'react';
import { StyleSheet, Platform, Image, Text, View, ScrollView } from 'react-native';
import Ionicons from 'react-native-vector-icons/Ionicons';
import { Icon } from 'react-native-elements';
import { createBottomTabNavigator } from 'react-navigation';
import firebase from 'react-native-firebase';
import { YellowBox } from 'react-native';
import HomeScreen from './pages/HomeScreen';
import ProfileScreen from './pages/ProfileScreen';
//import CameraScreen from './pages/CameraScreen';
import CameraScreenNavigator from './components/CameraScreenNavigator';
//import RentScreenNavigator from './components/RentScreenNavigator';
YellowBox.ignoreWarnings(['Class RCTCxxModule']);
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader']);
YellowBox.ignoreWarnings(['You should only render one navigator explicitly in your app, and other navigators should by rendered by including them in that navigator.']);
const AppNavigator = createBottomTabNavigator(
{
Home: HomeScreen,
Profile: ProfileScreen,
Rent: CameraScreenNavigator,
},
{
navigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
let iconName;
if (routeName === 'Home') {
iconName = 'home';
} else if (routeName === 'Profile') {
iconName = 'user';
} else if (routeName === 'Rent') {
iconName = 'plus-square';
}
// You can return any component that you like here! We usually use an
// icon component from react-native-vector-icons
return (
<Icon
name={iconName}
color={tintColor}
type='feather'
/>
)
}
}),
tabBarOptions: {
activeTintColor: '#fff',
inactiveTintColor: '#c9fffd',
activeBackgroundColor: '#6de3dc',
inactiveBackgroundColor: '#6de3dc'
},
},
);
export default class App extends React.Component {
render() {
return (
<AppNavigator/>
)
}
}
StackActions.reset
,我正在尝试导航到
Rentable
属于
CameraNavigator
,这是一个主要的子导航器
App
导航器。我正试图执行
堆栈操作.重置
Home
路由,它是根的一部分
应用程序
导航器。
navigate
把我带到
可出租的
路线。
我试过:
this.props
.navigation
.dispatch(
NavigationActions.navigate({
routeName: 'Rent',
actions: [
NavigationActions.navigate({
routeName: 'Rentable',
}),
]
}),
)
第一个
Navigation.navigate
工作,但
sub-action
导航到
没有。
我仍然在寻找为什么StackActions.reset不起作用的答案-但是对于我试图做的事情(从父导航器导航到子导航器的页面)…我在这里找到了@kashishgrover提出的解决方法/方法:
https://github.com/react-navigation/react-navigation/issues/2398
然而,这并不是一个完美的解决方法—它强制应用程序转到中间页,然后侦听参数,因此在一瞬间—中间页加载,然后加载预期的页面。