hotwired / turbo-android

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

Back button not seen unless the first fragment is different than second #188

Closed jaysson closed 6 months ago

jaysson commented 2 years ago

The initial URL's fragment has to be different than other screens that are pushed. Otherwise back button is not available in action bar.

The device back button does navigate the app back. It's only the action bar that has the issue.

Repo/commit which reproduces the issue: https://github.com/jaysson/turbo-android/commit/ebb8b4d9d780ea05dd71bfabf7c2b8cb730c4208. Basically it removes the turbo://fragment/web/home fragment so that turbo://fragment/web fragment is used for everything.

Context: I am trying to use Turbo native in an existing app. Other activities can navigate to turbo activity with arbitrary URLs. That means I cannot have an entry point fragment.

jayohms commented 2 years ago

@jaysson This is a known issue I've seen with Google's navigation components NavigationUI.setupWithNavController() implementation, which the turbo-android library uses.

One option would be to manually display a back arrow icon in the Fragment like:

toolbarForNavigation()?.navigationIcon = ContextCompat.getDrawable(view.context, R.drawable.ic_arrow)

You can also customize the behavior for the toolbar arrow in your Fragment:

toolbarForNavigation()?.setNavigationOnClickListener {
    // Your implementation, such as:
    navigateUp()

    // or finish the activity:
    requireActivity().finish()
}