react-native-router-flux:onLeft场景

时间:2017-03-30 12:04:06

标签: reactjs react-native ecmascript-6 react-native-router-flux

当我从场景返回时,我试图为场景employeeEdit场景添加onLeft,如果用户不希望对当前所选员工进行更改,他们将能够返回到员工列表和使用类型进入添加时,字段将被清空:' reset'好像要保存更改。

似乎onLeft在这种情况下不起作用,因为该函数实际上并未执行。

<Router sceneStyle={{ paddingTop: 65 }}>
    <Scene key="auth">
        <Scene key="login" component={LoginForm} title="Please Login" initial />
    </Scene>

    <Scene key="main">
        <Scene 
            onRight={() => Actions.employeeCreate()}
            rightTitle="Add"
            key="employeeList" 
            component={EmployeeList} 
            title="Employees" 
            initial
        />
        <Scene
            key="employeeCreate" 
            component={EmployeeCreate} 
            title="Create Employee" 
        />
        <Scene
            onLeft={() => Actions.employeeList({ type: 'reset' })}
            key="employeeEdit" 
            component={EmployeeEdit} 
            title="Edit Employee" 
        />                
    </Scene>
</Router>

1 个答案:

答案 0 :(得分:1)

更长的方法。

使用componentWillUnmount,这在离开组件时很有效,即EmployeeEdit

componentWillUnmount () {
    this.props.employeeInitial();
}

然后可以调用gigInitial的prop;有一个动作将返回一个类型为'EMPLOYEE_INITIAL'的发送说明

export const employeeInitial = () => {
    return (dispatch) => {
        dispatch({ type: EMPLOYEE_INITIAL });
    };
};

然后在EmployeeFormReducer中返回INITIAL_STATE

case EMPLOYEE_INITIAL:
    return INITIAL_STATE;