[Navigator] push should unmount component or have an event to listen to. Pop should remount the component it's moving to.
See original GitHub issueUsing 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:
- Created 8 years ago
- Reactions:1
- Comments:12 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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')
andwillfocus
.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:
Is it fixed? Or just closed because it’s okay to have a memory leak within an app?