具有React Native Router Flux的合成场景堆栈(历史)

时间:2016-12-25 11:25:05

标签: javascript react-native redux persistence react-native-router-flux

有没有办法如何使用React Native Router Flux综合定义场景堆栈(历史记录)?假设我有一个应用,用户可以自然地从A –> B –> C导航。我想在场景C上启动应用,它与自然行为(A -> B -> C)具有相同的历史记录,因此用户可以从最初打开的场景B导航回C

编辑:我想通过使用Redux Persist可以以某种方式实现,但我发现这与issue相关。

1 个答案:

答案 0 :(得分:1)

我设法做了一个假的空初始场景。它是非常hacky的解决方案,从C到B的动画仍然无法正常工作。

import React, {Component} from "react";
import {AppRegistry} from "react-native";
import {Scene, Router, Actions, ActionConst} from "react-native-router-flux";
import A from "./A";
import B from "./B";
import C from "./C";

class App extends React.Component {
  componentDidMount() {
    const params = {
      onBack: () => Actions.b({
        direction: 'fade',
        onBack: () => Actions.a({
          direction: 'fade'
        })
      }),
      duration: 0
    };
    Actions.c(params);
  }

  render() {
    return (
        <Router>
          <Scene key="root" style={{paddingTop: 60}}>
            <Scene key="empty"
                   component={class extends Component{render() {return null}}}
                   />
            <Scene key="a" component={A} title='A' type={ActionConst.RESET}/>
            <Scene key="b" component={B} title='B'/>
            <Scene key="c" component={C} title='C'/>
          </Scene>
        </Router>
    )
  }
}

AppRegistry.registerComponent('untitled', () => App);