Skip to content

Commit

Permalink
feat(iOS) remove deprecated [UIScreen mainScreen] references (faceboo…
Browse files Browse the repository at this point in the history
…k#41388)

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

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

Pull Request resolved: facebook#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 Saadnajmi committed Jan 10, 2024
1 parent 6e633a1 commit 8e7065e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 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 @@ -141,13 +141,11 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo
self->_showDate = [NSDate date];
if (!self->_window && !RCTRunningInTestEnvironment()) {
#if !TARGET_OS_OSX // [macOS]
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 @@ -240,14 +240,15 @@ - (NSString *)_fileNameForSelector:(SEL)selector
if (0 < identifier.length) {
fileName = [fileName stringByAppendingFormat:@"_%@", identifier];
}
CGFloat scale; // [macOS
#if !TARGET_OS_OSX
scale = [[UIScreen mainScreen] scale];
#else
#if !TARGET_OS_OSX // [macOS]
UITraitCollection *currentTraitCollection = [UITraitCollection currentTraitCollection];
if (currentTraitCollection.displayScale > 1.0) {
fileName = [fileName stringByAppendingFormat:@"@%.fx", currentTraitCollection.displayScale];
#else // [macOS
scale = [[NSScreen mainScreen] backingScaleFactor];
#endif
if (scale > 1.0) { // macOS]
if (scale > 1.0) {
fileName = [fileName stringByAppendingFormat:@"@%.fx", scale];
#endif // macOS]
}
fileName = [fileName stringByAppendingPathExtension:@"png"];
return fileName;
Expand Down

0 comments on commit 8e7065e

Please sign in to comment.