Skip to content
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

Add support for presenting/opening files on iOS #6448

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 10 additions & 10 deletions osu.Framework.iOS/IOSFilePresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ namespace osu.Framework.iOS
{
public class IOSFilePresenter : UIDocumentInteractionControllerDelegate
{
private readonly UIWindow window;
private readonly UIDocumentInteractionController viewController = new UIDocumentInteractionController();

private UIWindow? window;

public bool OpenFile(string filename, UIWindow window)
public IOSFilePresenter(UIWindow window)
{
this.window ??= window;
this.window = window;
}

var gameView = window.RootViewController!.View!;
public bool OpenFile(string filename)
{
setupViewController(filename);

if (viewController.PresentPreview(true))
return true;

var gameView = window.RootViewController!.View!;
return viewController.PresentOpenInMenu(gameView.Bounds, gameView, true);
}

public bool PresentFile(string filename, UIWindow window)
public bool PresentFile(string filename)
{
this.window ??= window;

var gameView = window.RootViewController!.View!;
setupViewController(filename);

var gameView = window.RootViewController!.View!;
return viewController.PresentOptionsMenu(gameView.Bounds, gameView, true);
}

Expand All @@ -49,7 +49,7 @@ private void setupViewController(string filename)
viewController.Uti = UTType.CreateFromExtension(Path.GetExtension(filename))?.Identifier ?? UTTypes.Data.Identifier;
}

public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller) => window!.RootViewController!;
public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller) => window.RootViewController!;

public override void WillBeginSendingToApplication(UIDocumentInteractionController controller, string? application)
{
Expand Down
9 changes: 5 additions & 4 deletions osu.Framework.iOS/IOSGameHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ namespace osu.Framework.iOS
{
public class IOSGameHost : SDLGameHost
{
private readonly IOSFilePresenter presenter = new IOSFilePresenter();

private IOSWindow iosWindow => (IOSWindow)Window;

private IOSFilePresenter? backingPresenter;
private IOSFilePresenter presenter => backingPresenter ??= new IOSFilePresenter(iosWindow.UIWindow);
Copy link
Member

Choose a reason for hiding this comment

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

i'd probably prefer using Lazy<> instead of backingXXX just to conform to existing standards.

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't intend to drag this but I made it a lazy and then felt I could just take a different much simpler approach instead. 7c7529d


public IOSGameHost()
: base(string.Empty)
{
Expand All @@ -46,9 +47,9 @@ protected override void SetupConfig(IDictionary<FrameworkSetting, object> defaul

public override Storage GetStorage(string path) => new IOSStorage(path, this);

public override bool OpenFileExternally(string filename) => presenter.OpenFile(filename, iosWindow.UIWindow);
public override bool OpenFileExternally(string filename) => presenter.OpenFile(filename);

public override bool PresentFileExternally(string filename) => presenter.PresentFile(filename, iosWindow.UIWindow);
public override bool PresentFileExternally(string filename) => presenter.PresentFile(filename);

public override void OpenUrlExternally(string url)
{
Expand Down
Loading