Skip to content

Commit

Permalink
add workaround for android 11 ime insets being weird (#16201)
Browse files Browse the repository at this point in the history
Co-authored-by: Max Katz <maxkatz6@outlook.com>
  • Loading branch information
emmauss and maxkatz6 authored Jul 2, 2024
1 parent 53b8c6d commit 75821be
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Android/Avalonia.Android/Platform/AndroidInsetsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Android.OS;
using Android.Views;
using Android.Views.Animations;
using AndroidX.Core.Graphics;
using AndroidX.Core.View;
using Avalonia.Android.Platform.SkiaPlatform;
using Avalonia.Animation.Easings;
Expand All @@ -25,6 +26,7 @@ internal sealed class AndroidInsetsManager : WindowInsetsAnimationCompat.Callbac
private Color? _systemBarColor;
private InputPaneState _state;
private Rect _previousRect;
private Insets? _previousImeInset;
private readonly bool _usesLegacyLayouts;

private AndroidWindow Window => _activity.Window ?? throw new InvalidOperationException("Activity.Window must be set.");
Expand Down Expand Up @@ -148,6 +150,19 @@ public WindowInsetsCompat OnApplyWindowInsets(View v, WindowInsetsCompat insets)

State = insets.IsVisible(WindowInsetsCompat.Type.Ime()) ? InputPaneState.Open : InputPaneState.Closed;

// Workaround for weird inset values for android 11
if(Build.VERSION.SdkInt == BuildVersionCodes.R)
{
var imeInset = insets.GetInsets(WindowInsetsCompat.Type.Ime());
if(_previousImeInset == default)
_previousImeInset = imeInset;
if(imeInset.Bottom != _previousImeInset.Bottom)
{
NotifyStateChanged(State, _previousRect, OccludedRect, TimeSpan.Zero, null);
}
_previousImeInset = imeInset;
}

return insets;
}

Expand Down

0 comments on commit 75821be

Please sign in to comment.