Skip to content

Commit 8a6139a

Browse files
Revert "delete RCTUIUtils (#49453)"
This reverts commit 49b7ce0.
1 parent c6b099e commit 8a6139a

File tree

3 files changed

+72
-16
lines changed

3 files changed

+72
-16
lines changed

packages/react-native/React/CoreModules/RCTDeviceInfo.mm

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#import <React/RCTEventDispatcherProtocol.h>
1515
#import <React/RCTInitializing.h>
1616
#import <React/RCTInvalidating.h>
17+
#import <React/RCTUIUtils.h>
1718
#import <React/RCTUtils.h>
1819
#import <atomic>
1920

@@ -174,25 +175,20 @@ static BOOL RCTIsIPhoneNotched()
174175
static NSDictionary *RCTExportedDimensions(CGFloat fontScale)
175176
{
176177
RCTAssertMainQueue();
177-
UIScreen *mainScreen = UIScreen.mainScreen;
178-
CGSize screenSize = mainScreen.bounds.size;
179-
UIView *mainWindow = RCTKeyWindow();
180-
181-
// We fallback to screen size if a key window is not found.
182-
CGSize windowSize = mainWindow ? mainWindow.bounds.size : screenSize;
183-
178+
RCTDimensions dimensions = RCTGetDimensions(fontScale);
179+
__typeof(dimensions.window) window = dimensions.window;
184180
NSDictionary<NSString *, NSNumber *> *dimsWindow = @{
185-
@"width" : @(windowSize.width),
186-
@"height" : @(windowSize.height),
187-
@"scale" : @(mainScreen.scale),
188-
@"fontScale" : @(fontScale)
181+
@"width" : @(window.width),
182+
@"height" : @(window.height),
183+
@"scale" : @(window.scale),
184+
@"fontScale" : @(window.fontScale)
189185
};
190-
186+
__typeof(dimensions.screen) screen = dimensions.screen;
191187
NSDictionary<NSString *, NSNumber *> *dimsScreen = @{
192-
@"width" : @(screenSize.width),
193-
@"height" : @(screenSize.height),
194-
@"scale" : @(mainScreen.scale),
195-
@"fontScale" : @(fontScale)
188+
@"width" : @(screen.width),
189+
@"height" : @(screen.height),
190+
@"scale" : @(screen.scale),
191+
@"fontScale" : @(screen.fontScale)
196192
};
197193
return @{@"window" : dimsWindow, @"screen" : dimsScreen};
198194
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <CoreGraphics/CoreGraphics.h>
9+
#import <Foundation/Foundation.h>
10+
#import <UIKit/UIKit.h>
11+
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
// Get window and screen dimensions
19+
typedef struct {
20+
struct {
21+
CGFloat width, height, scale, fontScale;
22+
} window, screen;
23+
} RCTDimensions;
24+
extern __attribute__((visibility("default"))) RCTDimensions RCTGetDimensions(CGFloat fontScale);
25+
26+
#ifdef __cplusplus
27+
}
28+
#endif
29+
30+
NS_ASSUME_NONNULL_END
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import "RCTUIUtils.h"
9+
10+
#import "RCTUtils.h"
11+
12+
RCTDimensions RCTGetDimensions(CGFloat fontScale)
13+
{
14+
UIScreen *mainScreen = UIScreen.mainScreen;
15+
CGSize screenSize = mainScreen.bounds.size;
16+
17+
UIView *mainWindow = RCTKeyWindow();
18+
// We fallback to screen size if a key window is not found.
19+
CGSize windowSize = mainWindow ? mainWindow.bounds.size : screenSize;
20+
21+
RCTDimensions result;
22+
typeof(result.screen) dimsScreen = {
23+
.width = screenSize.width, .height = screenSize.height, .scale = mainScreen.scale, .fontScale = fontScale};
24+
typeof(result.window) dimsWindow = {
25+
.width = windowSize.width, .height = windowSize.height, .scale = mainScreen.scale, .fontScale = fontScale};
26+
result.screen = dimsScreen;
27+
result.window = dimsWindow;
28+
29+
return result;
30+
}

0 commit comments

Comments
 (0)