mikepenz / MaterialDrawer

The flexible, easy to use, all in one drawer library for your Android project. Now brand new with material 2 design.
https://mikepenz.dev
Apache License 2.0
11.67k stars 2.05k forks source link

Navigation item selection makes all items highlighted #2495

Closed ronjunevaldoz closed 4 years ago

ronjunevaldoz commented 5 years ago

Screenshot

Screenshot_2019-09-05-18-58-46

About this issue

Details

Code

DrawerNavigationUI.setupWithNavController(drawer, navController)

mikepenz commented 5 years ago

@ronjunelopez that's interesting. The same seems to not happen in the sample app. have you compared your code?

ronjunevaldoz commented 5 years ago

@ronjunelopez that's interesting. The same seems to not happen in the sample app. have you compared your code?

Unfortunately I can't find the problem in my code. I am using custom nav host fragment to fill my navigation items. It is working fine, the problem is the bug is intermittent.

Additional details

using this reference https://github.com/mikepenz/MaterialDrawer/blob/develop/app/src/main/java/com/mikepenz/materialdrawer/app/NavControllerActivity.kt

private fun initDrawer(savedInstanceState: Bundle?) {
        val toolbar = findViewById<Toolbar>(R.id.toolbar)
        setSupportActionBar(toolbar)

        DrawerImageLoader.init(object : AbstractDrawerImageLoader() {
            override fun set(imageView: ImageView, uri: Uri, placeholder: Drawable) {
                Glide
                    .with(this@MainActivity)
                    .load(uri)
                    .centerCrop()
                    .placeholder(placeholder)
                    .apply(RequestOptions.circleCropTransform())
                    .override(128, 128)
                    .into(imageView)
            }

            override fun cancel(imageView: ImageView) {

            }
        })
        // Create the AccountHeader
        accountHeader = AccountHeaderBuilder()
            .withActivity(this)
            .withOnAccountHeaderListener(object : AccountHeader.OnAccountHeaderListener {
                override fun onProfileChanged(view: View?, profile: IProfile<*>, current: Boolean): Boolean {
                    return false
                }
            })
            .build()

        drawer = DrawerBuilder(this)
            .withRootView(R.id.drawer_container)
            .withAccountHeader(accountHeader)
            .withToolbar(toolbar)
            .withDisplayBelowStatusBar(false)
            .withActionBarDrawerToggle(true)
            .withActionBarDrawerToggleAnimated(true)
            .withDrawerLayout(R.layout.material_drawer_fits_not)
            .addDrawerItems(
                NavigationDrawerItem(
                    R.id.home_fragment,
                    PrimaryDrawerItem()
                        .withName(R.string.drawer_item_home)
                        .withIcon(FontAwesome.Icon.faw_home)
                ),
                DividerDrawerItem(),
                NavigationDrawerItem(
                    R.id.privacy_settings_fragment,
                    PrimaryDrawerItem()
                        .withName(R.string.drawer_item_privacy_settings)
                        .withIcon(FontAwesome.Icon.faw_cog)
                )
            )
            .withOnDrawerItemClickListener(object : Drawer.OnDrawerItemClickListener {
                override fun onItemClick(view: View?, position: Int, drawerItem: IDrawerItem<*>): Boolean {

                    if (drawerItem.identifier == 21L) {
                        presenter.onToolbarOptionSignOutClick()
                    }

                    return false
                }
            })
            .withSavedInstance(savedInstanceState)
            .build()
        navController = findNavController(R.id.nav_host_fragment)
        drawer.setupWithNavController(navController)
    }

Also I am using custom nav hot fragment

<fragment
                    android:id="@+id/nav_host_fragment"
                    android:name="com.ronscript.bountytips.ui.navigation.InjectingNavHostFragment"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:defaultNavHost="true"
                    app:navGraph="@navigation/navigation_graph"/>`

Can you help me provide test details, I want to test drawer items. Im gonna use espresso

@Test fun testDrawer() { onView(withId(R.id.material_drawer_layout)).perform(DrawerActions.open()) onView(withText(R.string.drawer_item_privacy_settings)).perform(click()) } This test is failing on drawer items

yogirana5557 commented 5 years ago

Getting same issue using NavController....drawer item selection & fragment backstack seems broken..need some workaround with issue.

mikepenz commented 5 years ago

Can you somehow reproduce the issue in the sample app?

ronjunevaldoz commented 5 years ago

Getting same issue using NavController....drawer item selection & fragment backstack seems broken..need some workaround with issue.

due to critical issue, It s better to use the basics from Navigation-UI.

mikepenz commented 5 years ago

we can not reproduce this in the sample app. please add more details or a full (runnable) sample app which showcases the problem

kareemzok commented 5 years ago

I m having the same issue with the highlight. When I click on any button other than the home, buttons are been highlighted and not cleared. On any button click, it should select the clicked one and cleared the others.

Capture

mikepenz commented 5 years ago

@kareemzok can you please try to reproduce this in the sample app? or adjust the sample app so it showcases your issue?

I've yet to see this problem :/

kareemzok commented 5 years ago

Hello @mikepenz ,

On the sample app it works fine but on my app not. Should we add something or its included already..

Please advise.

mikepenz commented 5 years ago

Well I need help to reproduce the problem to be able to investigate. I have not enough information to figure out what might be going on.

You can see the samples code here: https://github.com/mikepenz/MaterialDrawer/blob/develop/app/src/main/java/com/mikepenz/materialdrawer/app/NavControllerActivity.kt

perhaps you can find what you di dofferent, or adjust it to make it behave the same as in your app

kareemzok commented 5 years ago

In my app I have the item shown in the image above when I click on an item and go to new activity then go back to the home activity I open the drawer, I click on another item and then go back to the home activity I got 2 item clicked selected while the first selected one should be cleared.

As per your example, I m doing same for the java code, not kotlin but I don't have fragment, its activities

kareemzok commented 5 years ago

I was able to solve it, the issue was from my side as when I defined the item I added the identifier number for all which is 2. After I gave each item an identifier the selection work perfectly now.

mikepenz commented 4 years ago

Awesome :)