我使用react-native-code-push。这是:
此插件为 CodePush 服务提供客户端集成,让您可以轻松地为您的 React Native 应用程序添加动态更新体验。
但是在一些导航的本机实现中,例如react-native-navigation没有任何根组件。该应用程序将开始调用这样的函数:
// index.js
import { Navigation } from 'react-native-navigation';
Navigation.startTabBasedApp({
tabs: [
{
label: 'One',
screen: 'example.FirstTabScreen', // this is a registered name for a screen
icon: require('../img/one.png'),
selectedIcon: require('../img/one_selected.png'), // iOS only
title: 'Screen One'
},
{
label: 'Two',
screen: 'example.SecondTabScreen',
icon: require('../img/two.png'),
selectedIcon: require('../img/two_selected.png'), // iOS only
title: 'Screen Two'
}
]
});
// or a single screen app like:
Navigation.registerComponent('example.MainApplication', () => MainComponent);
Navigation.startSingleScreenApp({
screen: {
screen: 'example.MainApplication',
navigatorButtons: {},
navigatorStyle: {
navBarHidden: true
}
},
})
因为没有根组件,所以不清楚我应该在哪里调用CodePush
,因为通常我应该用 CodePush 包装我的整个根组件,就像一个高阶组件一样。我以前做的是:
// index.js
class MyRootComponent extends Component {
render () {
return <MainNavigator/> // a navigator using react-navigation
}
}
let codePushOptions = {
checkFrequency: CodePush.CheckFrequency.ON_APP_RESUME,
installMode: CodePush.InstallMode.ON_NEXT_RESUME
}
export default CodePush(codePushOptions)(MyRootComponent)
有没有解决这个问题的正确方法!?
我知道我可以这样做:
Navigation.registerComponent('example.MainApplication', () => CodePush(codePushOptions)(RootComponent));
Navigation.startSingleScreenApp({
screen: {
screen: 'example.MainApplication',
navigatorButtons: {},
navigatorStyle: {
navBarHidden: true
}
},
})
但是我应该只使用导航器来投影我的根组件,这看起来不是一个好主意。我认为这个问题可能有我正在寻找的最佳实践。
更新
我认为在 stacknavigator 中注册选项卡导航器有一些复杂性react-native-navigation
,至少我无法克服这个问题。tabBasedApp
中react-native-navigation
的示例react-native-code-push
,将是我所需要的。