hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
423 stars 51 forks source link

Multiple sequential modals only work when replaced #219

Closed svantepolk closed 2 years ago

svantepolk commented 2 years ago

Dismissing a TurboNavPresentationContext.MODAL visit by performing a DEFAULT context visit breaks the app when there's more than 1 MODAL context visit in the backstack.

Suppose we have this configuration.json:

{
  {
    "patterns": [ ".*" ],
      "properties": {
        "context": "default",
        "uri": "turbo://fragment/web"
      }
  },
  {
    "patterns": [ "/tasks/wizard/" ],
    "properties": { "context": "modal" }
  }
}

This sequence of visits works as expected:

/
/tasks
/tasks/wizard/step-1
/tasks

However, if we have this sequence of visits...

/
/tasks
/tasks/wizard/step-1
/tasks/wizard/step-2
/tasks

The app doesn't properly replace the underlying /tasks fragment. What seems to happen instead is that it tries to go back to /tasks/wizard/step-1 and breaks.

Here's a video for demonstration:

https://user-images.githubusercontent.com/25386350/156970441-ed353ecf-9d9c-4126-a847-aeadb48d31dc.mov

That can be 'fixed' it by adding this rule:

{
  "patterns": [ "/tasks/wizard/step-2$" ],
  "properties": { "presentation": "replace" }
}

Unfortunately, this means that if you're in a multi-step form, and you remember something you needed to change in the previous form, you'll then have to close the entire form and start again.

svantepolk commented 2 years ago

Looking into the navigation code, I noticed that the behaviour achieved with subsequent wizard steps performing a replace is totally independent of presentation context, as per TurboNavRule:64