diff --git a/RGPopup.Maui/Pages/PopupPage.cs b/RGPopup.Maui/Pages/PopupPage.cs index b617b44..b1c6760 100644 --- a/RGPopup.Maui/Pages/PopupPage.cs +++ b/RGPopup.Maui/Pages/PopupPage.cs @@ -7,6 +7,7 @@ namespace RGPopup.Maui.Pages { + [ContentProperty("CoreContent")] public class PopupPage : ContentPage { #region Internal Properties @@ -24,7 +25,7 @@ public class PopupPage : ContentPage #endregion #region Bindable Properties - + public static readonly BindableProperty IsPopupWindowResizableProperty = BindableProperty.Create(nameof(IsPopupWindowResizable), typeof(bool), typeof(PopupPage), false); public bool IsPopupWindowResizable @@ -137,6 +138,25 @@ public bool AndroidTalkbackAccessibilityWorkaround set => SetValue(AndroidTalkbackAccessibilityWorkaroundProperty, value); } + public static readonly BindableProperty CoreContentProperty = BindableProperty.Create(nameof(CoreContent), typeof(View), typeof(ContentPage), null, propertyChanged: OnContentChanged); + + public View CoreContent + { + get => (View)GetValue(CoreContentProperty); + set => SetValue(CoreContentProperty, value); + } + + public static void OnContentChanged(BindableObject bindable, object oldValue, object newValue) + { + if (bindable is not PopupPage popupPage) return; + var coreContent = newValue as View; + if (coreContent is not ContentView) + { + coreContent = new ContentView() { Content = coreContent, InputTransparent = false }; + } + popupPage.Content = new ScrollView(){ Content = coreContent, InputTransparent = false }; + } + #endregion #region Main Methods @@ -146,19 +166,12 @@ public PopupPage() BackgroundColor = Color.FromArgb("#80000000"); InputTransparent = false; } - - /// - /// Fix if ContentPage's content is not ContentView or Grid, then the children will not display. - /// + protected override void OnParentSet() { if (this.Parent != null) { this.SendAppearing(); - if (this.Content is not ContentView) - { - this.Content = new ContentView() { Content = this.Content, InputTransparent = false }; - } } else { diff --git a/RGPopup.Maui/Platforms/iOS/Effects/KeyboardOverlapFixPlatformEffect.cs b/RGPopup.Maui/Platforms/iOS/Effects/KeyboardOverlapFixPlatformEffect.cs index b96795c..8a43654 100644 --- a/RGPopup.Maui/Platforms/iOS/Effects/KeyboardOverlapFixPlatformEffect.cs +++ b/RGPopup.Maui/Platforms/iOS/Effects/KeyboardOverlapFixPlatformEffect.cs @@ -1,13 +1,13 @@ using Foundation; using Microsoft.Maui.Controls.Platform; using CoreGraphics; +using RGPopup.Maui.Pages; using UIKit; namespace RGPopup.Maui.Effects; public class KeyboardOverlapFixPlatformEffect : PlatformEffect { private const double KeyboardOverlapAdjust = 0; - private static readonly bool IsIOS15 = DeviceInfo.Version.Major >= 15; private UIView? _responderView; private NSObject? _keyboardShowObserver; @@ -21,7 +21,9 @@ public class KeyboardOverlapFixPlatformEffect : PlatformEffect private bool _pageShiftedUp; private bool _pageLoaded = false; - private ContentPage? CurrentPage => Element as ContentPage; + private PopupPage? CurrentPage => Element as PopupPage; + private ScrollView? ContentScrollView => CurrentPage?.Content as ScrollView; + private ContentView? ContentView => ContentScrollView?.Content as ContentView; protected override void OnAttached() { @@ -81,19 +83,14 @@ private void OnKeyboardShow(NSNotification notification) private void OnKeyboardShown(NSNotification notification) { - if (!_pageLoaded || _responderView == null || _keyboardShown) return; + if (!_pageLoaded || _keyboardShown) return; _keyboardShown = true; - var keyboardHeight = IsIOS15 ? _responderView.KeyboardLayoutGuide.LayoutFrame.Height : 0; - if (keyboardHeight <= 0) - { - var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification); - keyboardHeight = keyboardFrame.Height; - } - + var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification); + var keyboardHeight = keyboardFrame.Height; //Console.WriteLine($"KeyboardDidShowHeight: {keyboardHeight}"); - if (keyboardHeight <= _keyboardHeight) return; - this.CheckOverlap(keyboardHeight); + if (keyboardHeight < _keyboardHeight) return; + this.CheckOverlap(keyboardHeight, force: true); } private void OnKeyboardHide(NSNotification notification) @@ -109,9 +106,9 @@ private void OnKeyboardHide(NSNotification notification) } } - private void CheckOverlap(nfloat keyboardHeight) + private void CheckOverlap(nfloat keyboardHeight, bool force = false) { - if (_pageShiftedUp) { return; } + if (_pageShiftedUp && !force) { return; } var deltaHeight = keyboardHeight - _keyboardHeight; if (_keyboardOverlap > 0 && deltaHeight > KeyboardOverlapAdjust) { @@ -125,7 +122,6 @@ private void CheckOverlap(nfloat keyboardHeight) _responderView ??= FindFirstResponder(Control); if (_responderView == null) return; _keyboardOverlap = GetOverlapDistance(_responderView, Control, _keyboardHeight, false); - //Console.WriteLine($"KeyboardOverlap: {_keyboardOverlap}"); if (_keyboardOverlap > 0) { ShiftPageUp(); @@ -134,23 +130,24 @@ private void CheckOverlap(nfloat keyboardHeight) private void ShiftPageUp() { - if (CurrentPage == null || Control == null) return; + if (CurrentPage == null || ContentView == null || Control == null) return; + //Console.WriteLine($"KeyboardOverlap: {_keyboardOverlap}"); var deltaBottom = _keyboardOverlap + KeyboardOverlapAdjust; - _originalPadding ??= CurrentPage.Padding; - _currentPadding = new Thickness(_originalPadding.Value.Left, _originalPadding.Value.Top, _originalPadding.Value.Right, _originalPadding.Value.Bottom + deltaBottom); + _originalPadding ??= ContentView.Padding; + _currentPadding = new Thickness(_originalPadding.Value.Left, _originalPadding.Value.Top, _originalPadding.Value.Right, _originalPadding.Value.Bottom+deltaBottom); CurrentPage.Dispatcher.Dispatch(() => { - CurrentPage.Padding = _currentPadding; + ContentView.Padding = _currentPadding; }); _pageShiftedUp = true; } private void ShiftPageDown() { - if (CurrentPage == null || _originalPadding == null) return; + if (CurrentPage == null || ContentView == null || _originalPadding == null) return; CurrentPage.Dispatcher.Dispatch(() => { - CurrentPage.Padding = _originalPadding.Value; + ContentView.Padding = _originalPadding.Value; }); _pageShiftedUp = false; } diff --git a/RGPopup.Maui/Platforms/iOS/Platform/PopupWindow.cs b/RGPopup.Maui/Platforms/iOS/Platform/PopupWindow.cs index 455f514..395c537 100644 --- a/RGPopup.Maui/Platforms/iOS/Platform/PopupWindow.cs +++ b/RGPopup.Maui/Platforms/iOS/Platform/PopupWindow.cs @@ -39,11 +39,13 @@ public override UIView HitTest(CGPoint point, UIEvent? uievent) return null!; var nativeView = pageHandler?.PlatformView; + var scrollView = formsElement.Content?.Handler?.PlatformView as UIView; + var contentView = scrollView?.Subviews?.FirstOrDefault(); var safePadding = formsElement.SafePadding; if ((formsElement.BackgroundClickedCommand != null || formsElement.BackgroundInputTransparent || formsElement.CloseWhenBackgroundIsClicked) && Math.Max(SafeAreaInsets.Left, safePadding.Left) < point.X && point.X < (Bounds.Width-Math.Max(SafeAreaInsets.Right, safePadding.Right)) && Math.Max(SafeAreaInsets.Top, safePadding.Top) < point.Y && point.Y < (Bounds.Height-Math.Max(SafeAreaInsets.Bottom, safePadding.Bottom)) - && (hitTestResult.Equals(nativeView) || hitTestResult.Equals(nativeView?.Subviews?.FirstOrDefault()))) + && (hitTestResult.Equals(nativeView) || hitTestResult.Equals(contentView) || hitTestResult.Equals(contentView?.Subviews?.FirstOrDefault()))) { _ = formsElement.SendBackgroundClick(); if (formsElement.BackgroundInputTransparent)