mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
f21fa4ecb7
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.  ### 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
77 lines
2.6 KiB
Objective-C
77 lines
2.6 KiB
Objective-C
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import <React/RCTDefines.h>
|
|
|
|
#if RCT_DEV
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
@protocol RCTPackagerClientMethod;
|
|
@class RCTPackagerClientResponder;
|
|
|
|
typedef uint32_t RCTHandlerToken;
|
|
typedef void (^RCTNotificationHandler)(NSDictionary<NSString *, id> *);
|
|
typedef void (^RCTRequestHandler)(NSDictionary<NSString *, id> *, RCTPackagerClientResponder *);
|
|
typedef void (^RCTConnectedHandler)(void);
|
|
|
|
/** Encapsulates singleton connection to React Native packager. */
|
|
@interface RCTPackagerConnection : NSObject
|
|
|
|
+ (instancetype)sharedPackagerConnection;
|
|
|
|
/**
|
|
* Registers a handler for a notification broadcast from the packager. An
|
|
* example is "reload" - an instruction to reload from the packager.
|
|
* If multiple notification handlers are registered for the same method, they
|
|
* will all be invoked sequentially.
|
|
*/
|
|
- (RCTHandlerToken)addNotificationHandler:(RCTNotificationHandler)handler
|
|
queue:(dispatch_queue_t)queue
|
|
forMethod:(NSString *)method;
|
|
|
|
/**
|
|
* Registers a handler for a request from the packager. An example is
|
|
* pokeSamplingProfiler; it asks for profile data from the client.
|
|
* Only one handler can be registered for a given method; calling this
|
|
* displaces any previous request handler registered for that method.
|
|
*/
|
|
- (RCTHandlerToken)addRequestHandler:(RCTRequestHandler)handler
|
|
queue:(dispatch_queue_t)queue
|
|
forMethod:(NSString *)method;
|
|
|
|
/**
|
|
* Registers a handler that runs at most once, when the connection to the
|
|
* packager has been established. The handler will be dispatched immediately
|
|
* if the connection is already established.
|
|
*/
|
|
- (RCTHandlerToken)addConnectedHandler:(RCTConnectedHandler)handler
|
|
queue:(dispatch_queue_t)queue;
|
|
|
|
/** Removes a handler. Silently does nothing if the token is not valid. */
|
|
- (void)removeHandler:(RCTHandlerToken)token;
|
|
|
|
/** Disconnects and removes all handlers. */
|
|
- (void)stop;
|
|
|
|
/**
|
|
* Historically no distinction was made between notification and request
|
|
* handlers. If you use this method, it will be registered as *both* a
|
|
* notification handler *and* a request handler. You should migrate to the
|
|
* new block-based API instead.
|
|
*/
|
|
- (void)addHandler:(id<RCTPackagerClientMethod>)handler
|
|
forMethod:(NSString *)method __deprecated_msg("Use addRequestHandler or addNotificationHandler instead");
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|
|
|
|
#endif
|