Skip to content

Commit

Permalink
feat(iOS) remove deprecated [UIScreen mainScreen] references (#41388)
Browse files Browse the repository at this point in the history
Summary:
The goal for this PR is to further remove references for `[UIScreen mainScreen]` and migrate them to use trait collections. This helps out of tree platforms like visionOS (where the `UIScreen` is not available).

bypass-github-export-checks

## Changelog:

[INTERNAL] [CHANGED] - use currentTraitCollection for FBSnapshotTestController.m
[IOS] [CHANGED] - use key window width to assign the correct width for RCTDevLoadingView

Pull Request resolved: #41388

Test Plan:
– Check if tests passes
- Check if `RCTDevLoadingView` shows up correctly.

Screenshot:
![CleanShot 2023-11-09 at 13 48 48@2x](https://github.com/facebook/react-native/assets/52801365/4c91399e-f70a-4e78-8288-bc7b8377c980)

Reviewed By: javache

Differential Revision: D51156230

Pulled By: cipolleschi

fbshipit-source-id: bbe711e0281046a082fd1680b55e2d117915ad00
  • Loading branch information
okwasniewski authored and facebook-github-bot committed Nov 10, 2023
1 parent 1a61afd commit 88e3913
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 4 additions & 6 deletions packages/react-native/React/CoreModules/RCTDevLoadingView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,11 @@ - (void)showMessage:(NSString *)message color:(UIColor *)color backgroundColor:(
dispatch_async(dispatch_get_main_queue(), ^{
self->_showDate = [NSDate date];
if (!self->_window && !RCTRunningInTestEnvironment()) {
CGSize screenSize = [UIScreen mainScreen].bounds.size;

UIWindow *window = RCTSharedApplication().keyWindow;
self->_window =
[[UIWindow alloc] initWithFrame:CGRectMake(0, 0, screenSize.width, window.safeAreaInsets.top + 10)];
self->_label =
[[UILabel alloc] initWithFrame:CGRectMake(0, window.safeAreaInsets.top - 10, screenSize.width, 20)];
CGFloat windowWidth = window.bounds.size.width;

self->_window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, windowWidth, window.safeAreaInsets.top + 10)];
self->_label = [[UILabel alloc] initWithFrame:CGRectMake(0, window.safeAreaInsets.top - 10, windowWidth, 20)];
[self->_window addSubview:self->_label];

self->_window.windowLevel = UIWindowLevelStatusBar + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ - (NSString *)_fileNameForSelector:(SEL)selector
if (0 < identifier.length) {
fileName = [fileName stringByAppendingFormat:@"_%@", identifier];
}
if ([[UIScreen mainScreen] scale] > 1.0) {
fileName = [fileName stringByAppendingFormat:@"@%.fx", [[UIScreen mainScreen] scale]];

UITraitCollection *currentTraitCollection = [UITraitCollection currentTraitCollection];
if (currentTraitCollection.displayScale > 1.0) {
fileName = [fileName stringByAppendingFormat:@"@%.fx", currentTraitCollection.displayScale];
}
fileName = [fileName stringByAppendingPathExtension:@"png"];
return fileName;
Expand Down

0 comments on commit 88e3913

Please sign in to comment.