hotwired / turbo-android

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

Left toolbar icon is disappeared after dialog dismiss #192

Closed shkim closed 2 years ago

shkim commented 2 years ago

I need a hamburger button on left side of toolbar, but it is disappeared when a modal page is dismissed.

These are the reproduction steps to modify the "demo" project:

  1. Edit ~/turbo-android/demo/src/main/kotlin/dev/hotwire/turbo/demo/features/web/WebHomeFragment.kt add the following method below onCreateView (two imports will be automaticaly added by IDE)

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
    
        val toolbar = view.findViewById<Toolbar>(R.id.toolbar)
        toolbar.navigationIcon = ContextCompat.getDrawable(view.context, R.drawable.ic_close) // hamburger icon here
    }
  2. Run and Click "Load a webpage modally"

image

  1. Dismiss the modal, then the X button will be disappeared.

2b. I'm not sure but with my all devices and emulator, after I click the close icon, the web page changed to non-interactive mode; I could not scroll or click any links on the page. Is it an expected behavior?

jayohms commented 2 years ago

Do you have all the latest commits from the main branch? There was a bug that was fixed a couple weeks ago that would cause webpages to become stuck after visiting modals. I'm not able to replicate the issues you're describing.

I'm seeing the ic_close icon always displayed on the WebHomeFragment using your code - even after visiting modals.

shkim commented 2 years ago

I think I'm using the latest commit.

$ git log
commit 947c18884c9615c5e302164cde3129ec1725fa93 (HEAD -> main, tag: 7.0.0-rc1, origin/main, origin/HEAD)
Merge: 42b4883 b836b8d
Author: Jay Ohms <jay.ohms@gmail.com>
Date:   Tue Sep 7 21:19:06 2021 -0400

    Merge pull request #175 from hotwired/same-page-anchors

    Support same-page anchor scrolling
...

$ git status
On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   .idea/codeStyles/Project.xml
    modified:   demo/src/main/kotlin/dev/hotwire/turbo/demo/features/web/WebHomeFragment.kt

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    .idea/gradle.properties
    demo/.idea/
jayohms commented 2 years ago

Can you provide a screen recording of the behavior you're seeing in the demo app?

shkim commented 2 years ago

https://user-images.githubusercontent.com/1094548/135634196-f04848ac-e9ad-4fb7-ae3f-d34b4e00b4a7.mov

jayohms commented 2 years ago

Thanks, that's helpful. Here's how you can work around these issues:

@TurboNavGraphDestination(uri = "turbo://fragment/web/home")
class WebHomeFragment : WebFragment() {

    // ...

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        configureToolbar()
    }

    override fun shouldObserveTitleChanges(): Boolean {
        return false
    }

    override fun toolbarForNavigation(): Toolbar? {
        // Disable the automatic toolbar navigation configuration
        return null
    }

    private fun configureToolbar() {
        view?.findViewById<Toolbar>(R.id.toolbar)?.apply {
            navigationIcon = ContextCompat.getDrawable(requireContext(), R.drawable.ic_close)
            setNavigationOnClickListener {
                // Custom code here to open menu
                Toast.makeText(requireContext(), "Display menu", Toast.LENGTH_LONG).show()
            }
        }
    }
}

This works great from my end, so let me know if that doesn't address everything!