How to keep a view on the screen last visited by the user in react-native? - react-native

Suppose I have three screens in my application.
Screen A, Screen B, Screen C
Now If the user exists or if the app crashes when the user is on Screen B, I want to redirect the user directly to Screen B when the user visits the application again.
I am using react-navigation for navigating between screens.
Should I store the every Screen name visited by the user in async storage and then read that value on app launch and redirect user according to that value or is there any simple and easy way?

First and foremost thing , like i've done it in my app , but there are few catches with it. If you want to redirect to that screen if the app crashes , then it's possible by the way you suggest , that keep the name of page in async storage and then redirect upon app start.
Things to keep in mind.
1. The page which you are redirecting to should not have props dependencies from any page prior to that.
2. If the app starts, then navigation stack is cleared. So in android if user clicks on back button and if you have used this.props.navigation.goBack() it may misbehave, so keep that in mind. A fix to this would be on back button press you can do this.props.navigation.navigate('Screen').
Ive did this in login , like im storing token ,and if user opens next time it doesnt show login page , but home page. so you can do it too. Just take care of above points.

Related

How Can I open an application without login if one being opened already?

I have 5 different applications developed in react-native, I want give a better experience to my users, so if an application being logged I want the next one not to need to do login again if it is called from within the logged-in app.
How Can I do it?
There could be a lot of ways to do this, for me i use Redux for storing the Auth Token which i generate by Random string function, and i use 2 type of Stack 1) App Stack 2) Auth stack. So before that i wrap it inside a condition where it says { loginKey ?<AppStack/>:<AuthStack/> } where appStack is all the apps screens, AuthStack is login/signup screen and loginKey is redux state which stores the key one time (which we generate on successful login/signup).
Other way is as mentioned in above answer using user - login state and check if login state is true then show user your main apps screen else show user login screen.

How to manage the Authentication screens?

I have 7 screens and I am using the redux in Navigation container I did like that if
{Token===null then show 1,2,and 3rd screens else show if token get data then show 4,5,6,7 screens} my question is if the user remove application from the recent from the 6th screen.I want if the user close application from 6th screen then user should get the 6th screens. But according to my logic token has a data now and it will start from the 4th screen. Please help me what I can I do?
You can create a hashMap for storing the user's current screen and save it in asyncStorage. Later when the user reopens the application you can fetch the data and check on which screen the user was present. Then you can navigate to that screen

back doesn't work properly when navigating from notification in closed app

When I navigate from a notification in closed app i'm able to navigate to the required screen.
The app navigates to dashboard when i click on the hardware back button, but when i go back from a custom back button in toolbar header it navigates to the dashboard(as required) but instantly comes back to the same page.
Navigating from a notification:
this.props.navigation.push("screen", {
data: somedata,
})
Navigating back to dashboard:
this.props.navigation.push('Dashboard')
I also tried using ResetAction function but it had the same results.
How to solve this?
This is due to , your screen is not stack that time, for that You have firstly push that screen to stack and navigate it.
And without any operation of notification click , its default open the app first screen.
You should use this code when you press on notification tray.
this.props.navigation.navigate('XYZScreen'{itemID:id,fromWhere:"NOTIFICATION"})
this line navigate you to XYZScreen with this keys params. and there you can identify that you are coming from NOTIFICATION . so according this you can come back the any screen.
Please use this code , it helps me.
because you don't have any screen in stack
please use replace function like
this.props.navigation.replace('Dashboard')
and for hardware back press use backHander and same code in that listener function

How do I navigate to a previous page within a site opened using WebView?

I have an app that was created using React Native. In this app I have 2 screens (Home and View Web). In the View Web screen I am opening a webpage inside of a WebView. As an example, let's say the webpage being opened is Stack Overflow (Page A). My problem arises when the user clicks on a link within the Stack Overflow page (Page A), and then navigates to a different page on the site (Page B). When the user wants to go back to the original Stack Overflow page opened within the WebView (Page A), it won't let them, and instead navigates them back to the Home Screen.
Here is what I want to occur:
If the user is on Page B and they hit a back button, I want them to go back to Page A.
If the user is already on Page A and they hit the back button, I want them to go back to the Home Screen.
My question basically boils down to this: Is there a way for a single button to not only allow the user to navigate between pages inside of a WebView, but also allow for navigation between screens in the app itself? If so, please let me know how.
If you use this https://facebook.github.io/react-native/docs/webview, you can check the functions goBack();

Link to page when logging in to Facebook in xcode

So I've got my iPhone app running and what I want to achieve is when you navigate to a certain page, there is a button which, when clicked, will direct you to a certain page on Facebook. I have looked at the Facebook development pages (http://developers.facebook.com/docs/guides/mobile/) for adding Facebook and it is currently opening up Facebook when clicked and logs in successfully, although not straight away like it should.
So my problems are as follows:
1) When the button is pressed, it should bring up a page asking for permission for my application to automatically log in but it doesn't,
2) When logged in, I want the app to take the user straight to a specific page on Facebook so they can look at it and like it but i have no idea how to do this,
3) I would also need a way of exiting the Facebook view, back to the previous view the user was on inside my application.
Thanks,
Matthew