/
ShimRCTInstance.mm
76 lines (65 loc) · 2.53 KB
/
ShimRCTInstance.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* 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 "ShimRCTInstance.h"
#import <ReactCommon/RCTInstance.h>
#import "RCTSwizzleHelpers.h"
static __weak ShimRCTInstance *weakShim = nil;
@implementation ShimRCTInstance
- (instancetype)init
{
if (self = [super init]) {
_initCount = 0;
RCTSwizzleInstanceSelector(
[RCTInstance class],
[ShimRCTInstance class],
@selector(initWithDelegate:
jsRuntimeFactory:bundleManager:turboModuleManagerDelegate:onInitialBundleLoad:moduleRegistry
:parentInspectorTarget:launchOptions:));
RCTSwizzleInstanceSelector([RCTInstance class], [ShimRCTInstance class], @selector(invalidate));
RCTSwizzleInstanceSelector(
[RCTInstance class], [ShimRCTInstance class], @selector(callFunctionOnJSModule:method:args:));
weakShim = self;
}
return self;
}
- (void)reset
{
RCTSwizzleInstanceSelector(
[RCTInstance class],
[ShimRCTInstance class],
@selector(initWithDelegate:
jsRuntimeFactory:bundleManager:turboModuleManagerDelegate:onInitialBundleLoad:moduleRegistry
:parentInspectorTarget:launchOptions:));
RCTSwizzleInstanceSelector([RCTInstance class], [ShimRCTInstance class], @selector(invalidate));
RCTSwizzleInstanceSelector(
[RCTInstance class], [ShimRCTInstance class], @selector(callFunctionOnJSModule:method:args:));
_initCount = 0;
_invalidateCount = 0;
}
- (instancetype)initWithDelegate:(id<RCTInstanceDelegate>)delegate
jsRuntimeFactory:(std::shared_ptr<facebook::react::JSRuntimeFactory>)jsRuntimeFactory
bundleManager:(RCTBundleManager *)bundleManager
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)tmmDelegate
onInitialBundleLoad:(RCTInstanceInitialBundleLoadCompletionBlock)onInitialBundleLoad
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
parentInspectorTarget:(facebook::react::jsinspector_modern::HostTarget *)parentInspectorTarget
launchOptions:(NSDictionary *)launchOptions
{
weakShim.initCount++;
return self;
}
- (void)invalidate
{
weakShim.invalidateCount++;
}
- (void)callFunctionOnJSModule:(NSString *)moduleName method:(NSString *)method args:(NSArray *)args
{
weakShim.jsModuleName = moduleName;
weakShim.method = method;
weakShim.args = [args copy];
}
@end