Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NET6][Android] VisibleBoundsPadding and it's API are Not Working #12007

Closed
Soap-141 opened this issue Apr 17, 2023 · 26 comments · Fixed by #12246 or #12444
Closed

[NET6][Android] VisibleBoundsPadding and it's API are Not Working #12007

Soap-141 opened this issue Apr 17, 2023 · 26 comments · Fixed by #12246 or #12444
Assignees
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification

Comments

@Soap-141
Copy link

Soap-141 commented Apr 17, 2023

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:
MicrosoftTeams-image (8)

Android 10 issue:
image

Expected behavior

image
MicrosoftTeams-image (9)

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

  1. Download UnoAppTest.zip.
  2. For Android 13 issue you can play around with <item name="android:windowTranslucentNavigation"></item> in Styles.xml.
  3. For Android 10 issue, you can use breakpoints in MainPage.xaml.cs to see the actual values.
  4. 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

@Soap-141 Soap-141 added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels Apr 17, 2023
@Soap-141
Copy link
Author

May be similar to #6218

@Robert-Louis Robert-Louis self-assigned this Apr 27, 2023
@kazo0
Copy link
Contributor

kazo0 commented May 5, 2023

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

  • click the button to force a re-layout which causes the bottom padding to appear, or
  • rotate the device, or
  • uncomment the await Task.Delay(1000) in the code-behind and this causes the UI to reflect the Padding properly

Expected positions of green boxes:
image (1)

Actual positions of green boxes:
image

Here's what happens when you click on the re-layout button, notice the bottom padding appears after clicking.
vbp_button

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

@Soap-141
Copy link
Author

Soap-141 commented May 5, 2023

@kazo0 Yeah I did not notice any issue on our Xamarin applications as of now but it could also be an issue I guess. As long as we can find a fix. Poke me if you need anything.

@Soap-141
Copy link
Author

Soap-141 commented May 24, 2023

@kazo0 @jeromelaban I guess I should create a backport request for 4.8 after testing?

@Soap-141
Copy link
Author

@kazo0 Should it be on 4.9.0-dev.1168?

@jeromelaban
Copy link
Member

I'm not sure if we'll be able to backport to 4.8, this is quite a large change.

@jeromelaban
Copy link
Member

@kazo0 Should it be on 4.9.0-dev.1168?

You can find published builds from this list.

@Soap-141
Copy link
Author

The build is not ready yet. Will have to test later then.

@Soap-141
Copy link
Author

Soap-141 commented May 25, 2023

@kazo0 @jeromelaban I tested Uno 4.9.0-dev.1195 and I still need to use a workaround on Android 10 when using a translucent navigation bar (See description to know how I do that).

// Workaround for Android 10, the navigation bar is not included in the visible bounds, so we need to add it manually.
if (safeAreaBottomPadding == 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;

	safeAreaBottomPadding += navigationBarHeight;
}

@Soap-141 Soap-141 reopened this May 25, 2023
@kazo0
Copy link
Contributor

kazo0 commented May 25, 2023

@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

@kazo0
Copy link
Contributor

kazo0 commented May 27, 2023

@Soap-141

I took your original sample app and removed the workarounds and updated it to my local uno nuget override with the changes and it looks to be working fine. It should look like this right?

image

Once the CI for the PR runs I will test with the packages it creates but I didn't really change anything since you tested so I'm not sure why it wasn't working for you. This is on an emulator running API 28

@kazo0
Copy link
Contributor

kazo0 commented May 27, 2023

Looks to be working, let me know if it works for you as well:

image

@Soap-141
Copy link
Author

@kazo0 It's supposed to be API 29. But I'm testing again in a couple of minutes.

@Soap-141
Copy link
Author

Soap-141 commented May 29, 2023

@kazo0 If I set toolkit:VisibleBoundsPadding.PaddingMask="Bottom" in XAML, it's working but the part in the screenshot doesn't work (it's always 0).
image
It's problematic because in some applications we are using custom behaviors that use those API.

@kazo0
Copy link
Contributor

kazo0 commented May 29, 2023

@Soap-141

I'm not quite sure I'm understanding the issue, you should just be able to use the bottomPadding in all your cases. There should no longer be a need to use VisibleBoundsPadding.WindowPadding.Bottom or the #if __ANDROID_10__ block

@kazo0
Copy link
Contributor

kazo0 commented May 29, 2023

Oh wait, are you saying bottomPadding is always 0??

@Soap-141
Copy link
Author

Soap-141 commented May 29, 2023

@kazo0 Exactly, for Android 10.

@kazo0
Copy link
Contributor

kazo0 commented May 29, 2023

@Soap-141

Strange, it's working for me, I created a button and on click I grab the bottomPadding like you do and I am getting a value. Are you perhaps trying to calculate this too early? What is the value of the VisibleBounds when you debug?

@Soap-141
Copy link
Author

Soap-141 commented May 29, 2023

@kazo0
Are you on Android 10 API 29 (I am using an emulator)?
image
image

@kazo0
Copy link
Contributor

kazo0 commented May 29, 2023

Strange, I am using an API 29 emulator:

image

image

@Soap-141, what nuget package version are you on? the ones from the pull request i linked?

@Soap-141
Copy link
Author

@kazo0 Didn't have access to your link, so I assumed latest preview.

@kazo0
Copy link
Contributor

kazo0 commented May 29, 2023

ah i see, ok so this should all be fixed by #12444

@kazo0
Copy link
Contributor

kazo0 commented May 30, 2023

@Soap-141 you should be able to test with 4.10.0-dev.76

@Soap-141
Copy link
Author

@kazo0 Thanks I'll be testing that out and may request a back port on 4.8/4.9 depending on what is possible.

@Soap-141
Copy link
Author

It's working thanks @kazo0! https://github.com/unoplatform/nventive-private/issues/486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification
Projects
None yet
4 participants