listenzz / hybrid-navigation

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

Navigation.setDefaultOptions seems only works in andriod #252

Open daselang opened 9 months ago

daselang commented 9 months ago

version: "hybrid-navigation": "^2.16.6" "react-native": "0.72.4", Hi, I use Navigation.setDefaultOptions(globalDefaultOptions); before Navigation.startRegisterComponent(withRedux); and Navigation.setRoot(navigationStack); in android phone and simulator,it works well. but for IOS platform, setDefaultOptions has no effect, in the scenario UI page, I should use the sample codes below to make multi-platforms work in same action.

It seems that, the {XXX:YYY} in withNavigationItem merges with the globalDefaultOptions to generate a new option in android, but in IOS ,it replaces the globalDefaultOptions.

export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(
  withNavigationItem({
    statusBarHidden: false,
    topBarHidden: false,
    backButtonHidden: false,
    titleItem: {
      title: 'Home',
    },
  })(HomeScene),
);

so I have to use ... to expand the globalDefaultOptions and merge the key-value pairs into withNavigationItem({}) to make IOS taking effects,same code as in android.

export default connect(
  mapStateToProps,
  mapDispatchToProps,
)(
  withNavigationItem({
    ...globalDefaultOptions,
    statusBarHidden: false,
    topBarHidden: false,
    backButtonHidden: false,
    titleItem: {
      title: 'Home',
    },
  })(HomeScene),
);

Do you what the root cause is?

listenzz commented 9 months ago

Would it be possible to provide a repo that reproduces this issue?

daselang commented 9 months ago

Would it be possible to provide a repo that reproduces this issue?

@listenzz 目前没有在github上面弄个repo复现。就是 globalOption里面 ,假设 backgroundColor是黑色,Navigation.setDefaultOptions 在andriod上面生效,但是在IOS 上面,背景还是默认的白的。于是我只能在每个页面的withNavigationItem里面把 globalOption ...展开merge到单项里面才生效。 看上去像在android里面是 页面options与globalOptions是合并的。但是在ios里面是页面的options是直接replace了globalOptions.

listenzz commented 9 months ago

iOS 也是 merge 的,我这边无法重现你说的问题

daselang commented 8 months ago

iOS 也是 merge 的,我这边无法重现你说的问题

sorry,我的代码并没有什么特殊的。现实的效果就是我描述的那样,andriod merged(correct),IOS replaced(incorrect)。最后只能用...globalOptions来统一merge了。如果不能复现,留意着吧。