当使用react-router-native卸载React组件时,Android UI组件仍在运行

时间:2017-06-05 15:43:54

标签: react-native react-router react-native-android

将我的应用程序的导航处理从react-native-router-flux移动到react-router-native时,我似乎发现了我的应用程序的本机UI操作系统的处理问题。 / p>

我的应用程序有几个动画数据图,我用Java实现并以Native UI Components的形式导入React Native。可视化由在加载ui组件时启动的后台线程上的一些资源饥饿的可运行程序提供支持。以前,我通过将原生ui组件(isVisible)的prop更改为false来停止这些线程。

但是,当从包含react-router-native(在转换时卸载组件)的包含其中一个本机ui组件的屏幕导航时,即使在react组件中调用componentWillUnmount,为我的绘图提供动力的本机线程也会继续运行。

我试图通过在componentWillUnmount中将原生ui组件prop isVisible更改为false来关闭它们,但即使这样也无法解决问题。也许是因为在componentWillUnmount之后没有该组件的另一个渲染?

有没有人有任何关于如何强制原生UI组件及其所有进程在卸载父级时关闭的想法?

1 个答案:

答案 0 :(得分:1)

After fiddling around for a while I came up with a solution that I thought I should share here.

It's not included in the React Native docs, but there is a function called onDropViewInstance that is called in the React SimpleViewManager class whenever a Native Java UI Components is unmounted.

In order to get around my problem of having some thread still running, all I had to do was explicitly stop those threads in that onDropViewInstance function.