Skip to content
Merged
Prev Previous commit
Next Next commit
fix: type
  • Loading branch information
StanleyCocos committed Feb 8, 2025
commit 4f733e59285438507f3f31baeefc19823ecfc0e9
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class URLLaunchSession: NSObject, SFSafariViewControllerDelegate {

private let completion: OpenInSafariCompletionHandler
private let url: URL
private var isLoadCompleted: Bool?
private var isLoadCompleted: Bool = false

/// The Safari view controller used for displaying the URL.
let safariViewController: SFSafariViewController
Expand Down Expand Up @@ -47,14 +47,14 @@ final class URLLaunchSession: NSObject, SFSafariViewControllerDelegate {
} else {
completion(.success(.failedToLoad))
}
isLoadCompleted = didLoadSuccessfully
isLoadCompleted = true
}

/// Called when the user finishes using the Safari view controller.
///
/// - Parameter controller: The Safari view controller.
func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
if isLoadCompleted == nil {
if !isLoadCompleted {
completion(.success(.failedToLoad))
Copy link
Member

Choose a reason for hiding this comment

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

Is .failedToLoad the correct result here? Or we should add a new InAppLoadResult.dismissed result?

If this is the correct result, should we update this comment to indicate this case can happen if the user dismisses the Safari view before the initial load completes?

/// The URL did not load successfully.
failedToLoad,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At first, I did consider adding a new InAppLoadResult to describe the close action, but it seems it could lead to confusion among developers. This is because, currently, after a successful load, clicking the close button does not trigger any callback.

Additionally, when the user clicks close before the loading is complete, triggering the failedToLoad callback seems reasonable in a broader sense, as the interruption of the loading process can be considered a loading failure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this is the correct result, should we update this comment to indicate this case can happen if the user dismisses the Safari view before the initial load completes?

Do you think it’s possible to modify the comment like this:

// The URL did not load successfully (or close the SFSafariViewController earlier)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Returning this will throw an exception saying there was an error loading the page, which seems misleading. I think a new Pigeon return type that Dart interprets to return false would be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created a new dismissed state to represent the current status.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc @stuartmorgan
Could you take another look?

}
controller.dismiss(animated: true, completion: nil)
Expand Down