uno icon indicating copy to clipboard operation
uno copied to clipboard

[Android] ApplicationView.GetForCurrentView().Bounds ignores the translucent navigationbar

Open takla21 opened this issue 1 year ago • 7 comments

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

image

Screenshot_20240216-134423

Expected behavior

For the same code on iOS, those two values are different which helps us avoiding phone edges

image (1)

How to reproduce it (as minimally and precisely as possible)

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

takla21 avatar Feb 16 '24 22:02 takla21

This also feels similar to https://github.com/unoplatform/nventive-private/issues/510, what do you think @kazo0?

jeromelaban avatar Feb 19 '24 12:02 jeromelaban

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:

Screenshot_1708364514

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

kazo0 avatar Feb 19 '24 17:02 kazo0

It may be that the code relying on VisibleBounds should react on the Window.SizeChanged.

jeromelaban avatar Feb 19 '24 18:02 jeromelaban

@jeromelaban I've tried on the sample to subscribe to SizeChanged, but it doesn't seem to be raised at all on Android.

image

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 avatar Feb 19 '24 18:02 takla21

@takla21 what about hooking to ApplicationView.GetForCurrentView().VisibleBoundsChanged?

kazo0 avatar Feb 19 '24 18:02 kazo0

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 avatar Feb 19 '24 19:02 kazo0

@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.

takla21 avatar Feb 19 '24 19:02 takla21