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.

[Navigator] push should unmount component or have an event to listen to. Pop should remount the component it's moving to.

See original GitHub issue

Using the navigator, i’ve been trying to integrate flux with my components. The tricky thing is, i don’t have an event or method to hook into for removing the event listener. I’ve managed to hack around it a bit by removing the listener when i push the route. Likewise from there passing a component as a back button that has this top level component in scope:

class ProjectList extends Component {
  _onChange(project) {
    this._unsub();
    this.props.navigator.push({
      component: Project,
      props: { project: project },
      navigationBar: (<NavigationBar
        title={project.title}
        titleColor="#000000"
        style={appStyles.navigator}
        customPrev={<CustomPrev onPress={() => {
          this.props.navigator.pop();
          this._sub();
        }} />}
      />)
    });
  }
}

Which is rather ugly in my opinion. The this inside the onPress is the instance of the ProjectList

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
brentvatnecommented, Feb 13, 2016

@pukhalski - man, we are doing our best here, passive aggressive comments aren’t helpful or appreciated 😦

Yes the issue that this was created for has been fixed: “push should unmount component or have an event to listen to. Pop should remount the component it’s moving to.” – there is an event to listen to, navigationContext.addListener('didfocus') and willfocus.

There is actually a good reason for keeping these views mounted in React – on iOS for example you want to be able to use the swipe gesture to go back to a previous scene without having to re-render that scene (potentially expensive to do) and lose its state (bad ux).


A memory usage optimization for ListView is to automatically apply removeClippedSubviews, which will unmount the native views outside of the ScrollView content container clip rect (which will free up memory in the case of images), however there are no such optimizations for Navigator at the moment. See this discussion for details and a workaround: https://www.facebook.com/groups/react.native.community/permalink/710415322427382/

See @deanmcpherson’s comment at the end:

I also played wiith unmounting entire navigator views , but found that it had sketchy performance for me when navigating back quickly as it had to remount whole views on the fly (probably only an issue because people tend to navigate back quicker than they go forward).

2reactions
pukhalskicommented, Feb 13, 2016

Is it fixed? Or just closed because it’s okay to have a memory leak within an app?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Navigator] push should unmount component or have an event to ...
[Navigator] push should unmount component or have an event to listen to. Pop should remount the component it's moving to. closed. Brent Vatne....
Read more >
Navigation lifecycle
React Navigation emits events to screen components that subscribe to them. We can listen to focus and blur events to know when a...
Read more >
Handling Mounting And Unmounting Of Navigation Routes In ...
Let's look at how to mount and unmount navigation stack based on a met condition in React Native. In this article, we are...
Read more >
Component does not remount when route parameters change
This will remount the page when the URL changes, forcing all the components in the page to be created and mounted again, not...
Read more >
Lifecycle hooks are not enough with React Navigation in ...
When the Profile screen is unmounted, we should stop listening to events. That is why we remove the event listener by returning the...
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