Skip to content

Commit

Permalink
Merge branch 'main' into frameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
Saadnajmi authored Nov 7, 2023
2 parents 34e99a0 + d1ed53d commit ea67fa9
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .ado/variables/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ variables:
VmImageApple: macOS-13
slice_name: 'Xcode_15.0'
xcode_version: '/Applications/Xcode_15.0.app'
ios_version: '17.0'
ios_version: '17.0.1'
ios_simulator: 'iPhone 15'
2 changes: 2 additions & 0 deletions packages/react-native/React/Base/RCTUIKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,10 @@ NS_ASSUME_NONNULL_END

#if !TARGET_OS_OSX
typedef UIApplication RCTUIApplication;
typedef UIWindow RCTUIWindow;
#else
typedef NSApplication RCTUIApplication;
typedef NSWindow RCTUIWindow;
#endif

//
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/React/Base/RCTUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ RCT_EXTERN BOOL RCTRunningInAppExtension(void);
#endif // [macOS]

// Returns the shared UIApplication instance, or nil if running in an App Extension
RCT_EXTERN UIApplication *__nullable RCTSharedApplication(void);
RCT_EXTERN RCTUIApplication *__nullable RCTSharedApplication(void); // [macOS]

#if !TARGET_OS_OSX // [macOS]
// Returns the current main window, useful if you need to access the root view
// or view controller
RCT_EXTERN UIWindow *__nullable RCTKeyWindow(void);
RCT_EXTERN RCTUIWindow *__nullable RCTKeyWindow(void); // [macOS]

#if !TARGET_OS_OSX // [macOS]
// Returns the presented view controller, useful if you need
// e.g. to present a modal view controller or alert over it
RCT_EXTERN UIViewController *__nullable RCTPresentedViewController(void);
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/React/Base/RCTUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ BOOL RCTRunningInAppExtension(void)
}
#endif // [macOS]

UIApplication *__nullable RCTSharedApplication(void)
RCTUIApplication *__nullable RCTSharedApplication(void) // [macOS]
{
#if !TARGET_OS_OSX // [macOS]
if (RCTRunningInAppExtension()) {
Expand All @@ -593,7 +593,7 @@ BOOL RCTRunningInAppExtension(void)
#endif // macOS]
}

RCTPlatformWindow *__nullable RCTKeyWindow(void) // [macOS]
RCTUIWindow *__nullable RCTKeyWindow(void) // [macOS]
{
#if !TARGET_OS_OSX // [macOS]
if (RCTRunningInAppExtension()) {
Expand Down
18 changes: 5 additions & 13 deletions packages/react-native/React/CoreModules/RCTDeviceInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,10 @@ static BOOL RCTIsIPhoneNotched()
}


#if !TARGET_OS_OSX // [macOS]
NSDictionary *RCTExportedDimensions(CGFloat fontScale)
#else // [macOS
static NSDictionary *RCTExportedDimensions(RCTPlatformView *rootView)
#endif // macOS]
static NSDictionary *RCTExportedDimensions(CGFloat fontScale)
{
RCTAssertMainQueue();
#if !TARGET_OS_OSX // [macOS]
RCTDimensions dimensions = RCTGetDimensions(fontScale);
#else // [macOS
RCTDimensions dimensions = RCTGetDimensions(rootView);
#endif // macOS]
__typeof(dimensions.window) window = dimensions.window;
NSDictionary<NSString *, NSNumber *> *dimsWindow = @{
@"width" : @(window.width),
Expand All @@ -144,13 +136,13 @@ - (NSDictionary *)_exportedDimensions
RCTAccessibilityManager *accessibilityManager =
(RCTAccessibilityManager *)[_moduleRegistry moduleForName:"AccessibilityManager"];
RCTAssert(accessibilityManager, @"Failed to get exported dimensions: AccessibilityManager is nil");
CGFloat fontScale = accessibilityManager ? accessibilityManager.multiplier : 1.0;
#if !TARGET_OS_OSX // [macOS]
return RCTExportedDimensions(fontScale);
CGFloat fontScale = accessibilityManager ? accessibilityManager.multiplier : 1.0;
#else // [macOS
// TODO: Saad - get root view here
return RCTExportedDimensions(nil);
CGFloat fontScale = 1.0;
#endif // macOS]

return RCTExportedDimensions(fontScale);
}

- (NSDictionary<NSString *, id> *)constantsToExport
Expand Down
4 changes: 0 additions & 4 deletions packages/react-native/React/UIUtils/RCTUIUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ typedef struct {
} window, screen;
} RCTDimensions;
extern __attribute__((visibility("default")))
#if !TARGET_OS_OSX // [macOS]
RCTDimensions RCTGetDimensions(CGFloat fontScale);
#else // [macOS
RCTDimensions RCTGetDimensions(RCTPlatformView *rootView);
#endif // macOS]

#ifdef __cplusplus
}
Expand Down
31 changes: 9 additions & 22 deletions packages/react-native/React/UIUtils/RCTUIUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@

#import "RCTUtils.h"

#if !TARGET_OS_OSX // [macOS]
RCTDimensions RCTGetDimensions(CGFloat fontScale)
#else // [macOS
RCTDimensions RCTGetDimensions(RCTPlatformView *rootView)
#endif // macOS]
{
#if !TARGET_OS_OSX // [macOS]
UIScreen *mainScreen = UIScreen.mainScreen;
Expand All @@ -24,20 +20,11 @@ RCTDimensions RCTGetDimensions(RCTPlatformView *rootView)
// We fallback to screen size if a key window is not found.
CGSize windowSize = mainWindow ? mainWindow.bounds.size : screenSize;
#else // [macOS
NSWindow *window = nil;
NSSize windowSize;
NSSize screenSize;
if (rootView != nil) {
window = [rootView window];
windowSize = [window frame].size;
} else {
// We don't have a root view so fall back to the app's key window
window = [NSApp keyWindow];
windowSize = [window frame].size;
}
screenSize = [[window screen] frame].size;
#endif

RCTUIWindow *window = RCTKeyWindow();
NSSize windowSize = window ? [window frame].size : CGSizeMake(0, 0);
NSSize screenSize = window ? [[window screen] frame].size : CGSizeMake(0, 0);
CGFloat scale = window ? [[window screen] backingScaleFactor] : 1.0; // Default scale to 1.0 if window is nil
#endif // macOS
RCTDimensions result;
#if !TARGET_OS_OSX // [macOS]
typeof(result.screen) dimsScreen = {
Expand All @@ -48,13 +35,13 @@ RCTDimensions RCTGetDimensions(RCTPlatformView *rootView)
typeof(result.screen) dimsScreen = {
.width = screenSize.width,
.height = screenSize.height,
.scale = [[window screen] backingScaleFactor],
.fontScale = 1};
.scale = scale,
.fontScale = fontScale};
typeof(result.window) dimsWindow = {
.width = windowSize.width,
.height = windowSize.height,
.scale = [[window screen] backingScaleFactor],
.fontScale = 1};
.scale = scale,
.fontScale = fontScale};
#endif // macOS]
result.screen = dimsScreen;
result.window = dimsWindow;
Expand Down
23 changes: 14 additions & 9 deletions packages/react-native/React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1492,16 +1492,21 @@ - (BOOL)acceptsFirstResponder

- (void)updateTrackingAreas
{
if (_trackingArea) {
[self removeTrackingArea:_trackingArea];
}
BOOL hasMouseHoverEvent = self.onMouseEnter || self.onMouseLeave;
BOOL wouldRecreateIdenticalTrackingArea = hasMouseHoverEvent && _trackingArea && NSEqualRects(self.bounds, [_trackingArea rect]);

if (!wouldRecreateIdenticalTrackingArea) {
if (_trackingArea) {
[self removeTrackingArea:_trackingArea];
}

if (self.onMouseEnter || self.onMouseLeave) {
_trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
options:NSTrackingActiveAlways|NSTrackingMouseEnteredAndExited
owner:self
userInfo:nil];
[self addTrackingArea:_trackingArea];
if (hasMouseHoverEvent) {
_trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds
options:NSTrackingActiveAlways|NSTrackingMouseEnteredAndExited
owner:self
userInfo:nil];
[self addTrackingArea:_trackingArea];
}
}

[super updateTrackingAreas];
Expand Down

0 comments on commit ea67fa9

Please sign in to comment.