react-navigation: have the same state as a previous route, but act as a push?












1















Say I have Screen 1 and Screen 2. I navigate from Screen 1 to Screen 2 by pushing. So Screen 1 is still there, and its state is unchanged. But, I want to be able to navigate to a third screen, Screen 3, that has EXACTLY the same state as Screen 1 (a copy), but acts like a push.



Pushing from Screen 1 to Screen 2 gives me a card transition, but I basically want to push from Screen 2 to Screen 3 (another card transition), but have Screen 3 to have the same state as Screen 1, like scrolling is the same, data is the same, etc.



EDIT: Unfortunately, I cannot upload any gifs for clarification because many of them are too large. An example would be from the Reddit app: moving from the tabular view to viewing a post (where the tab view disappears), but then when you click on the subreddit's name, it takes you (with a push animation) to another tab view, but it's the same one.



EDIT 2: Here is a link of a screen recording of what I want.




  1. So the first screen shows me scrolling down to a certain area. (tabular view) - Screen 1

  2. Then there's a card navigation to a "View Post Screen", where you can see comments, etc. (no tabs) - Screen 2


  3. Then I clicked on r/aww, which navigates with a card transition to the subreddit page. (tabular view) - Screen 3


  4. The tab for Screen 3 is scrolled to the same place as I scrolled in Screen 1. This is what I meant by "same state".


Pushing another route of the same name doesn't work, because everything is set back to default, and would be bad for user experience. Going back wouldn't work because it would show a card "go back" transition from Screen 2 to Screen 3 - a card "push" transition is more natural.










share|improve this question

























  • This sounds like an unintuitive control flow. Is it possible to pop back to Screen 1, but substitute the push animation for the default pop animation?

    – NRitH
    Nov 20 '18 at 3:34











  • That's what I was thinking too, but I'm not really sure how. Check my edit for an example if you need clarification?

    – Michael Hsu
    Nov 20 '18 at 3:51











  • You could try passing the state of Screen1 as navigation props/params. This might help: stackoverflow.com/questions/50372616/…

    – Uzair A.
    Nov 20 '18 at 3:53











  • @NRitH that also would not work, because if I pop back to Screen 1, then I cannot go back from Screen 3 to Screen 2 to Screen 1.

    – Michael Hsu
    Nov 20 '18 at 3:55











  • Your video example doesn't have two screens that are exactly the same though, so I'm confused about that. Why do you want screen three (single subreddit view?) scrolled to the same place as screen one (list of subreddits)?

    – Noah Allen
    Nov 20 '18 at 16:05
















1















Say I have Screen 1 and Screen 2. I navigate from Screen 1 to Screen 2 by pushing. So Screen 1 is still there, and its state is unchanged. But, I want to be able to navigate to a third screen, Screen 3, that has EXACTLY the same state as Screen 1 (a copy), but acts like a push.



Pushing from Screen 1 to Screen 2 gives me a card transition, but I basically want to push from Screen 2 to Screen 3 (another card transition), but have Screen 3 to have the same state as Screen 1, like scrolling is the same, data is the same, etc.



EDIT: Unfortunately, I cannot upload any gifs for clarification because many of them are too large. An example would be from the Reddit app: moving from the tabular view to viewing a post (where the tab view disappears), but then when you click on the subreddit's name, it takes you (with a push animation) to another tab view, but it's the same one.



EDIT 2: Here is a link of a screen recording of what I want.




  1. So the first screen shows me scrolling down to a certain area. (tabular view) - Screen 1

  2. Then there's a card navigation to a "View Post Screen", where you can see comments, etc. (no tabs) - Screen 2


  3. Then I clicked on r/aww, which navigates with a card transition to the subreddit page. (tabular view) - Screen 3


  4. The tab for Screen 3 is scrolled to the same place as I scrolled in Screen 1. This is what I meant by "same state".


Pushing another route of the same name doesn't work, because everything is set back to default, and would be bad for user experience. Going back wouldn't work because it would show a card "go back" transition from Screen 2 to Screen 3 - a card "push" transition is more natural.










share|improve this question

























  • This sounds like an unintuitive control flow. Is it possible to pop back to Screen 1, but substitute the push animation for the default pop animation?

    – NRitH
    Nov 20 '18 at 3:34











  • That's what I was thinking too, but I'm not really sure how. Check my edit for an example if you need clarification?

    – Michael Hsu
    Nov 20 '18 at 3:51











  • You could try passing the state of Screen1 as navigation props/params. This might help: stackoverflow.com/questions/50372616/…

    – Uzair A.
    Nov 20 '18 at 3:53











  • @NRitH that also would not work, because if I pop back to Screen 1, then I cannot go back from Screen 3 to Screen 2 to Screen 1.

    – Michael Hsu
    Nov 20 '18 at 3:55











  • Your video example doesn't have two screens that are exactly the same though, so I'm confused about that. Why do you want screen three (single subreddit view?) scrolled to the same place as screen one (list of subreddits)?

    – Noah Allen
    Nov 20 '18 at 16:05














1












1








1








Say I have Screen 1 and Screen 2. I navigate from Screen 1 to Screen 2 by pushing. So Screen 1 is still there, and its state is unchanged. But, I want to be able to navigate to a third screen, Screen 3, that has EXACTLY the same state as Screen 1 (a copy), but acts like a push.



Pushing from Screen 1 to Screen 2 gives me a card transition, but I basically want to push from Screen 2 to Screen 3 (another card transition), but have Screen 3 to have the same state as Screen 1, like scrolling is the same, data is the same, etc.



EDIT: Unfortunately, I cannot upload any gifs for clarification because many of them are too large. An example would be from the Reddit app: moving from the tabular view to viewing a post (where the tab view disappears), but then when you click on the subreddit's name, it takes you (with a push animation) to another tab view, but it's the same one.



EDIT 2: Here is a link of a screen recording of what I want.




  1. So the first screen shows me scrolling down to a certain area. (tabular view) - Screen 1

  2. Then there's a card navigation to a "View Post Screen", where you can see comments, etc. (no tabs) - Screen 2


  3. Then I clicked on r/aww, which navigates with a card transition to the subreddit page. (tabular view) - Screen 3


  4. The tab for Screen 3 is scrolled to the same place as I scrolled in Screen 1. This is what I meant by "same state".


Pushing another route of the same name doesn't work, because everything is set back to default, and would be bad for user experience. Going back wouldn't work because it would show a card "go back" transition from Screen 2 to Screen 3 - a card "push" transition is more natural.










share|improve this question
















Say I have Screen 1 and Screen 2. I navigate from Screen 1 to Screen 2 by pushing. So Screen 1 is still there, and its state is unchanged. But, I want to be able to navigate to a third screen, Screen 3, that has EXACTLY the same state as Screen 1 (a copy), but acts like a push.



Pushing from Screen 1 to Screen 2 gives me a card transition, but I basically want to push from Screen 2 to Screen 3 (another card transition), but have Screen 3 to have the same state as Screen 1, like scrolling is the same, data is the same, etc.



EDIT: Unfortunately, I cannot upload any gifs for clarification because many of them are too large. An example would be from the Reddit app: moving from the tabular view to viewing a post (where the tab view disappears), but then when you click on the subreddit's name, it takes you (with a push animation) to another tab view, but it's the same one.



EDIT 2: Here is a link of a screen recording of what I want.




  1. So the first screen shows me scrolling down to a certain area. (tabular view) - Screen 1

  2. Then there's a card navigation to a "View Post Screen", where you can see comments, etc. (no tabs) - Screen 2


  3. Then I clicked on r/aww, which navigates with a card transition to the subreddit page. (tabular view) - Screen 3


  4. The tab for Screen 3 is scrolled to the same place as I scrolled in Screen 1. This is what I meant by "same state".


Pushing another route of the same name doesn't work, because everything is set back to default, and would be bad for user experience. Going back wouldn't work because it would show a card "go back" transition from Screen 2 to Screen 3 - a card "push" transition is more natural.







react-native react-navigation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 6:49







Michael Hsu

















asked Nov 20 '18 at 3:32









Michael HsuMichael Hsu

380212




380212













  • This sounds like an unintuitive control flow. Is it possible to pop back to Screen 1, but substitute the push animation for the default pop animation?

    – NRitH
    Nov 20 '18 at 3:34











  • That's what I was thinking too, but I'm not really sure how. Check my edit for an example if you need clarification?

    – Michael Hsu
    Nov 20 '18 at 3:51











  • You could try passing the state of Screen1 as navigation props/params. This might help: stackoverflow.com/questions/50372616/…

    – Uzair A.
    Nov 20 '18 at 3:53











  • @NRitH that also would not work, because if I pop back to Screen 1, then I cannot go back from Screen 3 to Screen 2 to Screen 1.

    – Michael Hsu
    Nov 20 '18 at 3:55











  • Your video example doesn't have two screens that are exactly the same though, so I'm confused about that. Why do you want screen three (single subreddit view?) scrolled to the same place as screen one (list of subreddits)?

    – Noah Allen
    Nov 20 '18 at 16:05



















  • This sounds like an unintuitive control flow. Is it possible to pop back to Screen 1, but substitute the push animation for the default pop animation?

    – NRitH
    Nov 20 '18 at 3:34











  • That's what I was thinking too, but I'm not really sure how. Check my edit for an example if you need clarification?

    – Michael Hsu
    Nov 20 '18 at 3:51











  • You could try passing the state of Screen1 as navigation props/params. This might help: stackoverflow.com/questions/50372616/…

    – Uzair A.
    Nov 20 '18 at 3:53











  • @NRitH that also would not work, because if I pop back to Screen 1, then I cannot go back from Screen 3 to Screen 2 to Screen 1.

    – Michael Hsu
    Nov 20 '18 at 3:55











  • Your video example doesn't have two screens that are exactly the same though, so I'm confused about that. Why do you want screen three (single subreddit view?) scrolled to the same place as screen one (list of subreddits)?

    – Noah Allen
    Nov 20 '18 at 16:05

















This sounds like an unintuitive control flow. Is it possible to pop back to Screen 1, but substitute the push animation for the default pop animation?

– NRitH
Nov 20 '18 at 3:34





This sounds like an unintuitive control flow. Is it possible to pop back to Screen 1, but substitute the push animation for the default pop animation?

– NRitH
Nov 20 '18 at 3:34













That's what I was thinking too, but I'm not really sure how. Check my edit for an example if you need clarification?

– Michael Hsu
Nov 20 '18 at 3:51





That's what I was thinking too, but I'm not really sure how. Check my edit for an example if you need clarification?

– Michael Hsu
Nov 20 '18 at 3:51













You could try passing the state of Screen1 as navigation props/params. This might help: stackoverflow.com/questions/50372616/…

– Uzair A.
Nov 20 '18 at 3:53





You could try passing the state of Screen1 as navigation props/params. This might help: stackoverflow.com/questions/50372616/…

– Uzair A.
Nov 20 '18 at 3:53













@NRitH that also would not work, because if I pop back to Screen 1, then I cannot go back from Screen 3 to Screen 2 to Screen 1.

– Michael Hsu
Nov 20 '18 at 3:55





@NRitH that also would not work, because if I pop back to Screen 1, then I cannot go back from Screen 3 to Screen 2 to Screen 1.

– Michael Hsu
Nov 20 '18 at 3:55













Your video example doesn't have two screens that are exactly the same though, so I'm confused about that. Why do you want screen three (single subreddit view?) scrolled to the same place as screen one (list of subreddits)?

– Noah Allen
Nov 20 '18 at 16:05





Your video example doesn't have two screens that are exactly the same though, so I'm confused about that. Why do you want screen three (single subreddit view?) scrolled to the same place as screen one (list of subreddits)?

– Noah Allen
Nov 20 '18 at 16:05












2 Answers
2






active

oldest

votes


















1














In react-navigation you can navigate to unlimited - in theory - of same screen. If you wish to change the contents of the screen you can use navigation parameters. You can think instagram app for example.



User(me) -> Followers -> User(Alice) -> Followers -> User(Bob) -> Followers -> User(John)



const Navigator = createStackNavigator({
Followers: { screen: Followers },
User: { screen: Profile },
});

/...
this.props.navigation.navigate('User', { user: 'me' });
this.props.navigation.navigate('Followers', { user: 'me' });
this.props.navigation.navigate('User', { user: 'Alice' });
this.props.navigation.navigate('Followers', { user: 'Alice' });
this.props.navigation.navigate('User', { user: 'Bob' });
this.props.navigation.navigate('Followers', { user: 'Bob' });
this.props.navigation.navigate('User', { user: 'John' });





share|improve this answer
























  • There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

    – Michael Hsu
    Nov 20 '18 at 6:49



















0














My understanding of your use case scenario is that you want to preserve the styling and structure of a component across different screens. I have two takeaways here:




  • If the two screens (Screen1 and Screen3) are exactly the same, then why would you want a duplicate in the first place? Why not show the Screen1 again to keep your stack size small? In your example: User is on Screen1 which is subreddit's homepage. Then they click on a post link which takes them to Screen2. Again, when user clicks on the link to subreddit's homepage, they are not opening a new screen, they are simply going back to the original Screen1.


  • If there are slight differences between the two screens, your could simply employ component re-use. Like, if there are two subreddits r/android and r/reactnative, you'll have a single component for both of them: <SubRedditComponent> but their data and styling would be different.







share|improve this answer


























  • There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

    – Michael Hsu
    Nov 20 '18 at 6:50











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385826%2freact-navigation-have-the-same-state-as-a-previous-route-but-act-as-a-push%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














In react-navigation you can navigate to unlimited - in theory - of same screen. If you wish to change the contents of the screen you can use navigation parameters. You can think instagram app for example.



User(me) -> Followers -> User(Alice) -> Followers -> User(Bob) -> Followers -> User(John)



const Navigator = createStackNavigator({
Followers: { screen: Followers },
User: { screen: Profile },
});

/...
this.props.navigation.navigate('User', { user: 'me' });
this.props.navigation.navigate('Followers', { user: 'me' });
this.props.navigation.navigate('User', { user: 'Alice' });
this.props.navigation.navigate('Followers', { user: 'Alice' });
this.props.navigation.navigate('User', { user: 'Bob' });
this.props.navigation.navigate('Followers', { user: 'Bob' });
this.props.navigation.navigate('User', { user: 'John' });





share|improve this answer
























  • There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

    – Michael Hsu
    Nov 20 '18 at 6:49
















1














In react-navigation you can navigate to unlimited - in theory - of same screen. If you wish to change the contents of the screen you can use navigation parameters. You can think instagram app for example.



User(me) -> Followers -> User(Alice) -> Followers -> User(Bob) -> Followers -> User(John)



const Navigator = createStackNavigator({
Followers: { screen: Followers },
User: { screen: Profile },
});

/...
this.props.navigation.navigate('User', { user: 'me' });
this.props.navigation.navigate('Followers', { user: 'me' });
this.props.navigation.navigate('User', { user: 'Alice' });
this.props.navigation.navigate('Followers', { user: 'Alice' });
this.props.navigation.navigate('User', { user: 'Bob' });
this.props.navigation.navigate('Followers', { user: 'Bob' });
this.props.navigation.navigate('User', { user: 'John' });





share|improve this answer
























  • There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

    – Michael Hsu
    Nov 20 '18 at 6:49














1












1








1







In react-navigation you can navigate to unlimited - in theory - of same screen. If you wish to change the contents of the screen you can use navigation parameters. You can think instagram app for example.



User(me) -> Followers -> User(Alice) -> Followers -> User(Bob) -> Followers -> User(John)



const Navigator = createStackNavigator({
Followers: { screen: Followers },
User: { screen: Profile },
});

/...
this.props.navigation.navigate('User', { user: 'me' });
this.props.navigation.navigate('Followers', { user: 'me' });
this.props.navigation.navigate('User', { user: 'Alice' });
this.props.navigation.navigate('Followers', { user: 'Alice' });
this.props.navigation.navigate('User', { user: 'Bob' });
this.props.navigation.navigate('Followers', { user: 'Bob' });
this.props.navigation.navigate('User', { user: 'John' });





share|improve this answer













In react-navigation you can navigate to unlimited - in theory - of same screen. If you wish to change the contents of the screen you can use navigation parameters. You can think instagram app for example.



User(me) -> Followers -> User(Alice) -> Followers -> User(Bob) -> Followers -> User(John)



const Navigator = createStackNavigator({
Followers: { screen: Followers },
User: { screen: Profile },
});

/...
this.props.navigation.navigate('User', { user: 'me' });
this.props.navigation.navigate('Followers', { user: 'me' });
this.props.navigation.navigate('User', { user: 'Alice' });
this.props.navigation.navigate('Followers', { user: 'Alice' });
this.props.navigation.navigate('User', { user: 'Bob' });
this.props.navigation.navigate('Followers', { user: 'Bob' });
this.props.navigation.navigate('User', { user: 'John' });






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 4:17









bennygenelbennygenel

12.7k32548




12.7k32548













  • There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

    – Michael Hsu
    Nov 20 '18 at 6:49



















  • There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

    – Michael Hsu
    Nov 20 '18 at 6:49

















There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

– Michael Hsu
Nov 20 '18 at 6:49





There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

– Michael Hsu
Nov 20 '18 at 6:49













0














My understanding of your use case scenario is that you want to preserve the styling and structure of a component across different screens. I have two takeaways here:




  • If the two screens (Screen1 and Screen3) are exactly the same, then why would you want a duplicate in the first place? Why not show the Screen1 again to keep your stack size small? In your example: User is on Screen1 which is subreddit's homepage. Then they click on a post link which takes them to Screen2. Again, when user clicks on the link to subreddit's homepage, they are not opening a new screen, they are simply going back to the original Screen1.


  • If there are slight differences between the two screens, your could simply employ component re-use. Like, if there are two subreddits r/android and r/reactnative, you'll have a single component for both of them: <SubRedditComponent> but their data and styling would be different.







share|improve this answer


























  • There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

    – Michael Hsu
    Nov 20 '18 at 6:50
















0














My understanding of your use case scenario is that you want to preserve the styling and structure of a component across different screens. I have two takeaways here:




  • If the two screens (Screen1 and Screen3) are exactly the same, then why would you want a duplicate in the first place? Why not show the Screen1 again to keep your stack size small? In your example: User is on Screen1 which is subreddit's homepage. Then they click on a post link which takes them to Screen2. Again, when user clicks on the link to subreddit's homepage, they are not opening a new screen, they are simply going back to the original Screen1.


  • If there are slight differences between the two screens, your could simply employ component re-use. Like, if there are two subreddits r/android and r/reactnative, you'll have a single component for both of them: <SubRedditComponent> but their data and styling would be different.







share|improve this answer


























  • There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

    – Michael Hsu
    Nov 20 '18 at 6:50














0












0








0







My understanding of your use case scenario is that you want to preserve the styling and structure of a component across different screens. I have two takeaways here:




  • If the two screens (Screen1 and Screen3) are exactly the same, then why would you want a duplicate in the first place? Why not show the Screen1 again to keep your stack size small? In your example: User is on Screen1 which is subreddit's homepage. Then they click on a post link which takes them to Screen2. Again, when user clicks on the link to subreddit's homepage, they are not opening a new screen, they are simply going back to the original Screen1.


  • If there are slight differences between the two screens, your could simply employ component re-use. Like, if there are two subreddits r/android and r/reactnative, you'll have a single component for both of them: <SubRedditComponent> but their data and styling would be different.







share|improve this answer















My understanding of your use case scenario is that you want to preserve the styling and structure of a component across different screens. I have two takeaways here:




  • If the two screens (Screen1 and Screen3) are exactly the same, then why would you want a duplicate in the first place? Why not show the Screen1 again to keep your stack size small? In your example: User is on Screen1 which is subreddit's homepage. Then they click on a post link which takes them to Screen2. Again, when user clicks on the link to subreddit's homepage, they are not opening a new screen, they are simply going back to the original Screen1.


  • If there are slight differences between the two screens, your could simply employ component re-use. Like, if there are two subreddits r/android and r/reactnative, you'll have a single component for both of them: <SubRedditComponent> but their data and styling would be different.








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 '18 at 5:01

























answered Nov 20 '18 at 4:21









Uzair A.Uzair A.

6121521




6121521













  • There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

    – Michael Hsu
    Nov 20 '18 at 6:50



















  • There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

    – Michael Hsu
    Nov 20 '18 at 6:50

















There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

– Michael Hsu
Nov 20 '18 at 6:50





There's some confusion as to what I'm asking about. I posted a google drive link to a screen recording. I hope this helps understand my problem?

– Michael Hsu
Nov 20 '18 at 6:50


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53385826%2freact-navigation-have-the-same-state-as-a-previous-route-but-act-as-a-push%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini