-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Implement fixed mode for Bottom Navigation Bar Android #4003
Conversation
I'm not sure about this try/catch:
|
According to this StackOverflow question, using reflection will cause problems when ProGaurd is enabled. It will strip the internal non-public fields of the BottomNavigationView and this fix will not work. If this gets merged, this should be atleast documented somewhere. |
Thank you @AmrAlSayed0 ! |
if (menuView == null) | ||
return; | ||
|
||
var shiftMode = menuView.Class.GetDeclaredField("mShiftingMode"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if this was obfuscated by Proguard? we might need to add some rules to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing to note about this is that with API 28 google is grey listing reflection calls
https://developer.android.com/about/versions/pie/restrictions-non-sdk-interfaces
We have an issue to look at this
#4118
It looks like Version 28 of the support libraries is going to support setting this so we'll need to determine if we want to add a grey listed api like this until we can upgrade Xamarin Forms to the newer support libraries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LabelVisibilityMode has different behaviour than api function SetBottomToolbarShiftMode
.
And problems that related with reflection (grey list, Proguard, etc) are pretty unpleasant.
If we want to wait for new api, we will lose this functionality only for api 26,27 (if I correctly understand how Xamarin forms and support libraries work).
I think we should wait until Xamarin forms will be upgraded to the newer support libraries.
P.S. And after that I will correct review remarks and suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use reflection. I have look around the web and seems other's on "Java" work do the same. But we will need to try to find another workaround since Proguard or other obfuscation/linker tool can strip that property.
return; | ||
|
||
var shiftMode = menuView.Class.GetDeclaredField("mShiftingMode"); | ||
shiftMode.Accessible = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do we set true, and then False?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just the whacky way you have to do it
https://stackoverflow.com/questions/40176244/how-to-disable-bottomnavigationview-shift-mode
The other thing to note is that android looks to be adding an API for doing all of this in the upcoming support libraries
<android.support.design.widget.BottomNavigationView
app:labelVisibilityMode="labeled" />
shiftMode.Accessible = true; | ||
shiftMode.SetBoolean(menuView, IsEnableShiftMode); | ||
shiftMode.Accessible = false; | ||
shiftMode.Dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to call Dispose?
@@ -150,6 +150,48 @@ public static int GetMaxItemCount(this IPlatformElementConfiguration<Android, Fo | |||
return GetMaxItemCount(config.Element); | |||
} | |||
|
|||
public static readonly BindableProperty ToolbarShiftModeProperty = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can have the same property for both, the TabbedPage and the Items, instead of having 2 different properties with different naming.
Maybe add ShiftMode to Page ?
I tested this with v28 of the support libraries and the new setting. It looks like that setting will work for what we need. It's interesting because it looks like the default LabelVisibilityMode with support 28 is the non shifting one. Which is annoying that the behavior is going to just change when updating to v28. LabelVisibilityMode has 4 different available values and we will probably surface this change by surfacing an API for that ENUM into the platform specifics (I'll modify the original ticket) I've included a screen shot of how it looks using the new setting in v28 |
FYI @Viridovics we recently added this If you feel like updating this PR to use that then we can look at getting this reopened and merged |
Description of Change
Add platform specific api:
Issues Resolved
API Changes
Added:
Platforms Affected
Behavioral/Visual Changes
Before/After Screenshots
Not applicable
Testing Procedure
Ui test
BottomNavigationShiftModes
PR Checklist