listenzz / hybrid-navigation

React Native Navigation that supports seamless navigation between Native and React.
MIT License
325 stars 37 forks source link

app启动闪退 #240

Closed labike closed 2 years ago

labike commented 2 years ago

1661506995259 1661507036106 1661507077774

按照教程中, rn中index.js里导入'./src/views/navigation'和'./src/views/options'启动app后闪退没找到哪里原因帮忙看看谢谢!

index.js:

import Navigation from 'hybrid-navigation'

import NavigationScreen from './src/views/Navigation'
import Options from './src/views/Options'

// 重要必须
Navigation.startRegisterComponent()

// 注意,你的每一个页面都需要注册
Navigation.registerComponent('Navigation', () => NavigationScreen)
Navigation.registerComponent('Options', () => Options, { path: '/options' })

// 重要必须
Navigation.endRegisterComponent()

// 通过 `Navigator#setRoot` 来设置 UI 层级
const navigationStack = {
  stack: {
    children: [{ screen: { moduleName: 'Navigation' } }],
  },
}

const optionsStack = {
  stack: {
    children: [{ screen: { moduleName: 'Options' } }],
  },
}

const tabs = {
  tabs: {
    children: [navigationStack, optionsStack],
    options: {
    //tabBarModuleName: 'BulgeTabBar',
    //sizeIndeterminate: true,
    //tabBarModuleName: 'CustomTabBar',
    //sizeIndeterminate: false,
    //selectedIndex: 1,
    },
  },
}

const drawer = {
  drawer: {
    children: [tabs],
    options: {
      maxDrawerWidth: 280,
      minDrawerMargin: 64,
    },
  },
}

// 设置 UI 层级
Navigation.setRoot(drawer)
listenzz commented 2 years ago
const drawer = {
  drawer: {
    children: [tabs],
    options: {
      maxDrawerWidth: 280,
      minDrawerMargin: 64,
    },
  },
}

drawer 的 children 应该是一个长度为 2 的数组,你可以试试 Navigation.setRoot(tabs) 正不正常先。

listenzz commented 2 years ago
<div>Navigation</div>

是用了什么 UI 框架吗

labike commented 2 years ago

@listenzz 大意了写成了div应该是, 不过我按照你说的Navigation.setRoot(tabs)也还是闪退

labike commented 2 years ago

@listenzz 会不会跟我的rn版本有关

listenzz commented 2 years ago

@listenzz 会不会跟我的rn版本有关

和版本无关,你可以查看 android 日志,看下为什么崩溃吗?

npx react-native log-android
listenzz commented 2 years ago

原因大概是

Did you forgot to call Navigation.setDefaultOptions before Navigation.setRoot ?

labike commented 2 years ago

@listenzz 雀实要设置全局样式,感谢!!!