2using Microsoft.Maui.ApplicationModel;
14 private double keyboardHeight;
15 private bool isKeyboardVisible;
16 private bool isDisposed;
24 this.platformSpecific = platformSpecific ??
throw new ArgumentNullException(nameof(platformSpecific));
25 this.platformSpecific.KeyboardSizeChanged += this.OnKeyboardSizeChanged;
26 this.platformSpecific.KeyboardHidden += this.OnKeyboardHidden;
46 this.platformSpecific.KeyboardSizeChanged -= this.OnKeyboardSizeChanged;
47 this.platformSpecific.KeyboardHidden -= this.OnKeyboardHidden;
48 this.isDisposed =
true;
53 double newHeight = Math.Max(0, message.KeyboardSize);
54 bool newVisibility = newHeight > 0.5;
56 if (Math.Abs(newHeight -
this.keyboardHeight) < 0.5 && newVisibility ==
this.isKeyboardVisible)
59 this.keyboardHeight = newHeight;
60 this.isKeyboardVisible = newVisibility;
66 if (this.keyboardHeight <= 0 && !this.isKeyboardVisible)
69 this.keyboardHeight = 0;
70 this.isKeyboardVisible =
false;
74 private void RaiseChanged()
78 this.KeyboardInsetChanged?.Invoke(
this,
new KeyboardInsetChangedEventArgs(this.keyboardHeight, this.isKeyboardVisible));
81 if (MainThread.IsMainThread)
84 MainThread.BeginInvokeOnMainThread(Raise);
Default implementation of IKeyboardInsetsService that normalizes platform keyboard measurements.
bool IsKeyboardVisible
Gets a value indicating whether the software keyboard is currently visible.
KeyboardInsetsService(IPlatformSpecific platformSpecific)
Initializes a new instance of the KeyboardInsetsService class.
EventHandler< KeyboardInsetChangedEventArgs >? KeyboardInsetChanged
double KeyboardHeight
Gets the current keyboard height in device-independent units.
void Dispose()
Disposes the instance and detaches event handlers.
Provides normalized keyboard inset information for UI components.
class KeyboardSizeMessage(float KeyboardSize)
Keyboard size change message