Toolbar navigation is overridden

Product: Native Android PDFTron SDK

Product Version: 9.2.1

Please give a brief summary of your issue:
PdfViewCtrlTabHostFragment2 toolbar overrides actionbar of the entire app

Please describe your issue and provide steps to reproduce it:
The action bar of the entire app is overridden when navigating back from the PdfViewCtrlTabHostFragment2.

Reproduction steps:

  1. Open the app provided.
  2. Notice that each page in the app displays the page name in the toolbar on the top without the back navigation icon.
  3. Go to the notifications bottom tab
  4. Tap on the “Go to PDFTron Viewer” button
  5. Notice that the PDFTron fragment displays its own toolbar.
  6. Hit the back button

Result: Notice that the toolbar (actionbar) of the app on every page now has the navigation back arrow + no longer indicates the name of the page it’s on

Expected Result: Navigation toolbar is not overridden and continues to show page titles correctly and if on the base level does not show the navigation icon as if in a deeper page.

Please provide a link to a minimal sample where the issue is reproducible:

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi,

I was able to reproduce the issue using your sample project.
The issue could be related to the navigation controller.

Please see the code below to hide the navigation icon and set the titles for your specific fragments below:

        navController.addOnDestinationChangedListener { controller, destination, arguments ->
            if (destination.id == R.id.navigation_home || destination.id == R.id.navigation_dashboard || destination.id == R.id.navigation_notifications) {
                binding.toolbar.navigationIcon = null
                binding.toolbar.title = destination.label
            }
        }

Please let us know if this solution works for you.

Best,
Eamon

Thank you for your quick response. I did try your suggestion and it works in the sample app but not in our huge app with dozens and dozens of pages. It seems as though the PdfViewCtrlTabHostFragment2 has completely ruined the connection of our navController with the toolbar. Adding this to our app didn’t work in our actual app:

binding.appBar.appToolbar.toolbar.navigationIcon = null
binding.appBar.appToolbar.toolbar.title = destination.label

You can see in the attached image that the toolbar still has the icon and title of the opened .pdf when navigating back. The PdfViewCtrlTabHostFragment2 even messed with the theming of the TabLayout :cry:.

This code connects the two on app start in our MainActivity using the androidx navigation framework:

appBarConfiguration =
     AppBarConfiguration(
         setOf(
                    R.id.dashboard_fragment,
                    R.id.nav_contacts,
                    R.id.nav_files
         )
)
setSupportActionBar(binding.appBar.appToolbar.toolbar)
setupActionBarWithNavController(navController, appBarConfiguration)

The AppBarConfiguration registers the root level destinations and the setupActionBarWithNavController registers the navigation.xml that the navController uses with the supportActionBar (toolbar). This automatically updates the navigation icon and title of the page in the toolbar upon navigation based on the fragment’s label determined in the navigation.xml (it’s mobile_navigation.xml in the sample app).

Something with the PDFTron Fragment code is messing with the Support Action Bar of the Activity instead of just its own fragment. This is then making the androidx navigation no longer be hooked up to the supportActionBar. We manage two very big apps with dozens of pages in both. It would be very tedious and undesirable to have to re implement a “hacky” workaround navigation just because of replacing a FrameLayout with the PdfViewCtrlTabHostFragment2 in a couple places in the app… :frowning:

Are there any other options to disable the navigation of the PdfViewCtrlTabHostFragment2? I’ve even tried using the PdfViewCtrlTabHostFragment2.TabHostListener's override fun onNavButtonPressed() but that didn’t work either :cry:

Hi,

Could you try enabling this setting in ViewerConfig:

.useSupportActionBar(false)

Please give this a try and see if it works for you.

Thanks,
Andrew

That worked for us! Thank you!

This was it!! Thank you