uno
uno copied to clipboard
[Android] ApplicationView.GetForCurrentView().Bounds ignores the translucent navigationbar
Current behavior
With windowTranslucentNavigation
set to true
ApplicationView.GetForCurrentView().VisibleBounds.Bottom
is the same as MainWindow!.Bounds.Bottom
#if __ANDROID__ || __IOS__
var full = App.Instance.MainWindow!.Bounds;
var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
var bottomPadding = full.Bottom - bounds.Bottom;
#else
var bottomPadding = 0;
#endif
Expected behavior
For the same code on iOS, those two values are different which helps us avoiding phone edges
How to reproduce it (as minimally and precisely as possible)
- Download this sample BottomBoundsIssue.zip
- Deploy on Android
Workaround
Waiting for ApplicationView.GetForCurrentView().VisibleBoundsChanged
event to be raised to ensure that it gets the appropriate values
public Page()
{
#if __ANDROID__
ApplicationView.GetForCurrentView().VisibleBoundsChanged += OnVisibleBoundsChanged;
#else
InitializeSafeArea();
#endif
}
private void OnVisibleBoundsChanged(ApplicationView sender, object args)
{
ApplicationView.GetForCurrentView().VisibleBoundsChanged -= OnVisibleBoundsChanged;
InitializeSafeArea();
}
private void InitializeSafeArea()
{
#if __ANDROID__ || __IOS__
var full = App.Instance.CurrentWindow.Bounds;
var bounds = ApplicationView.GetForCurrentView().VisibleBounds;
var bottomPadding = full.Bottom - bounds.Bottom;
#else
var bottomPadding = 0;
#endif
if (bottomPadding > 0)
{
SafeAreaRow.Height = new GridLength(bottomPadding);
}
}
Works on UWP/WinUI
None
Environment
Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia
NuGet package version(s)
5.1.56
Affected platforms
Android
IDE
Visual Studio 2022
IDE version
17.7.7; 17.10.0 Preview 1.0
Relevant plugins
No response
Anything else we need to know?
On our project, it started to happen when we've updated uno from 4.8.39 to 4.10.34
Related issue #12007
This also feels similar to https://github.com/unoplatform/nventive-private/issues/510, what do you think @kazo0?
Looks to be a timing issue with when the VisibleBounds is grabbed. If I place a button in the page and cause it to call InitializeSafeArea
on click, I see the right values:
But for some reason the VisibleBounds looks to still be reporting as if we are on the splashscreen and displaying fullscreen when the ctor for MainPage is called
It may be that the code relying on VisibleBounds should react on the Window.SizeChanged.
@jeromelaban I've tried on the sample to subscribe to SizeChanged
, but it doesn't seem to be raised at all on Android.
However, from what @kazo0 mentioned in his previous comment, I can workaround it by subscribing to the Loaded
event. Although it can cause flickers depending on some cases on our actual project, at least it gives us a temporary solution to move the content out of the navigationbar
@takla21 what about hooking to ApplicationView.GetForCurrentView().VisibleBoundsChanged
?
Ah, it seemingly also depends on when you call MainWindow.Activate()
in the App.cs
, so placing that call before the navigation to MainPage
is performed will avoid this issue but we are still stuck with the Windows Bounds being equal to the VisibleBounds at that point
@MartinZikmund this looks to be related to multi-window changes
@kazo0 so subscribing to ApplicationView.GetForCurrentView().VisibleBoundsChanged
works too. However, is it expected to be the permanent solution? Like, I tried to do the same on iOS and that event isn't being called at all.