首先请问我英语不好。
我正在使用React-native开发App。对于导航,我使用redux模式。
我遇到了很大的问题,无法理解发生了什么事。
首先,我有我的组件导航器:
import React from 'react';
import {
createStackNavigator,
createSwitchNavigator,
createBottomTabNavigator
} from 'react-navigation';
import { connect } from 'react-redux';
import Login from '../auth/login';
import CreateTrip from '../trip/create';
import DeleteTrip from '../trip/delete';
import Signup from '../signup/signup';
import Trip from '../trip/index';
import Secured from '../home/home';
import ConfirmIdentity from '../confirmIdentity';
import {createReactNavigationReduxMiddleware, reduxifyNavigator} from "react-navigation-redux-helpers";
const middleware = createReactNavigationReduxMiddleware(
'root',
state => state.nav
);
const RootNavigator = createStackNavigator({
loginFlow: {
screen: createBottomTabNavigator({
Login: {screen: Login , navigationOptions: { tabBarVisible: false }},
Register: {screen: Signup , navigationOptions: { tabBarVisible: false }},
},
{initialRouteName: 'Login'})
},
homeFlow: {
screen: createBottomTabNavigator({ Dashboard: {screen: Secured},
Trip: {screen: Trip, navigationOptions: { tabBarVisible: false }},
ConfirmIdentity: {screen: ConfirmIdentity, navigationOptions: { tabBarVisible: false }},}),
},
tripFlow: {
screen: createSwitchNavigator({
CreateTrip: {screen: CreateTrip},
DeleteTrip: {screen: DeleteTrip}
},
{initialRouteName: 'CreateTrip'})
}
},
{navigationOptions: {header: null}});
const AppWithNavigationState = reduxifyNavigator(RootNavigator, 'root');
const mapStateToProps = state => ({
state: state.nav,
});
const AppNavigator = connect(mapStateToProps)(AppWithNavigationState);
export { RootNavigator, AppNavigator, middleware };
我的减速机导航:
import { NavigationActions } from 'react-navigation';
import { RootNavigator } from '../../components/navigator/navigation';
const initialNavState = RootNavigator.router.getStateForAction(NavigationActions.navigate({ routeName: 'Login' }));
function navAuthReducer(state = initialNavState, action) {
let nextState;
RootNavigator.router.display = false;
console.log(action.type);
switch (action.type) {
case 'LOGIN':
nextState = RootNavigator.router.getStateForAction(
NavigationActions.navigate({ routeName: 'Dashboard' }),
state
);
break;
case 'LOGOUT':
nextState = RootNavigator.router.getStateForAction(
NavigationActions.navigate({ routeName: 'Login' }),
state
);
break;
case 'GOREG':
nextState = RootNavigator.router.getStateForAction(
NavigationActions.navigate({ routeName: 'Register' }),
state
);
break;
case 'CREATE':
nextState = RootNavigator.router.getStateForAction(NavigationActions.navigate({ routeName: 'CreateTrip' },
state
));
break;
case 'DELETE':
nextState = RootNavigator.router.getStateForAction(
NavigationActions.navigate({ routeName: 'DeleteTrip' }),
state
);
break;
default:
nextState = RootNavigator.router.getStateForAction(action, state);
break;
}
// Simply return the original `state` if `nextState` is null or undefined.
return nextState || state;
}
export default navAuthReducer;
这是我的旅行索引。我可以在此页面上单击该按钮来进行案例创建吗:
import {Component} from "react";
import connect from "react-redux/es/connect/connect";
import React from "react";
import {Button, ScrollView, Text} from "react-native";
import {creatingTrip} from "../../actions/trip";
class Index extends Component {
createTrip(e) {
e.preventDefault();
this.props.onCreateTrip();
}
render() {
return (
<ScrollView>
<Text>${this.props.isCountryExist}</Text>
<Button onPress={(e) => this.createTrip(e)} title="Logout"/>
</ScrollView>
);
}
}
const mapStateToProps = (state, ownProps) => {
return {
isCountryExist: state.tripReducer.isCountryExist
};
};
const mapDispatchToProps = (dispatch) => {
return {
onCreateTrip: () => { dispatch(creatingTrip()); }
}
};
export default connect(mapStateToProps, mapDispatchToProps)(Index);
当我要创建案件时,我不知道为什么我的应用程序显示登录页面。
我所做的事情:
谢谢所有答案。
答案 0 :(得分:0)
问题出在这条线上:
ds = set(D)
c_min, c_max = min(C), max(C)
d_min, d_max = min(ds), max(ds)
shortcuts = {}
for a in A:
for b in B:
s = a + b
if s in shortcuts:
for c, d in shortcuts[s]:
print(a, b, c, d)
continue
shortcuts[s] = []
if s + c_min + d_min > X or s + c_max + d_max < X:
continue
for c in C:
d = X - a - b - c
if d in ds:
print(a, b, c, d)
shortcuts[s].append((c, d))
括号不在适当位置。
nextState = RootNavigator.router.getStateForAction(
NavigationActions.navigate({ routeName: 'CreateTrip' },
state));