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.

Add callbacks to Navigator methods (push / pop / etc)

See original GitHub issue

Not sure if this is something you’re interested in adding, but I think it would be useful to be able to pass a callback to Navigator methods that would fire when the transition (as defined by the sceneConfig) has completed.

Use case

I’m working on an app with a pin entry screen that is displayed whenever you start a workflow on the Home screen. I want the pin entry scene to float up from the bottom of the screen, then when it’s dismissed, I want the next scene to enter from the right after the pin screen has animated out.

Example

(user taps a button)

navigator.push({
  scene: PinEntryScene,
  sceneConfig: FloatFromBottom,
  props: { nextScene: WorkflowScene }
});

(user enters pin)

navigator.pop(() => {
  navigator.push({
    scene: this.props.nextScene,
    sceneConfig: HorizontalSwipeJump
  });
});

Workaround

It’s awkward to use the navigationContext events to manage this, so at the moment I’m wrapping my next scene transition in a setTimeout which is quite brittle (it relies on knowing the sceneConfig used to transition to a scene, which will not always be possible)

navigator.pop();
setTimeout(() => {
  navigator.push({
    scene: this.props.nextScene,
    sceneConfig: HorizontalSwipeJump
  });
}, 500);

…or is there a better way to achieve this that I’ve missed?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hulvei3commented, Dec 28, 2016

For me the problem was that the InteractionManager wasn’t highlighted enough in the docs 😃 If you just need to wait for animations to finish use this. http://facebook.github.io/react-native/releases/0.39/docs/timers.html

0reactions
Kudocommented, Nov 27, 2015

Are there any updates for change/willchange or willblur/didblur event? I didn’t see these events in current master branch code. I would like to have willblur/didblur and I can help for a PR but not sure if this will fit React Native’s road map.

My use case is for react-redux. Currently I use Navigator with react-redux, unfortunately, Navigator.push() will keep old components and these old/hidden components also listen for new actions. When doing Navigator.pop(), the old component was be changed due to previous action changes.

What I am thinking is to add Component.tryUnsubscribe() in willblur and Component.trySubscribe() in didfocus.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Navigation events
You can listen to various events emitted by React Navigation to get ... The addListener method takes 2 arguments: type of the event,...
Read more >
Navigator.pop() callback? - flutter - Stack Overflow
Im using it for showModalBottomSheet(useRootNavigator: true) then Navigator.pop() to close the bottom sheet, then push a new route. code:
Read more >
Flutter: Push, Pop, Push. Overview of Navigator methods in…
Overview of Navigator methods in Flutter and describing the implementation and a use-case for each push and pop method.
Read more >
Flutter navigator.pop callback - YouTube
Flutter navigate to new page navigator. push Example. Flutter navigator. pop callback example. Flutter Route and Navigator example.
Read more >
Callbacks and Error Handling - Actipro WPF Controls Docs
Push and related Pop methods are available for this scenario. Normally reading ahead through tokens in a can-match callback would consume the token, ......
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 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