ismaeldivita / chip-navigation-bar

An android navigation bar widget
MIT License
890 stars 136 forks source link

menu items cannot be deselected. #35

Closed kojofosu closed 4 years ago

kojofosu commented 4 years ago

chipNavigationBar.setItemSelected(getSelectedItemId, false)

trying to use this method to deselect a particular item . But it doesn't work

ismaeldivita commented 4 years ago

Today there is no API to remove the selection only to set a new one. The second parameter on setItemSelected is to propagate or not the change to the listeners.

    /**
     * Remove the selected state from the current item and set the selected state to true
     * for the menu item with the [id]
     *
     * @param id menu item id
     * @param dispatchAction enable this action to dispatch listener events
     */
    fun setItemSelected(id: Int, dispatchAction: Boolean = true)

Tell me more about your use case. You want to remove the current selection and leave the menu without any active items?

kojofosu commented 4 years ago

Yes, i want to remove current selection and leave the menu without any active items after some seconds of selection.

So i want the items to be deselected like this....after 5 seconds like this

but then somtimes it ends up like this.. where after disabling the icon with .setItemEnabled(getSelectedItemId, false), the icon turns color gray first.

kojofosu commented 4 years ago

in case you wanted a sample code of how i'm handling it, this is it below

private void isChipItemSelected(final int getSelectedItemId) { Log.d(TAG, "chipNavigation bar isSelected : " + getSelectedItemId ); final int interval = 2000; // 2 Seconds before the item disables Handler handler = new Handler(); // init handler Runnable runnable = new Runnable() { public void run() { final int interval = 1000; // 1 Second before the item enables again for user to be able to click Handler handler = new Handler(); Runnable runnable = new Runnable() { public void run() { chipNavigationBar.setItemEnabled(getSelectedItemId, true); } }; handler.postAtTime(runnable, System.currentTimeMillis() + interval); //chip enabler handler handler.postDelayed(runnable, interval); chipNavigationBar.setItemEnabled(getSelectedItemId, false); //disabling chip item to reverse animation Log.d(TAG, "chipNavigation bar getSelectedItemId : " + chipNavigationBar.getSelectedItemId()); } }; handler.postAtTime(runnable, System.currentTimeMillis() + interval); //chip disabler handler handler.postDelayed(runnable, interval); }

ismaeldivita commented 4 years ago

Indeed, you got a very particular use case. But anyway, remove the selection sounds a very basic requirement that we should support.

I'll add this to the next release.

ismaeldivita commented 4 years ago

Closed by #36

ismaeldivita commented 4 years ago

@kojofosu https://github.com/ismaeldivita/chip-navigation-bar/releases/tag/1.3.1