Skip to content

chore: fix project #19894

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Android.Views;
using Android.Widget;
using Microsoft.UI.Xaml.Media;
using Com.Nostra13.Universalimageloader.Core;
using Windows.Foundation.Metadata;
using Uno.Extensions;
using Windows.ApplicationModel.Activation;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using Android.App;
using Android.Graphics;
using Android.Graphics.Drawables;
Expand All @@ -10,10 +8,7 @@
using AndroidX.Core.View;
using Uno.Disposables;
using Uno.UI.Extensions;
using Windows.Devices.Sensors;
using Windows.Foundation;
using Windows.Graphics.Display;
using Windows.UI.ViewManagement;
using Microsoft.UI.Xaml;
using Rect = Android.Graphics.Rect;

Expand All @@ -36,11 +31,14 @@

private readonly Activity _activity;
private readonly GlobalLayoutProvider _adjustNothingLayoutProvider, _adjustResizeLayoutProvider;
private double _cachedDensity;

Check warning on line 34 in src/Uno.UI.Runtime.Skia.Android/Microsoft/UI/Xaml/LayoutProvider.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/Uno.UI.Runtime.Skia.Android/Microsoft/UI/Xaml/LayoutProvider.cs#L34

Make '_cachedDensity' 'readonly'.

public LayoutProvider(Activity activity)
{
this._activity = activity;

_cachedDensity = GetScale();

_adjustNothingLayoutProvider = new GlobalLayoutProvider(activity, null!, null!)
{
SoftInputMode = SoftInput.AdjustNothing | SoftInput.StateUnchanged,
Expand Down Expand Up @@ -138,11 +136,37 @@

private void MeasureInsets(PopupWindow sender, WindowInsetsCompat insets)
{
//var systemInsets = insets.GetInsets(WindowInsetsCompat.Type.SystemBars())
// .ToThickness()
// .PhysicalToLogicalPixels();
var size = insets.GetInsets(WindowInsetsCompat.Type.SystemBars())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartinZikmund Is this relevant? I saw it was commented out so I added the implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartinZikmund did you have time to check this?

.ToThickness();

var systemInsets = PhysicalToLogicalPixels(size);

InsetsChanged?.Invoke(systemInsets);
}

private Thickness PhysicalToLogicalPixels(Thickness size)
{
return new Thickness(
top: PhysicalToLogicalPixels(size.Top),
left: PhysicalToLogicalPixels(size.Left),
right: PhysicalToLogicalPixels(size.Right),
bottom: PhysicalToLogicalPixels(size.Bottom)
);
}

private double PhysicalToLogicalPixels(double value) => value / _cachedDensity;

private float GetScale()
{
float cachedDensity = 0;

if (Android.App.Application.Context.Resources is { } resources && resources.DisplayMetrics is not null)
{
using Android.Util.DisplayMetrics displayMetrics = resources.DisplayMetrics;
cachedDensity = displayMetrics.Density;
}

InsetsChanged?.Invoke(default);
return cachedDensity;
}

private class GlobalLayoutProvider : PopupWindow, ViewTreeObserver.IOnGlobalLayoutListener, AndroidX.Core.View.IOnApplyWindowInsetsListener
Expand Down
Loading