我将React-Native-Navigation v2.18.5与React Native 0.59.8一起使用,当我尝试将Navigation.setRoot(...)与bottomTabs布局一起使用时,应用程序崩溃了。控制台中什么都没有显示,但是logcat显示了此内容:
java.lang.RuntimeException: Tried to get null value!
at com.reactnativenavigation.parse.params.Param.get(Param.java:14)
at com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController.lambda$createTabs$3(BottomTabsController.java:155)
at com.reactnativenavigation.viewcontrollers.bottomtabs.-$$Lambda$BottomTabsController$hVDDSxSvqNX-4DhQHls8ynB4x2w.map(Unknown Source:4)
at com.reactnativenavigation.utils.CollectionUtils.map(CollectionUtils.java:42)
at com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController.createTabs(BottomTabsController.java:151)
at com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController.createView(BottomTabsController.java:75)
at com.reactnativenavigation.viewcontrollers.ViewController.getView(ViewController.java:167)
at com.reactnativenavigation.viewcontrollers.ParentController.getView(ParentController.java:60)
at com.reactnativenavigation.viewcontrollers.navigator.RootPresenter.setRoot(RootPresenter.java:35)
at com.reactnativenavigation.viewcontrollers.navigator.Navigator.setRoot(Navigator.java:135)
at com.reactnativenavigation.react.NavigationModule.lambda$setRoot$1(NavigationModule.java:70)
at com.reactnativenavigation.react.-$$Lambda$NavigationModule$IfiDeOnYfgJADKZUxIVN9Zforsw.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
这是我的代码:
import { Navigation } from "react-native-navigation";
import Icon from "react-native-vector-icons/Ionicons";
const startMainTabs = () => {
Promise.all([
Icon.getImageSource("md-body", 30),
Icon.getImageSource("md-time", 30)
])
.then(sources => {
console.log("GOT IMAGES");
console.log(sources[0], sources[1]);
Navigation.setRoot({
root: {
bottomTabs: {
children: [
{
component: {
name: "fitboard.myworkouts",
options: {
buttomTab: {
text: "MyWorkouts",
icon: sources[0]
}
}
}
},
{
component: {
name: "fitboard.hiittimer",
options: {
bottomTab: {
text: "HIITTimer",
icon: sources[1]
}
}
}
}
]
}
}
});
})
.catch(err => {
console.log(err);
});
};
export default startMainTabs;
这些屏幕也在我的App.js中注册:
Navigation.registerComponent(`fitboard.hiittimer`, () => HiitTimer);
Navigation.registerComponent(`fitboard.myworkouts`, () => MyWorkouts);
如您所见,我正在提供图标,所以这不是问题。此外,当我使用组件布局时,react-native-navigation不会使我的应用程序崩溃。有什么想法吗?