question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[NavigationExperimental] Best way to dynamically change content of overlay from scene?

See original GitHub issue

I want to control / update content of overlay from the scene component. For example, I want to dynamically change nav bar title based on user interactions inside a scene without doing any navigation.

Afaik, the following is a simplified version of how scene and overlay are rendered inside a AnimatedView or CardStack.

<AnimatedView>
  {scene}
  {overlay}
</AnimatedView>

Correct me if I am wrong, but currently, it seems the only way to trigger rerendering of overlay from the scene is to update navigationState. That means we need to use a reducer to create a new navigationState, which will cause rerendering of scene as well as overlay. It sounds like an overkill and too heavy work for such a trivial task.

Another way I can think of is to expose a new API via context that can override overlayProps. Here’s a simplified code snippet for the concept:

class ContainerWithContext extends Component {
  getChildContext() {
    return {
      setOverlayProps: (overlayProps) => this.setState({overlayProps})
    };
  }
  renderOverlay() {
    return this.props.renderOverlay({
      ...this.props,
      ...this.state.overlayProps,
    });
  }
  render() {
    return (
      <View>
        {this.renderScene()}
        {this.renderOverlay()}
      </View>
    );
  }
}

const Overlay = ({title}) => <View><Text>{title}</Text></View>;

class Scene extends Component {
  static contextTypes = { setOverlayProps: PropTypes.func }

  updateNavTitle(title) {
    this.context.setOverlayProps(title);
  }
}

I can help with PR if you think this is a good idea. What are your thoughts on this?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jmurzycommented, May 9, 2017

It would be overkill to use context here. There seems to be multiple ways to approach this. But I’m not convinced this belongs within NavigationExperimental. The low level nature of NavigationExperimental enables greater abstractions to be built up in higher layers.

Also, NavigationAnimatedView is deprecated. As for NavigationTransitioner, renderScene and renderOverlay are also deprecated. NavigationTransitioner now delegates the rendering of all its children to a user provided render function. This addresses the issue discussed here. A nice side effect of this is that it allows full control over both the scene and overlay components.

That means you can just pass in a ref (to your overlay) in props to your scenes and just call a function directly on your overlay component to mutate its internal state. Let me know if this doesn’t make sense and I’ll put together an example. Oh and then there is Redux 😆

🍺

1reaction
RichardLindhoutcommented, Jul 29, 2016

@jmurzy What can I do to reference my header in e.g. my scenes?

I can’t find examples for this. I need to send scrollY positions to my header component to do animation.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to build dynamic, multi-level overlays with ... - YouTube
DYNAMIC OVERLAYS : How to build dynamic, multi-level overlays with keynote for your live streams**Filmed live in Ecamm Live FB group**Learn a ...
Read more >
Overlays - Unity - Manual
Change Overlay orientation · Right-click the handle (=) and select Horizontal or Vertical. · If the Overlay is floating or snapped in the...
Read more >
Ground then Navigate: Language-guided Navigation in Dynamic ...
Our work addresses these limitations and re-formulates the RNR approach to perform language-guided navigation in a dynamically changing environment by ...
Read more >
Choosing the right way to hide a view - Apple Developer
You can lay out all the other content as if the view doesn't exist, then update the position of the other content when...
Read more >
ThreeJS: Remove object from scene - javascript - Stack Overflow
I did small experiment. I added scene.remove(object.name); right after scene.add(object); within addEntity function and as result ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found