Skip to content

Commit

Permalink
move registerSegmentWithId: to internal APIs (#37398)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #37398

Changelog: [Internal]

in this diff, i introduce an internal category and header for RCTHost for functionality that needs to be accessible for our purposes, but not an official part of our stable API.

after this change, we can remove `ReactInstanceForwarding`.

Reviewed By: cipolleschi

Differential Revision: D45760091

fbshipit-source-id: 88a82fc70a20934f5d8989041c3eb2ffe2d27b20
  • Loading branch information
philIip authored and facebook-github-bot committed May 11, 2023
1 parent 0ccc98d commit 2668f50
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#import "RCTHost.h"

@interface RCTHost (Internal)

- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ typedef std::shared_ptr<facebook::react::JSEngineInstance> (^RCTHostJSEngineProv
* RCTHost is long lived, while an instance may be deallocated and re-initialized. Some examples of when this happens:
* CMD+R reload in DEV or a JS crash. The host should be the single owner of an RCTInstance.
*/
@interface RCTHost : NSObject <ReactInstanceForwarding>
@interface RCTHost : NSObject

- (instancetype)initWithHostDelegate:(id<RCTHostDelegate>)hostDelegate
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#import "RCTHost.h"
#import "RCTHost+Internal.h"

#import <PikaOptimizationsMacros/PikaOptimizationsMacros.h>
#import <React/RCTAssert.h>
Expand Down Expand Up @@ -238,15 +239,6 @@ - (void)didReceiveReloadCommand
}
}

// TODO (T74233481) - Should raw instance be accessed in this class like this? These functions shouldn't be called very
// early in startup, but could add some intelligent guards here.
#pragma mark - ReactInstanceForwarding

- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path
{
[_instance registerSegmentWithId:segmentId path:path];
}

- (void)dealloc
{
[_instance invalidate];
Expand All @@ -259,6 +251,13 @@ - (void)dealloc
return [_hostDelegate createContextContainer];
}

#pragma mark - Internal

- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path
{
[_instance registerSegmentWithId:segmentId path:path];
}

#pragma mark - Private
- (void)_refreshBundleURL FB_OBJC_DIRECT
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,14 @@ FB_RUNTIME_PROTOCOL

@end

/**
* A set of functions which are forwarded through RCTHost, RCTInstance to ReactInstance.
*/
@protocol ReactInstanceForwarding

/**
* Registers a new JS segment.
*/
- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path;

@end

typedef void (^_Null_unspecified RCTInstanceInitialBundleLoadCompletionBlock)();

/**
* RCTInstance owns and manages most of the pieces of infrastructure required to display a screen powered by React
* Native. RCTInstance should never be instantiated in product code, but rather accessed through RCTHost. The host
* ensures that any access to the instance is safe, and manages instance lifecycle.
*/
@interface RCTInstance : NSObject <ReactInstanceForwarding>
@interface RCTInstance : NSObject

- (instancetype)initWithDelegate:(id<RCTInstanceDelegate>)delegate
jsEngineInstance:(std::shared_ptr<facebook::react::JSEngineInstance>)jsEngineInstance
Expand All @@ -73,6 +61,8 @@ typedef void (^_Null_unspecified RCTInstanceInitialBundleLoadCompletionBlock)();

- (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args;

- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path;

- (void)invalidate;

@property (nonatomic, readonly, strong) RCTSurfacePresenter *surfacePresenter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ - (void)invalidate
}];
}

- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path
{
if (_valid) {
_reactInstance->registerSegment(static_cast<uint32_t>([segmentId unsignedIntValue]), path.UTF8String);
}
}

#pragma mark - RCTTurboModuleManagerDelegate

- (Class)getModuleClassFromName:(const char *)name
Expand Down Expand Up @@ -197,15 +204,6 @@ - (Class)getModuleClassFromName:(const char *)name
return nullptr;
}

#pragma mark - ReactInstanceForwarding

- (void)registerSegmentWithId:(NSNumber *)segmentId path:(NSString *)path
{
if (_valid) {
_reactInstance->registerSegment(static_cast<uint32_t>([segmentId unsignedIntValue]), path.UTF8String);
}
}

#pragma mark - Private

- (void)_start
Expand Down

0 comments on commit 2668f50

Please sign in to comment.