From 5c60904fbc0f30a5ea08ef65b92df64607ac27eb Mon Sep 17 00:00:00 2001
From: Alicia Drummond <7664112+FalseLobster@users.noreply.github.com>
Date: Tue, 23 Jul 2024 10:50:45 -0700
Subject: [PATCH] fix ci errors

---
 .../React/CoreModules/RCTRedBox.mm            | 125 +++---------------
 .../IntegrationTests/LayoutEventsTest.js      |   3 +-
 .../js/examples/FocusOnMount/FocusOnMount.js  |   1 +
 3 files changed, 19 insertions(+), 110 deletions(-)

diff --git a/packages/react-native/React/CoreModules/RCTRedBox.mm b/packages/react-native/React/CoreModules/RCTRedBox.mm
index 0ea706615078c7..6d43d0e8165aea 100644
--- a/packages/react-native/React/CoreModules/RCTRedBox.mm
+++ b/packages/react-native/React/CoreModules/RCTRedBox.mm
@@ -120,10 +120,12 @@ - (instancetype)initWithCustomButtonTitles:(NSArray<NSString *> *)customButtonTi
     _customButtonTitles = customButtonTitles;
     _customButtonHandlers = customButtonHandlers;
     
+#if TARGET_OS_OSX // [macOS
     _window = [[NSWindow alloc] initWithContentRect:NSZeroRect styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreBuffered defer:YES];
     _window.backgroundColor = [NSColor colorWithRed:0.8 green:0 blue:0 alpha:1];
     _window.animationBehavior = NSWindowAnimationBehaviorDocumentWindow;
     _window.contentViewController = self;
+#endif // macOS]
   }
 
   return self;
@@ -303,13 +305,16 @@ - (void)viewDidLoad
   [NSLayoutConstraint activateConstraints:@[
     [topBorder.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
     [topBorder.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
-    [topBorder.bottomAnchor constraintEqualToAnchor:buttonStackView.topAnchor],
-    [NSLayoutConstraint constraintWithItem:scrollView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1 constant:0],
-   [NSLayoutConstraint constraintWithItem:scrollView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:0],
-  [NSLayoutConstraint constraintWithItem:scrollView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1 constant:0],
-  [scrollView.bottomAnchor constraintEqualToAnchor:topBorder.topAnchor]
-   
+    [topBorder.bottomAnchor constraintEqualToAnchor:buttonStackView.topAnchor]
   ]];
+  
+#if TARGET_OS_OSX // [macOS
+  [NSLayoutConstraint activateConstraints:@[
+    [NSLayoutConstraint constraintWithItem:scrollView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeading multiplier:1 constant:0],
+    [NSLayoutConstraint constraintWithItem:scrollView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:0],
+    [NSLayoutConstraint constraintWithItem:scrollView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTrailing multiplier:1 constant:0],
+    [scrollView.bottomAnchor constraintEqualToAnchor:topBorder.topAnchor]]];
+#endif // macOS]
 }
 
 #if !TARGET_OS_OSX // [macOS]
@@ -435,7 +440,7 @@ - (void)showErrorMessage:(NSString *)message
   }
 }
 
-#if TARGET_OS_OSX // [macOS]
+#if TARGET_OS_OSX // [macOS
 - (void)showModal
 {
   NSModalSession session = [NSApp beginModalSessionForWindow:_window];
@@ -447,7 +452,7 @@ - (void)showModal
 
   [NSApp endModalSession:session];
 }
-#endif
+#endif // macOS]
 
 - (void)dismiss
 {
@@ -749,118 +754,22 @@ - (NSAttributedString *)attributedStringForRow:(NSUInteger)row
   return frameSource;
 }
 
-#endif // macoS]
-@end
-
-
-#if TARGET_OS_OSX
-@interface RCTRedBoxWindow : NSObject
-
-
-@property (nonatomic, weak) id<RCTRedBoxControllerActionDelegate> actionDelegate;
-
-@end
-
-@implementation RCTRedBoxWindow
-{
-  NSWindow *_window;
-  BOOL _visible;
-}
-
-- (instancetype)init
-{
-  if ((self = [super init])) {
 /*
-    NSButton *dismissButton = [[NSButton alloc] initWithFrame:NSZeroRect];
-    dismissButton.accessibilityIdentifier = @"redbox-dismiss";
-    dismissButton.translatesAutoresizingMaskIntoConstraints = NO;
-    dismissButton.target = self;
-    dismissButton.action = @selector(dismiss:);
-    [dismissButton setButtonType:NSButtonTypeMomentaryPushIn];
-    dismissButton.bezelStyle = NSBezelStyleRounded;
-    dismissButton.title = @"Dismiss (Esc)";
-    dismissButton.keyEquivalent = @"\e";
-    [dismissButton setContentCompressionResistancePriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationHorizontal];
-
-    NSButton *reloadButton = [[NSButton alloc] initWithFrame:NSZeroRect];
-    reloadButton.accessibilityIdentifier = @"redbox-reload";
-    reloadButton.translatesAutoresizingMaskIntoConstraints = NO;
-    reloadButton.target = self;
-    reloadButton.action = @selector(reload:);
-    reloadButton.bezelStyle = NSBezelStyleRounded;
-    reloadButton.title = @"Reload JS (\u2318R)";
-    [reloadButton setButtonType:NSButtonTypeMomentaryPushIn];
-    reloadButton.keyEquivalent = @"r";
-    reloadButton.keyEquivalentModifierMask = NSEventModifierFlagCommand;
-    [reloadButton setContentCompressionResistancePriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationHorizontal];
-    [reloadButton setContentCompressionResistancePriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical];
-
-    NSButton *copyButton = [[NSButton alloc] initWithFrame:NSZeroRect];
-    copyButton.accessibilityIdentifier = @"redbox-copy";
-    copyButton.translatesAutoresizingMaskIntoConstraints = NO;
-    copyButton.target = self;
-    copyButton.action = @selector(copyStack:);
-    copyButton.title = @"Copy (\u2325\u2318C)";
-    copyButton.bezelStyle = NSBezelStyleRounded;
-    [copyButton setButtonType:NSButtonTypeMomentaryPushIn];
-    copyButton.keyEquivalent = @"c";
-    copyButton.keyEquivalentModifierMask = NSEventModifierFlagOption | NSEventModifierFlagCommand;
-    [copyButton setContentCompressionResistancePriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationHorizontal];
-
-    NSView *contentView = _window.contentView;
-    [contentView addSubview:scrollView];
-    [contentView addSubview:dismissButton];
-    [contentView addSubview:reloadButton];
-    [contentView addSubview:copyButton];
-
-    [NSLayoutConstraint activateConstraints:@[
-      // the window shouldn't be any bigger than 375x643 points
-      [NSLayoutConstraint constraintWithItem:contentView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:375],
-      [NSLayoutConstraint constraintWithItem:contentView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:643],
-      // scroll view hugs the left, top, and right sides of the window, and the buttons at the bottom
-      [NSLayoutConstraint constraintWithItem:scrollView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:contentView attribute:NSLayoutAttributeLeading multiplier:1 constant:16],
-      [NSLayoutConstraint constraintWithItem:scrollView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:contentView attribute:NSLayoutAttributeTop multiplier:1 constant:16],
-      [NSLayoutConstraint constraintWithItem:scrollView attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:contentView attribute:NSLayoutAttributeTrailing multiplier:1 constant:-16],
-      [NSLayoutConstraint constraintWithItem:scrollView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:reloadButton attribute:NSLayoutAttributeTop multiplier:1 constant:-8],
-      // buttons have equal widths
-      [NSLayoutConstraint constraintWithItem:dismissButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:reloadButton attribute:NSLayoutAttributeWidth multiplier:1 constant:0],
-      [NSLayoutConstraint constraintWithItem:dismissButton attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:copyButton attribute:NSLayoutAttributeWidth multiplier:1 constant:0],
-      // buttons are centered horizontally in the window
-      [NSLayoutConstraint constraintWithItem:dismissButton attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:contentView attribute:NSLayoutAttributeLeading multiplier:1 constant:16],
-      [NSLayoutConstraint constraintWithItem:copyButton attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationLessThanOrEqual toItem:contentView attribute:NSLayoutAttributeTrailing multiplier:1 constant:-16],
-      [NSLayoutConstraint constraintWithItem:dismissButton attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:reloadButton attribute:NSLayoutAttributeLeading multiplier:1 constant:-8],
-      [NSLayoutConstraint constraintWithItem:reloadButton attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:contentView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0],
-      [NSLayoutConstraint constraintWithItem:copyButton attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:reloadButton attribute:NSLayoutAttributeTrailing multiplier:1 constant:8],
-      // buttons are baseline aligned
-      [NSLayoutConstraint constraintWithItem:dismissButton attribute:NSLayoutAttributeBaseline relatedBy:NSLayoutRelationEqual toItem:reloadButton attribute:NSLayoutAttributeBaseline multiplier:1 constant:0],
-      [NSLayoutConstraint constraintWithItem:dismissButton attribute:NSLayoutAttributeBaseline relatedBy:NSLayoutRelationEqual toItem:copyButton attribute:NSLayoutAttributeBaseline multiplier:1 constant:0],
-      // buttons appear at the bottom of the window
-      [NSLayoutConstraint constraintWithItem:reloadButton attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:contentView attribute:NSLayoutAttributeBottom multiplier:1 constant:-16],
-    ]];
- */
-  }
-  return self;
-}
-
 - (void)dealloc
 {
   // VSO#1878643: On macOS the RedBox can be dealloc'd on the JS thread causing the Main Thread Checker to throw when the NSTableView properties below are accessed.
-  /* NSTableView *stackTraceTableView = _stackTraceTableView;
+  NSTableView *stackTraceTableView = _stackTraceTableView;
   RCTUnsafeExecuteOnMainQueueSync(^{
     stackTraceTableView.dataSource = nil;
     stackTraceTableView.delegate = nil;
   });
-   TBD */
+   
 }
+TBD */
 
-
-
-
-
+#endif // macoS]
 @end
 
-#endif // macOS]
-
 @interface RCTRedBox () <
     RCTInvalidating,
     RCTRedBoxControllerActionDelegate,
diff --git a/packages/rn-tester/IntegrationTests/LayoutEventsTest.js b/packages/rn-tester/IntegrationTests/LayoutEventsTest.js
index 43a40c5b994722..b6db62f521c6d2 100644
--- a/packages/rn-tester/IntegrationTests/LayoutEventsTest.js
+++ b/packages/rn-tester/IntegrationTests/LayoutEventsTest.js
@@ -10,7 +10,6 @@
 
 'use strict';
 
-const {Platform} = ReactNative; // [macOS]
 import type {ViewStyleProp} from 'react-native/Libraries/StyleSheet/StyleSheet';
 import type {
   Layout,
@@ -21,7 +20,7 @@ const React = require('react');
 const ReactNative = require('react-native');
 const deepDiffer = require('react-native/Libraries/Utilities/differ/deepDiffer');
 
-const {Image, LayoutAnimation, StyleSheet, Text, View} = ReactNative;
+const {Image, LayoutAnimation, Platform, StyleSheet, Text, View} = ReactNative; // [macOS Platform]
 const {TestModule} = ReactNative.NativeModules;
 function debug(...args: Array<void | Layout | string>) {
   // console.log.apply(null, arguments);
diff --git a/packages/rn-tester/js/examples/FocusOnMount/FocusOnMount.js b/packages/rn-tester/js/examples/FocusOnMount/FocusOnMount.js
index 0e3f6efa3cdf6c..757cd82d3c9f16 100644
--- a/packages/rn-tester/js/examples/FocusOnMount/FocusOnMount.js
+++ b/packages/rn-tester/js/examples/FocusOnMount/FocusOnMount.js
@@ -22,6 +22,7 @@ class FocusOnMountExample extends React.Component<{}> {
       const commands = UIManager.getViewManagerConfig('RCTView').Commands;
       if ('focus' in commands) {
         UIManager.dispatchViewManagerCommand(
+          // $FlowFixMe
           findNodeHandle(this.ref.current),
           UIManager.getViewManagerConfig('RCTView').Commands.focus,
           undefined,