uno: [NET6][Android] VisibleBoundsPadding and it's API are Not Working
Current behavior
Using Uno.UI.Toolkit.VisibleBoundsPadding.PaddingMask=Bottom with <item name="android:windowTranslucentNavigation">true</item> doesn’t work and the Android navigation bar height is ignored.
Also this wasn’t an issue on Xamarin with or without the windowTranslucentNavigation.
I also noticed that on Android 10, ApplicationView.GetForCurrentView().VisibleBounds.Bottom doesn’t include the navigation bar height in it and can cause issues with custom controls even if it looks like it work inside Uno.UI.Toolkit.VisibleBoundsPadding.PaddingMask=Bottom. On some applications we need to set <item name="android:windowTranslucentNavigation">true</item> but not in the sample.
Android 13 issue:

Android 10 issue:

Expected behavior

How to reproduce it (as minimally and precisely as possible)
- Download UnoAppTest.zip.
- For Android 13 issue you can play around with
<item name="android:windowTranslucentNavigation"></item>in Styles.xml. - For Android 10 issue, you can use breakpoints in MainPage.xaml.cs to see the actual values.
- Doable on physical device and emulators.
Workaround
Android 13 issue:
Playing around with <item name="android:windowTranslucentNavigation">false</item> or <item name="android:windowTranslucentNavigation">true</item> may fix the issue.
Android 10 issue: Adding some Android 10 specific code could fix the issue but it doesn’t look like the right thing to do considering that it assumes that we must have bottom padding here.
private double GetBottomPadding()
{
#if __MOBILE__
var bounds = App.MainWindow.Bounds;
var visibleBounds = ApplicationView.GetForCurrentView().VisibleBounds;
var bottomPadding = bounds.Bottom - visibleBounds.Bottom;
#if __ANDROID_10__
// Workaround for Android 10, the navigation bar is not included in the visible bounds, so we need to add it manually.
if (bottomPadding == 0)
{
var navigationBarHeightId = Android.Content.Res.Resources.System.GetIdentifier("navigation_bar_height", "dimen", "android");
var navigationBarHeight = Android.Content.Res.Resources.System.GetDimensionPixelSize(navigationBarHeightId) / Android.Content.Res.Resources.System.DisplayMetrics.Density;
bottomPadding += navigationBarHeight;
}
#endif
return bottomPadding;
#else
return 0;
#endif
}
Works on UWP/WinUI
None
Environment
Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia, Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia
NuGet package version(s)
4.9.0-dev.580
Affected platforms
Android
IDE
Visual Studio 2022
IDE version
17.5.4
Relevant plugins
No response
Anything else we need to know?
No response
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 26 (13 by maintainers)
@carldebilly
Looks to be some sort of layouting/measuring issue on Android. Attached a small repro app - VisibleBoundsPaddingTest.zip. Some sort of race condition maybe? It seems that the VisibleBoundsPadding is properly setting the Padding on the control but it is not reflected in the UI until a re-layout is forced.
In the repro app, either you can:
await Task.Delay(1000)in the code-behind and this causes the UI to reflect the Padding properlyExpected positions of green boxes:
Actual positions of green boxes:
Here’s what happens when you click on the re-layout button, notice the bottom padding appears after clicking.
Also, @Soap-141, I get the same issue on a Xamarin/UWP app so I’m not sure if it’s net6.0-android specific: sample app - VBPXamUWP.zip
It’s working thanks @kazo0! https://github.com/unoplatform/nventive-private/issues/486
@Soap-141 you should be able to test with 4.10.0-dev.76
ah i see, ok so this should all be fixed by https://github.com/unoplatform/uno/pull/12444
@Soap-141 sorry the PR was accidentally merged and auto-closed the issue, im still working on it now. It should definitely have fixed the issue you are talking about though for Android 10- so this is concerning. I will look into it
You can find published builds from this list.
I’m not sure if we’ll be able to backport to 4.8, this is quite a large change.