react-native-macos/React/CoreModules
Andy Matuschak f21fa4ecb7 Enabling RCTWebSocket on UIKitForMac (macOS Catalyst) (#27469)
Summary:
In https://github.com/facebook/react-native/issues/25427, radex added initial support for running React Native projects on macOS via Catalyst. However, `RCTWebSocket` was disabled for that target because of some compilation issues. This meant that running projects via a connection to the packager wasn't possible: no live reload, and projects must be run in "Release" mode. It also meant making manual changes to Xcode projects deploying to macOS and scattering a number of conditional checks throughout the codebase.

In this change, I've implemented support for `RCTWebSocket` on the macOS target and re-enabled the affected features. Live reload and the inspector now work for macOS targets. Manual modifications of Xcode build settings are no longer necessary for react-native projects running on macOS.

![Screen Shot 2019-12-10 at 8 36 38 AM](https://user-images.githubusercontent.com/2771/70549905-ce7b0800-1b29-11ea-85c6-07bf09811ae2.png)

### Limitations

There's no binding which displays the developer menu (since there's no shake event on macOS). We'll probably want to add one, perhaps to the menu bar.

I've chosen not to commit the modifications to RNTester which enable macOS support, since that would imply more "official" support for this target than I suspect you all would like to convey. I'm happy to add those chunks if it would be helpful.

## Changelog

[iOS] [Added] - Added web socket support for macOS (Catalyst), enabling debug builds and live reload
Pull Request resolved: https://github.com/facebook/react-native/pull/27469

Test Plan:
* Open RNTester/RNTester.xcodeproj with Xcode 11.2.1, run it like a normal iOS app -- make sure it compiles and runs correctly (no regression)
* Select "My Mac" as device target, and run. You may need to configure a valid development team to make signing work.
* RNTester should run fine with no additional configuration. Modify a file in RNTester, note that live reload is now working.
* Test the developer inspector. To display the developer menu, you'll need to manually show it; here's an example diff which does that:
```
 diff --git a/RNTester/js/RNTesterApp.ios.js b/RNTester/js/RNTesterApp.ios.js
index 8245a68d12..a447ad3b1b 100644
 --- a/RNTester/js/RNTesterApp.ios.js
+++ b/RNTester/js/RNTesterApp.ios.js
@@ -19,6 +19,8 @@ const React = require('react');
 const SnapshotViewIOS = require('./examples/Snapshot/SnapshotViewIOS.ios');
 const URIActionMap = require('./utils/URIActionMap');

+import NativeDevMenu from '../../Libraries/NativeModules/specs/NativeDevMenu';
+
 const {
   AppRegistry,
   AsyncStorage,
@@ -143,6 +145,7 @@ class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {

   UNSAFE_componentWillMount() {
     BackHandler.addEventListener('hardwareBackPress', this._handleBack);
+    NativeDevMenu.show();
   }

   componentDidMount() {
```

Reviewed By: sammy-SC

Differential Revision: D18945861

Pulled By: hramos

fbshipit-source-id: edcf02c5803742c89a845a3e5d72bc7dacae839f
2019-12-17 16:52:29 -08:00
..
BUCK Add NativeLogBox module on iOS 2019-12-10 02:31:37 -08:00
CoreModulesPlugins.h Add NativeLogBox module on iOS 2019-12-10 02:31:37 -08:00
CoreModulesPlugins.mm Add NativeLogBox module on iOS 2019-12-10 02:31:37 -08:00
RCTAccessibilityManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTAccessibilityManager.mm Remove unneeded NSNotification center removeObserver 2019-11-04 10:19:30 -08:00
RCTActionSheetManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTActionSheetManager.mm Fix Share dialog not resolving promise when dismissed on iOS (#26842) 2019-10-28 16:24:16 -07:00
RCTAlertManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTAlertManager.mm Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTAppState.h Make RCTAppState TurboModule-compatible 2019-11-01 12:06:21 -07:00
RCTAppState.mm Make RCTAppState TurboModule-compatible 2019-11-01 12:06:21 -07:00
RCTAppearance.h emit Dimensions change enent when app goes split screen 2019-12-11 10:04:20 -08:00
RCTAppearance.mm emit Dimensions change enent when app goes split screen 2019-12-11 10:04:20 -08:00
RCTAsyncLocalStorage.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTAsyncLocalStorage.mm Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTClipboard.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTClipboard.mm Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTDevMenu.h Make RCTDevMenu and RCTDevSettings TurboModule-compatible 2019-11-04 16:07:23 -08:00
RCTDevMenu.mm Enabling RCTWebSocket on UIKitForMac (macOS Catalyst) (#27469) 2019-12-17 16:52:29 -08:00
RCTDevSettings.h Make RCTDevMenu and RCTDevSettings TurboModule-compatible 2019-11-04 16:07:23 -08:00
RCTDevSettings.mm Enabling RCTWebSocket on UIKitForMac (macOS Catalyst) (#27469) 2019-12-17 16:52:29 -08:00
RCTDeviceInfo.h Remove unneeded NSNotification center removeObserver 2019-11-04 10:19:30 -08:00
RCTDeviceInfo.mm emit Dimensions change enent when app goes split screen 2019-12-11 10:04:20 -08:00
RCTExceptionsManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTExceptionsManager.mm LogBox - Don't show native redbox for JS errors 2019-10-31 16:26:42 -07:00
RCTFPSGraph.h Make RCTPerfMonitor TurboModule-compatible 2019-11-01 12:06:21 -07:00
RCTFPSGraph.m Fix podspecs 2019-11-01 19:34:46 -07:00
RCTI18nManager.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTI18nManager.mm Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTKeyboardObserver.h Make RCTKeyboardObserver TurboModule-compatible 2019-11-01 12:06:20 -07:00
RCTKeyboardObserver.mm Make RCTKeyboardObserver TurboModule-compatible 2019-11-01 12:06:20 -07:00
RCTLogBox.h Add NativeLogBox module on iOS 2019-12-10 02:31:37 -08:00
RCTLogBox.mm iOS Logbox: always return a turbomodule instance 2019-12-16 15:04:27 -08:00
RCTPerfMonitor.mm Make RCTPerfMonitor TurboModule-compatible 2019-11-01 12:06:21 -07:00
RCTPlatform.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTPlatform.mm Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTRedBox.h Make RedBox TurboModule-compatible 2019-11-04 16:07:23 -08:00
RCTRedBox.mm Make RedBox TurboModule-compatible 2019-11-04 16:07:23 -08:00
RCTSourceCode.h Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTSourceCode.mm Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
RCTStatusBarManager.h Make RCTStatusBarManager TurboModule-compatible 2019-11-01 12:06:20 -07:00
RCTStatusBarManager.mm Add requiresMainQueueSetup YES to top offenders 2019-12-04 07:48:54 -08:00
RCTTVNavigationEventEmitter.h Make RCTTVNavigationEventEmitter TurboModule-compatible 2019-11-04 16:07:24 -08:00
RCTTVNavigationEventEmitter.mm Make RCTTVNavigationEventEmitter TurboModule-compatible 2019-11-04 16:07:24 -08:00
RCTTiming.h Make RCTTiming TurboModule-compatible 2019-10-16 19:00:26 -07:00
RCTTiming.mm Make RCTTiming a regular NativeModule 2019-11-08 17:28:23 -08:00
RCTWebSocketExecutor.h Make RCTWebSocketModule TurboModule-compatible 2019-11-08 14:14:46 -08:00
RCTWebSocketExecutor.mm Make RCTWebSocketModule TurboModule-compatible 2019-11-08 14:14:46 -08:00
RCTWebSocketModule.h Make RCTWebSocketModule TurboModule-compatible 2019-11-08 14:14:46 -08:00
RCTWebSocketModule.mm Make RCTWebSocketModule TurboModule-compatible 2019-11-08 14:14:46 -08:00
React-CoreModules.podspec Move non-license comments out of license header 2019-10-15 20:12:12 -07:00