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

feat: refactor RCTKeyWindow to be more resilient and work in multi-window apps #42036

Closed

Conversation

okwasniewski
Copy link
Contributor

Summary:

This PRs refactors RCTKeyWindow() to be more resilient and work in multi-window apps. After my recent PR got merged (#41935) it significantly reduced the number of calls to RCTKeyWindow() and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt UIWindowSceneDelegate

Changelog:

[IOS] [CHANGED] - refactor RCTKeyWindow to be more resilient and work in multi-window apps

Test Plan:

Checkout RNTester example for Alerts and LoadingView.

rct-key-window-refactorConverted.mp4

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Callstack Partner: Callstack Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Dec 21, 2023
@okwasniewski okwasniewski force-pushed the okwasniewski/KeyWindow branch 2 times, most recently from 2dc9793 to 177ae7d Compare December 22, 2023 09:03
Copy link
Contributor

@cipolleschi cipolleschi left a comment

Choose a reason for hiding this comment

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

Looks good to me, but from a small details.
Can you check that?

NSLog(@"Unable to create alert window: keyWindow is nil");
}
}
_alertWindow = [[UIWindow alloc] initWithWindowScene:RCTKeyWindow().windowScene];
Copy link
Contributor

Choose a reason for hiding this comment

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

The previous check was also checking that the scene activation state was active.
can the windowScene retrieved by RCTKeyWindow be inactive (e.g.: there is already another alert presented)?

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've updated the function to take the activation state into account. As, we should always get the currently focused window. With the previous approach it was possible to retrieve some inactive keyWindow of additional scene (for example created by the OS). Can you check if the internal tests are passing now?

@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@cipolleschi
Copy link
Contributor

On top of the linting issue, we have several tests that are failing internally when they try to present a picker. :(
I'll have to invest some more time to understand why they are failing.

@okwasniewski
Copy link
Contributor Author

Thanks for letting me know, I'm on PTO until next week, when I will be back I will check whether we need the active state check and maybe that would resolve the issue with failing internal tests.

Can you provide me a minimal reproduction of the test that is failing? Is it not finding the current window or something else is happening?

@cipolleschi
Copy link
Contributor

Can you provide me a minimal reproduction of the test that is failing? Is it not finding the current window or something else is happening?

This is tricky. I don't even know where they are failing as our infra is quite complex. I'll need more time to investigate and understand what happens. 😞

@okwasniewski okwasniewski force-pushed the okwasniewski/KeyWindow branch 2 times, most recently from d5f98bb to 7371947 Compare January 2, 2024 12:31
@facebook-github-bot
Copy link
Contributor

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@okwasniewski
Copy link
Contributor Author

Ugh, the internal linter is failing.. Are those internal tests also failing?

@cipolleschi
Copy link
Contributor

Cool, so, the linter is failing, but that's easy and I have to run a simple command to fix that.
This is a well known problem where, internally, we use a linter that is different from the OSS. It is an internally modified version, so it is very hard to have them matching.

The other tests should be good. I'll try to land the diff before EOW.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Jan 5, 2024
@facebook-github-bot
Copy link
Contributor

@cipolleschi merged this pull request in 782e9ea.

Othinn pushed a commit to Othinn/react-native that referenced this pull request Jan 9, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

## Changelog:

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
Saadnajmi pushed a commit to Saadnajmi/react-native-macos that referenced this pull request Jan 15, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
okwasniewski added a commit to callstack/react-native-visionos that referenced this pull request Jan 31, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
okwasniewski added a commit to callstack/react-native-visionos that referenced this pull request Feb 6, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
github-merge-queue bot pushed a commit to software-mansion/react-native-reanimated that referenced this pull request Feb 8, 2024
## Summary

This PR adds `visionos` support. I've refactored call sites to
`UIApplication.sharedApplication.keyWindow` (it's unavailable on
visionOS) for `RCTKeyWindow()` its a React Native core utility for
retrieving key window. (In one of my recent PRs it got support for
multi-window scenarios:
facebook/react-native#42036)


https://github.com/software-mansion/react-native-reanimated/assets/52801365/8b535f78-c91c-4a7c-b956-29c6985d157a

## Test plan

1. Init new visionOS app `npx @callstack/react-native-visionos@latest
init MyApp`
2. Install Reanimated from GitHub commit or link it locally: 

`"react-native-reanimated":
"git@github.com:okwasniewski/react-native-reanimated.git#feat/visionos",`

---------

Co-authored-by: Tomek Zawadzki <tomekzawadzki98@gmail.com>
Co-authored-by: Krzysztof Piaskowy <krzysztof.piaskowy@swmansion.com>
okwasniewski added a commit to callstack/react-native-visionos that referenced this pull request Apr 5, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
okwasniewski added a commit to callstack/react-native-visionos that referenced this pull request Jun 24, 2024
…window apps (facebook#42036)

Summary:
This PRs refactors `RCTKeyWindow()` to be more resilient and work in multi-window apps. After my recent PR got merged (facebook#41935) it significantly reduced the number of calls to `RCTKeyWindow()` and now it's called only when necessary. So this PR makes this function a bit more resource intensive but it guarantees that we will find current scene's key window.

This would also fix some brownfield scenarios where React Native is working in multi-window mode and in the future allow us to more easily adopt `UIWindowSceneDelegate`

bypass-github-export-checks

[IOS] [CHANGED] - refactor `RCTKeyWindow` to be more resilient and work in multi-window apps

Pull Request resolved: facebook#42036

Test Plan:
Checkout RNTester example for Alerts and LoadingView.

https://github.com/facebook/react-native/assets/52801365/8cf4d698-db6d-4a12-8d8d-7a5acf34858b

Reviewed By: huntie

Differential Revision: D52431720

Pulled By: cipolleschi

fbshipit-source-id: 0d6ef1d46b2428c30c9f64dae66b95dbc69f0a3b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. p: Callstack Partner: Callstack Partner Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants