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

[iOS] Picker not displayed when not on main view controller #136

Merged
merged 4 commits into from
Jul 29, 2024

Conversation

dan15d
Copy link
Contributor

@dan15d dan15d commented Jul 29, 2024

Retrieve the top view controller from the view hierarchy and display picker.

In the current versión i get this error:

Attempt to present <UIDocumentPickerViewController: 0x10c80ac00> on <.MainViewController: 0x10a0099f0> (from <.MainViewController: 0x10a0099f0>) whose view is not in the window hierarchy.

Retrieve the top view controller from the view hierarchy and display picker
@dan15d dan15d changed the title Picker not displayed when not on main view controller [iOS] Picker not displayed when not on main view controller Jul 29, 2024
@MohamedRejeb
Copy link
Owner

Thanks for reporting that!
What about using LocalUIViewController.current is it going to fix the issue?

@dan15d
Copy link
Contributor Author

dan15d commented Jul 29, 2024

Unfortunately, LocalUIViewController.current requires a @composable context and the onLaunch callback of FilePickerLauncher doesn't have this context.

@MohamedRejeb
Copy link
Owner

Yes that's ok, it can be created on Compose:
val uiViewController = LocalUIViewController.current
and then passed to onLaunch, also it should be passed as a key to the remember

@dan15d
Copy link
Contributor Author

dan15d commented Jul 29, 2024

That works! Do you want me to upload the changes?

@MohamedRejeb
Copy link
Owner

Yes

[iOS] Use LocalUIViewController.current to show the picker
@MohamedRejeb
Copy link
Owner

It need to be added as a key to the remember as well:

...
    return remember(currentUiViewController) {
        FilePickerLauncher(
...

@MohamedRejeb
Copy link
Owner

Also, you forgot to push the import for LocalUIViewController I guess

@dan15d
Copy link
Contributor Author

dan15d commented Jul 29, 2024

yes, i fix it. sorry

pass the currentUIViewController on remember
@MohamedRejeb MohamedRejeb self-requested a review July 29, 2024 12:31
Copy link
Owner

@MohamedRejeb MohamedRejeb left a comment

Choose a reason for hiding this comment

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

Look good. Thanks for your contribution!

@MohamedRejeb MohamedRejeb merged commit 58e15b7 into MohamedRejeb:main Jul 29, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants