Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to control swipe and return to the specified page instead of the previous page(ios) #3187

Closed
ljmkimqx opened this issue Aug 17, 2018 · 14 comments

Comments

@ljmkimqx
Copy link

Version

Tell us which versions you are using:

  • react-native-router-flux ^4.0.0-beta.32 (v3 is not supported)
  • react-native v0.?.?

Expected behaviour

How to control swipe and return to the specified page instead of the previous page(ios)

@mwskwong
Copy link

mwskwong commented Aug 18, 2018

call

Actions.push("sceneKey",  {props to pass to the scene});

if you want to navigate to a specific page.

Or,

Actions.popTo("sceneKey", {props to pass to the scene});

If you want to return to a specific page.
These methods can be called in everywhere, including any kind of listeners (e.g. onPress).

take at look at here
https://github.com/aksonov/react-native-router-flux/blob/master/docs/API.md#actions

I never tried to use swipe gesture to navigate between pages, but you may also tried to implement the onBack listener.

e.g.

<Scene
   key="whateverKey"
   onBack={() => Actions.popTo("sceneKey")}
/>

@ljmkimqx
Copy link
Author

I know this, I often use these methods。But I mean when I slide back right, not when I click back。For example, A->B->C, in the C page, I hope that when I can slide right, I will return the A page instead of the B page. The reason why I have this requirement is because I don't want users to ban right slides on C pages (I don't want to use panHandlers={null}). I personally think that prohibiting right slip is not very friendly. Is there a way to solve this problem? If there is no better way, I will use panHandlers={null}. Thanks.

@mwskwong
Copy link

How about onBack? Does it work for swipe gesture as well?

@ljmkimqx
Copy link
Author

How to use onBack in the right swipe gesture, I found a lot of information not found, I hope to provide reference code, thank you.

@mwskwong
Copy link

That's the point, I'm not sure whether onBack handles the swipe gesture in iOS, but it DOES handle the back button in the nav bar AND the hardware back button in Android devices.

You may try

<Scene
   key="whateverKey"
   onBack={() => Actions.popTo("sceneKey")}
/>

@ljmkimqx
Copy link
Author

I found that ios's right-sliding back and Android's hardware back button won't trigger the onBack method.

@mwskwong
Copy link

Too bad.

For android, you can implement the backhandler

For ios though, still searching

@ljmkimqx
Copy link
Author

Yes, but thank you for answering me.

@daviscabral
Copy link
Collaborator

Hey guys, looking into the issue history I found out that onBack is really not called by hardware handlers like you can see at #2359. For now BackHandler still should be used, I'll check what can be done on that matter - feel free to provide PRs that help on that matter.

@ljmkimqx
Copy link
Author

Not a problem with BackHandler. I mean when I slide back right, not when I click back。For example, A->B->C, in the C page, I hope that when I can slide right, I will return the A page instead of the B page. The reason why I have this requirement is because I don't want users to ban right slides on C pages (I don't want to use panHandlers={null}). I personally think that prohibiting right slip is not very friendly. Is there a way to solve this problem? If there is no better way, I will use panHandlers={null}. Thanks.

@daviscabral
Copy link
Collaborator

Sorry - I misread the issue. Maybe we could work in a new event here? Not sure yet how to fix it - I am checking other issues with the Example code, and might take a look into that too.

@daviscabral daviscabral reopened this Aug 18, 2018
@ljmkimqx
Copy link
Author

Is there a way to solve this problem? thanks

@mwskwong
Copy link

mwskwong commented Aug 20, 2018

OK, I think none of the libraries will be able to provide an elegant solution, since even iOS native doesn't provide a high level api for that.
See https://stackoverflow.com/questions/50471658/overriding-back-swipe-gesture-in-uinavigationcontroller

You may try to take reference from that, override the pan gesture and call Actions.popTo() when user swipe back. You may have a look at React Native Gesture Handler, which is a high level gesture handling api with full documentation. This should make your life easier.

@ljmkimqx
Copy link
Author

thanks,I'll look at the use of React Native Gesture Handler, but I have an idea of ​​directly manipulating Actions.state to see if I can delete a page in state, so I don't have to modify the swipe gesture, but it feels so dangerous.

@aksonov aksonov closed this as completed Sep 5, 2018
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

No branches or pull requests

4 participants