File tree Expand file tree Collapse file tree 8 files changed +170
-0
lines changed
nativemodule/core/platform/ios/ReactCommon
runtime/platform/ios/ReactCommon Expand file tree Collapse file tree 8 files changed +170
-0
lines changed Original file line number Diff line number Diff line change 22
22
@class RCTModuleRegistry;
23
23
@class RCTViewRegistry;
24
24
@class RCTCallableJSModules;
25
+ @class RCTRuntimeExecutionWrapper;
25
26
26
27
/* *
27
28
* The type of a block that is capable of sending a response to a bridged
@@ -150,6 +151,11 @@ RCT_EXTERN_C_END
150
151
*/
151
152
@property (nonatomic , weak , readonly ) RCTBridge *bridge RCT_DEPRECATED;
152
153
154
+ /* *
155
+ * A way to reference the RuntimeExecutor.
156
+ */
157
+ @property (nonatomic , readonly ) RCTRuntimeExecutionWrapper *runtimeExecutionWrapper;
158
+
153
159
/* *
154
160
* This property is deprecated. This selector used to support two functionalities.
155
161
*
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ @class RCTRuntimeExecution;
9
+
10
+ NS_ASSUME_NONNULL_BEGIN
11
+
12
+ /* *
13
+ Swift friendly wrapper of RCTRuntimeExecution.
14
+ */
15
+ @interface RCTRuntimeExecutionWrapper : NSObject
16
+
17
+ - (instancetype )init NS_UNAVAILABLE;
18
+ - (instancetype )initWithRuntimeExecution : (RCTRuntimeExecution *)runtimeExecution ;
19
+
20
+ - (RCTRuntimeExecution *)getRuntimeExecution ;
21
+
22
+ @end
23
+
24
+ NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ #import " RCTRuntimeExecutionWrapper.h"
9
+
10
+ @implementation RCTRuntimeExecutionWrapper {
11
+ RCTRuntimeExecution *_runtimeExecution;
12
+ }
13
+
14
+ #pragma mark - Initializer
15
+
16
+ - (instancetype )initWithRuntimeExecution : (RCTRuntimeExecution *)runtimeExecution
17
+ {
18
+ if (self = [super init ]) {
19
+ _runtimeExecution = runtimeExecution;
20
+ }
21
+
22
+ return self;
23
+ }
24
+
25
+ #pragma mark - Public API
26
+
27
+ - (RCTRuntimeExecution *)getRuntimeExecution
28
+ {
29
+ return _runtimeExecution;
30
+ }
31
+
32
+ @end
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ #import < jsi/jsi.h>
9
+
10
+ #import < ReactCommon/CallInvoker.h>
11
+
12
+ NS_ASSUME_NONNULL_BEGIN
13
+
14
+ typedef void (^RCTJSIRuntimeHandlingBlock)(facebook::jsi::Runtime &runtime);
15
+ typedef void (^RCTRuntimeExecutorBlock)(RCTJSIRuntimeHandlingBlock);
16
+
17
+ @interface RCTRuntimeExecution : NSObject
18
+
19
+ - (instancetype )init NS_UNAVAILABLE;
20
+
21
+ /* *
22
+ Initializes an object that wraps ways to access the RuntimeExecutor.
23
+
24
+ @param callInvoker A native-to-JS call invoker.
25
+ @param runtimeExecutorBlock A block that provides thread-safe access to jsi::runtime.
26
+ */
27
+ - (instancetype )initWithCallInvoker : (std::shared_ptr<facebook::react::CallInvoker>)callInvoker
28
+ runtimeExecutorBlock : (RCTRuntimeExecutorBlock)runtimeExecutorBlock NS_DESIGNATED_INITIALIZER;
29
+
30
+ - (std::shared_ptr<facebook::react::CallInvoker>)callInvoker ;
31
+
32
+ - (RCTRuntimeExecutorBlock)runtimeExecutorBlock ;
33
+
34
+ @end
35
+
36
+ NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ #import " RCTRuntimeExecution.h"
9
+
10
+ @implementation RCTRuntimeExecution {
11
+ std::shared_ptr<facebook::react::CallInvoker> _callInvoker;
12
+ RCTRuntimeExecutorBlock _runtimeExecutorBlock;
13
+ }
14
+
15
+ #pragma mark - Initializer
16
+
17
+ - (instancetype )initWithCallInvoker : (std::shared_ptr<facebook::react::CallInvoker>)callInvoker
18
+ runtimeExecutorBlock : (RCTRuntimeExecutorBlock)runtimeExecutorBlock
19
+ {
20
+ if (self = [super init ]) {
21
+ _callInvoker = callInvoker;
22
+ _runtimeExecutorBlock = [runtimeExecutorBlock copy ];
23
+ }
24
+
25
+ return self;
26
+ }
27
+
28
+ #pragma mark - Public API
29
+
30
+ - (std::shared_ptr<facebook::react::CallInvoker>)callInvoker
31
+ {
32
+ return _callInvoker;
33
+ }
34
+
35
+ - (RCTRuntimeExecutorBlock)runtimeExecutorBlock
36
+ {
37
+ return _runtimeExecutorBlock;
38
+ }
39
+
40
+ @end
Original file line number Diff line number Diff line change 15
15
#import < React/RCTTurboModuleRegistry.h>
16
16
#import < ReactCommon/RuntimeExecutor.h>
17
17
#import < ReactCommon/TurboModuleBinding.h>
18
+
19
+ #import " RCTRuntimeExecution.h"
18
20
#import " RCTTurboModule.h"
19
21
22
+ @class RCTTurboModuleManager;
23
+
20
24
@protocol RCTTurboModuleManagerDelegate <NSObject >
21
25
22
26
/* *
50
54
- (NSArray <id<RCTBridgeModule>> *)extraModulesForBridge : (RCTBridge *)bridge
51
55
__attribute((deprecated(" Please make all native modules returned from this method TurboModule-compatible." )));
52
56
57
+ - (void )turboModuleManager : (RCTTurboModuleManager *)turboModuleManager
58
+ handleRuntimeBlock : (RCTJSIRuntimeHandlingBlock)block ;
59
+
53
60
@end
54
61
55
62
@interface RCTTurboModuleManager : NSObject <RCTTurboModuleRegistry>
Original file line number Diff line number Diff line change 24
24
#import < React/RCTLog.h>
25
25
#import < React/RCTModuleData.h>
26
26
#import < React/RCTPerformanceLogger.h>
27
+ #import < React/RCTRuntimeExecutionWrapper.h>
27
28
#import < React/RCTUtils.h>
28
29
#import < ReactCommon/RuntimeExecutor.h>
29
30
#import < ReactCommon/TurboCxxModule.h>
@@ -676,6 +677,21 @@ - (BOOL)_shouldCreateObjCModule:(Class)moduleClass
676
677
}
677
678
}
678
679
680
+ if ([module respondsToSelector: @selector (runtimeExecutionWrapper )]) {
681
+ __weak __typeof (self) weakSelf = self;
682
+ RCTRuntimeExecution *runtimeExecution =
683
+ [[RCTRuntimeExecution alloc ] initWithCallInvoker: _jsInvoker
684
+ runtimeExecutorBlock: ^void (RCTJSIRuntimeHandlingBlock block) {
685
+ __strong __typeof (self) strongSelf = weakSelf;
686
+ if (strongSelf) {
687
+ [strongSelf->_delegate turboModuleManager: strongSelf handleRuntimeBlock: block];
688
+ }
689
+ }];
690
+ RCTRuntimeExecutionWrapper *runtimeExecutionWrapper =
691
+ [[RCTRuntimeExecutionWrapper alloc ] initWithRuntimeExecution: runtimeExecution];
692
+ [(id )module setValue: runtimeExecutionWrapper forKey: @" runtimeExecutionWrapper" ];
693
+ }
694
+
679
695
/* *
680
696
* Some modules need their own queues, but don't provide any, so we need to create it for them.
681
697
* These modules typically have the following:
Original file line number Diff line number Diff line change @@ -208,6 +208,15 @@ - (Class)getModuleClassFromName:(const char *)name
208
208
return nullptr ;
209
209
}
210
210
211
+ - (void )turboModuleManager : (RCTTurboModuleManager *)turboModuleManager
212
+ handleRuntimeBlock : (RCTJSIRuntimeHandlingBlock)block ;
213
+ {
214
+ if (_valid) {
215
+ RuntimeExecutor bufferedRuntimeExecutor = _reactInstance->getBufferedRuntimeExecutor ();
216
+ bufferedRuntimeExecutor ([=](jsi::Runtime &runtime) { block (runtime); });
217
+ }
218
+ }
219
+
211
220
#pragma mark - Private
212
221
213
222
- (void )_start
You can’t perform that action at this time.
0 commit comments