在弹出窗口

时间:2017-01-01 11:41:23

标签: react-native

如何重新运行React Component Lifecycle方法,以确定在使用React Native Router Flux从堆栈转换回以前的屏幕时是否需要重新渲染?

场景场景A - > B - >一个 可以说,A是最初的场景,我们使用 push即Actions.SceneB 从A导航到B.从B到A,带有 Pop 。当弹出堆栈以显示Scene-A时,没有为Scene-A调用React Component方法。如何确定是否需要重新渲染?我搜索了github repo上列出的问题,许多人似乎没有解决方案就遇到了这个问题。这个问题是如何解决的?

我使用setTimeout调用Actions.refresh()的工作很丑陋。


解决方法有效! 这种解决方法似乎很棘手。必须有更好的方法来挂钩组件生命周期,以确定是否需要重新渲染。也许是对Component的回调?

<TouchableHighlight underlayColor='#efefef' onPress={() => { Actions.pop(); setTimeout(()=> Actions.refresh(), 500)}} style={styles.cancel}>

不起作用的选项

Actions.pop({type: 'reset'})

          OR

Actions.refresh({"key" : "sceneA"})

2 个答案:

答案 0 :(得分:2)

努力工作!这种解决方法似乎很棘手。必须有更好的方法来挂钩组件生命周期,以确定是否需要重新渲染。

<TouchableHighlight underlayColor='#efefef' onPress={() => { Actions.pop(); setTimeout(()=> Actions.refresh(), 500)}} style={styles.cancel}>

这将调用shouldComponentUpdate()方法,该方法提供了一个选项,用于确定是否需要重新渲染。

答案 1 :(得分:0)

我在代码给我所需的结果下面也面临着同样的问题。

let count = 0;
moveToMainScreen = () => {
    count += 1;
    Actions.pop({ refresh: { test: count } });
};



<Button onPress={this.moveToMainScreen}> Click </Button>
相关问题