Skip to content

Commit

Permalink
Added: Code from PRs:
Browse files Browse the repository at this point in the history
https://github.com/rotorgames/Rg.Plugins.Popup/pull/754/files
rotorgames#752

Also added logic to keep soft keyboard open when popup displays
  • Loading branch information
brandonward34 committed May 21, 2023
1 parent 8e5a166 commit d1afffd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Rg.Plugins.Popup/Animations/MoveAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public override Task Appearing(View content, PopupPage page)

if (content != null)
{
if (Device.RuntimePlatform == Device.iOS)
{
page.Opacity = 0;
}

var topOffset = GetTopOffset(content, page);
var leftOffset = GetLeftOffset(content, page);

Expand All @@ -77,6 +82,11 @@ public override Task Appearing(View content, PopupPage page)
content.TranslationX = leftOffset;
}

if (Device.RuntimePlatform == Device.iOS)
{
taskList.Add(page.FadeTo(1, 1));
}

taskList.Add(content.TranslateTo(_defaultTranslationX, _defaultTranslationY, DurationIn, EasingIn));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,19 @@ protected override void OnLayout(bool changed, int l, int t, int r, int b)

protected override void OnAttachedToWindow()
{
Context.HideKeyboard(((Activity?)Context)?.Window?.DecorView);
// Comment out so keyboard can be seen when popup displays
//Context.HideKeyboard(((Activity?)Context)?.Window?.DecorView);
base.OnAttachedToWindow();
}

protected override void OnDetachedFromWindow()
{
Device.StartTimer(TimeSpan.FromMilliseconds(0), () =>
{
Popup.Context.HideKeyboard(((Activity?)Popup.Context)?.Window?.DecorView);
return false;
});
// Comment out so keyboard can be seen when popup displays
//Device.StartTimer(TimeSpan.FromMilliseconds(0), () =>
//{
// Popup.Context.HideKeyboard(((Activity?)Popup.Context)?.Window?.DecorView);
// return false;
//});
base.OnDetachedFromWindow();
}

Expand Down
26 changes: 22 additions & 4 deletions Rg.Plugins.Popup/Platforms/Ios/Impl/PopupPlatformIos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,23 @@ public Task AddAsync(PopupPage page)
PopupWindow window;
if (IsiOS13OrNewer)
{
if (UIApplication.SharedApplication.ConnectedScenes.ToArray()
.FirstOrDefault(x => x.ActivationState == UISceneActivationState.ForegroundActive && x is UIWindowScene) is UIWindowScene connectedScene)
window = new PopupWindow(connectedScene);
var connectedWindowScene = UIApplication.SharedApplication
.ConnectedScenes
.ToArray()
.FirstOrDefault(scene =>
{
// The popup should only be displayed on a scene that displays interactive windows
// on the device’s built-in display or an externally connected display.
if (scene.Session?.Role != UIWindowSceneSessionRole.Application)
{
return false;
}
return scene.ActivationState == UISceneActivationState.ForegroundActive
&& scene is UIWindowScene;
}) as UIWindowScene;

if (connectedWindowScene != null)
window = new PopupWindow(connectedWindowScene);
else
window = new PopupWindow();

Expand All @@ -71,7 +85,11 @@ public Task AddAsync(PopupPage page)
if (window.RootViewController.View != null)
window.RootViewController.View.BackgroundColor = Color.Transparent.ToUIColor();
window.WindowLevel = UIWindowLevel.Normal;
window.MakeKeyAndVisible();
// Comment out so keyboard can be seen when popup displays
//window.MakeKeyAndVisible();

// Add so keyboard can be seen when popup displays
window.Hidden = false;

if (!IsiOS9OrNewer)
window.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);
Expand Down
2 changes: 2 additions & 0 deletions Rg.Plugins.Popup/Rg.Plugins.Popup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<Description>Plugin for Xamarin forms. Allows you to open any page as a popup.</Description>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
<UseWPF Condition=" '$(OS)' == 'Windows_NT' ">true</UseWPF>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>2.1.0.3</Version>
</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.StartsWith('uap')) And '$(OS)' == 'Windows_NT'">
Expand Down

0 comments on commit d1afffd

Please sign in to comment.