Skip to content

Conversation

@mokagio
Copy link
Contributor

@mokagio mokagio commented Dec 6, 2022

Description

The compiler said:

'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead

Testing instructions

I looked at the code using this property but I'm not user how to exercise the app to trigger one of those code paths.
@woocommerce/ios-developers can some help validate this tweak? Thanks!


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

The compiler said:

> 'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a
> relevant window scene instead
@peril-woocommerce
Copy link

Warnings
⚠️ PR is not assigned to a milestone.
⚠️ PR is missing at least one label.

Generated by 🚫 dangerJS

.connectedScenes
// Filter the connected UIScene instances for those that are UIWindowScene instances
// and map to their keyWindow property
.compactMap { ($0 as? UIWindowScene)?.keyWindow }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's also the option to split this into one computed var for currentWindowScene and one that calls keyWindow on it.

I suggest this because I noticed one instance in which we call this currentKeyWindow only to then access the windowScene of the result:

let orientation = UIApplication.shared.currentKeyWindow?.windowScene?.interfaceOrientation

For additional reference, we also have the code below that uses windowScene, although that one does it starting bottom-up from a UIViewController, rather than top-down from UIApplication.

private extension UIViewController {
/// Attempts to return the scene in with the current controller lives
/// If its view is attached to a window, it will use the scene from that window
/// Otherwise, it looks at it's ancestors for a valid window to find the scene
var currentScene: UIWindowScene? {
if let window = view.window {
return window.windowScene
}
if let parent = parent {
return parent.currentScene
}
return nil
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we should delete this re-implementation? The original keyWindow API has been deprecated for three years. Maybe it's time to stop relying on the no longer true concept that there is one "key window" across the whole application?

Copy link
Contributor Author

@mokagio mokagio Dec 7, 2022

Choose a reason for hiding this comment

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

Good point 🤔 I think the solution might vary on a case by case basis across the various usages of this currentKeyWindow computed property.

I left a comment in a pre-existing issue on the topic that I didn't know about till your comment prompted me to do more research.

@koke, as the author of that issue, have you got any additional context or ideas how to go about this?

I value the removal of the warning and I'm tempted to argue for merging this to reduce the warnings noise. At the same time, I'm well to aware that if we silence it, we might not address the lack of multi window support for a while.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a lot of experience dealing with windows and scenes, but I agree with @crazytonyli that the best approach is probably to get rid of this method. Looking at usage, I see two distinct use cases:

  • To speed up animations when ProcessConfiguration.shouldDisableAnimations is true. For this case, we could as well iterate through all UIApplication.shared.connectedScenes and set the layer speed for all their key windows.
  • Every other instance happens on a UIViewController, which could use view.window instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've added a draft to remove currentKeyWindow: #8440 as discussed above. It's mostly done, but I'll do additional testing next week on specific views functionality.

@mokagio mokagio requested review from a team and crazytonyli December 6, 2022 15:22
@mokagio mokagio added this to the 11.6 milestone Dec 6, 2022
@mokagio mokagio self-assigned this Dec 6, 2022
@wpmobilebot
Copy link
Collaborator

You can test the changes from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr8327-372ffad on your iPhone

If you need access to App Center, please ask a maintainer to add you.

@mokagio mokagio modified the milestones: 11.6, 11.7 Dec 7, 2022
@spencertransier spencertransier modified the milestones: 11.7, 11.8 Dec 16, 2022
@ealeksandrov
Copy link
Contributor

Closing this in favor of currentKeyWindow removal.

@mokagio
Copy link
Contributor Author

mokagio commented Jan 4, 2023

thanks @ealeksandrov 🎉 🙇‍♂️

@mokagio mokagio deleted the mokagio/ios-15-key-window branch January 4, 2023 02:08
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.

7 participants