Skip to content

Support for history stack entry replace #6283

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

Open
bundyo opened this issue Sep 20, 2018 · 8 comments
Open

Support for history stack entry replace #6283

bundyo opened this issue Sep 20, 2018 · 8 comments

Comments

@bundyo
Copy link
Contributor

bundyo commented Sep 20, 2018

Did you verify this is a real problem by searching the NativeScript Forum and the other open issues in this repo?

Yes

Tell us about the problem

While developing an app, I noticed that {N} doesn't support history replacement as the one the History API has in Web. backstackVisible: false comes close, but has one subtle difference, which I will describe now:

                             navigate()
        +---------------------------------------------------+
        |             backstackVisible: false               |
        |                                                   |
+-------v------+        goBack()         +---------------+  |
|              <-------------------------+ Cancel   Done +--+
+--------------+                         +---------------+
|              |        navigate()       |               |
| Details Page +------------------------->   Edit Page   |
|              | backstackVisible: false |               |
+--------------+                         +---------------+

If we use backstackVisible: false, the edit page doesn't enter the stack and goBack() navigates properly on canceling Edit page. However, if we want to navigate to the Details page on Done (to indicate with forward transition, that the changes were stored), the new Details Page is not replacing the old one, and using goBack() in it will navigate it to its previous stack copy - from itself to itself.

In the Web History API, replace is effectively replacing the page in the stack, so going back will just navigate to the previous one in the stack - the correct one.

Using clearHistory in this case is not okay, as we have previous pages in the stack, which we will lose.

Which platform(s) does your issue occur on?

iOS/Android/Both


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@MartoYankov
Copy link
Contributor

MartoYankov commented Sep 20, 2018

I'm all for this feature. Just to add that currently, there are two alternative ways to do this:

  1. Use goBack() on Done.
  2. Use a Modal View for the Edit page.

Both have the added benefit of not recreating the details page. This can be very important if you have some heavy UI there.

@bundyo
Copy link
Contributor Author

bundyo commented Sep 20, 2018

Yes, I'm aware of both possibilities, but each is a bit different.

  1. I think with goBack() you can't pass transition. Also you can be 2-3 screens away (though you can pass the old entry to goBack). There might be different scenarios that I can't think of currently.
  2. True, but I'm not sure you can control the animation with a Modal.

If we can pass transition with goBack() - that will be a good workaround that won't re-create the View.

@msaelices
Copy link
Contributor

msaelices commented Mar 8, 2019

This would be amazing also for fixing HMR issues with Vue. Right now there is a weird navigation issue nativescript-vue/nativescript-vue#388 caused because when the current page code is changed, there is a navigation action triggered to the same page. In order to fix it, I did a dirty hack for replacing the latest entry in the navigation stack https://github.com/nativescript-vue/nativescript-vue/pull/444/files#diff-c7066f3e92bcad6c8156ffe597acaa48R117

If there was some way to replace the last entry in the navigation stack in the NS API, the developer experience using HMR would be a lot better and my fix would look nicer :)

@jlooper
Copy link

jlooper commented Mar 8, 2019

If it would help HMR on Vue, it would be a big plus, and wonder if it would help on our Vue-Router issue?

@msaelices
Copy link
Contributor

@jlooper it probably would help on that too.

@bundyo
Copy link
Contributor Author

bundyo commented Mar 8, 2019

Yeah, I logged it around that time.

@MartoYankov
Copy link
Contributor

The problem with implementing this as a public API lies with transitions. We should be able to not simply replace a navigation entry in the history stack, but also replace a transition on the previous entry, so that when you go back, the transition is fluid. This would require lots of testing against lots of scenarios (we also added nesting navigations recently). As far as our research showed a while back, the native frameworks don't support "replace" out of the box.

@msaelices
Copy link
Contributor

@MartoYankov I guess you already read it, but if not, please read my comment here: nativescript-vue/nativescript-vue#388 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants