Skip to content

Nav bar save props#2211

Merged
guyca merged 2 commits into
masterfrom
navBarSaveProps
Nov 23, 2017
Merged

Nav bar save props#2211
guyca merged 2 commits into
masterfrom
navBarSaveProps

Conversation

@guyca
Copy link
Copy Markdown
Collaborator

@guyca guyca commented Nov 23, 2017

fixes #1961, #1546, #1705

This commit changes the way props are injected into custom navBar components. Instead of passing props over the bridge and initializing the native component with them, props are now stored in Js, and are injected back when the react component is created.
This change lets us pass unserializable props to the component.

For example, passing a navigator to the component is now possible:

componentDidMount() {
    this.props.navigator.setStyle({
      navBarCustomView: 'example.CustomTopBar',
      navBarComponentAlignment: 'center',
      navBarCustomViewInitialProps: {title: 'Hi!', navigator: this.props.navigator}
    });
  }

This commit saves navBar component props in propsRegistry and restores the saved props
when the component is mounted, allowing us to pass unserializable props to custom navBar component.
@guyca guyca merged commit 6170e70 into master Nov 23, 2017
@guyca guyca deleted the navBarSaveProps branch November 23, 2017 10:04
thanhzusu pushed a commit to thanhzusu/react-native-navigation that referenced this pull request Nov 27, 2017
* master: (22 commits)
  setTabButton to change the label of the TabButton (wix#2215)
  3D Touch Preview API (wix#2186)
  Update android-specific-use-cases.md
  Update android-specific-use-cases.md
  Load props from props registry for redux screens
  Nav bar save props (wix#2211)
  Support passing unserializable props to custom navBar component
  Save buttons props for root screens
  Ensure that styles set on individual buttons are not overridden (wix#2200)
  Update top-level-api.md
  (Android) Allow disableOpenGesture right or left in the drawer (wix#2189)
  Revert "Support iOS 11 prefersLargeTitles #1643 (wix#2090)" (wix#2204)
  Support iOS 11 prefersLargeTitles #1643 (wix#2090)
  Support passing unserializable props to custom button (wix#2192)
  addOnNavigatorEvent improvements (wix#2175)
  Fix missing props (wix#2179)
  Revert "Don't custom button props over the bridge (wix#2174)" (wix#2177)
  Don't custom button props over the bridge (wix#2174)
  Set missing TopBar background color
  Register multiple navigatorEventListeners (wix#2173)
  ...
garrettm pushed a commit to Ginger-Labs/react-native-navigation that referenced this pull request Dec 19, 2017
This commit saves navBar component props in propsRegistry and restores the saved props
when the component is mounted, allowing us to pass unserializable props to custom navBar component.
garrettm pushed a commit to Ginger-Labs/react-native-navigation that referenced this pull request Dec 19, 2017
This commit saves navBar component props in propsRegistry and restores the saved props
when the component is mounted, allowing us to pass unserializable props to custom navBar component.
@ghoshabhi
Copy link
Copy Markdown

ghoshabhi commented Jan 16, 2018

Hello @guyca ! Thank you for bringing in this change. Unfortunately, when I tried to pass the navigator through the navBarCustomViewInitialProps - I get an error saying: TypeError: Converting circular structure to JSON.

Here's my code:

ViewContainer.js

componentDidMount() {
    const { type } = this.props;
    const navBarLabel = this.getNavBarLabel(type);
    this.props.navigator.setStyle({
      navBarCustomView: 'Foo.CustomNavbar',
      navBarComponentAlignment: 'center',
      navBarCustomViewInitialProps: {
        navBarLabel,
        navigator: this.props.navigator, // <=======
      },
    });
  }

Below is the error I see:

screen shot 2018-01-16 at 6 50 25 am

Anything obvious that I am doing wrong ?

@witalobenicio
Copy link
Copy Markdown

@ghoshabhi you are getting RNN from master branch or npm package?
try this way:
"react-native-navigation": "git+https://github.com/wix/react-native-navigation.git",

@ghoshabhi
Copy link
Copy Markdown

@witalobenicio : Thank you for your suggestion. I think we are using a forked version at our company. Will try out your suggestion 👍 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants