@@ -101,70 +101,25 @@ static bool isRAMBundle(NSData *script) {
101
101
// is not the JS thread. C++ modules don't use RCTNativeModule, so this little
102
102
// adapter does the work.
103
103
104
- class QueueNativeModule : public NativeModule {
104
+ class DispatchMessageQueueThread : public MessageQueueThread {
105
105
public:
106
- QueueNativeModule (RCTCxxBridge *bridge,
107
- std::unique_ptr<NativeModule> module)
108
- : bridge_(bridge)
109
- , module_(std::move(module))
110
- // Create new queue (store queueName, as it isn't retained by dispatch_queue)
111
- , queueName_(" com.facebook.react." + module_->getName () + "Queue")
112
- , queue_(dispatch_queue_create(queueName_.c_str(), DISPATCH_QUEUE_SERIAL)) {}
113
-
114
- std::string getName () override {
115
- return module_->getName ();
116
- }
117
-
118
- std::vector<MethodDescriptor> getMethods () override {
119
- return module_->getMethods ();
120
- }
121
-
122
- folly::dynamic getConstants () override {
123
- return module_->getConstants ();
124
- }
125
-
126
- bool supportsWebWorkers () override {
127
- return module_->supportsWebWorkers ();
128
- }
106
+ DispatchMessageQueueThread (RCTModuleData *moduleData)
107
+ : moduleData_(moduleData) {}
129
108
130
- void invoke (ExecutorToken token, unsigned int reactMethodId,
131
- folly::dynamic &¶ms) override {
132
- __weak RCTCxxBridge *bridge = bridge_;
133
- auto module = module_;
134
- auto cparams = std::make_shared<folly::dynamic>(std::move (params));
135
- dispatch_async (queue_, ^{
136
- if (!bridge || !bridge.valid ) {
137
- return ;
138
- }
139
-
140
- module->invoke (token, reactMethodId, std::move (*cparams));
109
+ void runOnQueue (std::function<void ()>&& func) override {
110
+ dispatch_async (moduleData_.methodQueue , [func=std::move (func)] {
111
+ func ();
141
112
});
142
113
}
143
-
144
- MethodCallResult callSerializableNativeHook (
145
- ExecutorToken token, unsigned int reactMethodId,
146
- folly::dynamic &&args ) override {
147
- return module_-> callSerializableNativeHook (token, reactMethodId, std::move (args)) ;
114
+ void runOnQueueSync (std::function< void ()>&& func) override {
115
+ LOG (FATAL) << " Unsupported operation " ;
116
+ }
117
+ void quitSynchronous ( ) override {
118
+ LOG (FATAL) << " Unsupported operation " ;
148
119
}
149
120
150
121
private:
151
- RCTCxxBridge *bridge_;
152
- std::shared_ptr<NativeModule> module_;
153
- std::string queueName_;
154
- dispatch_queue_t queue_;
155
- };
156
-
157
-
158
- // This is a temporary hack. The cxx bridge assumes a single native
159
- // queue handles all native method calls, but that's false on ios. So
160
- // this is a no-thread passthrough, and queues are handled in
161
- // RCTNativeModule. A similar refactoring should be done on the Java
162
- // bridge.
163
- class InlineMessageQueueThread : public MessageQueueThread {
164
- public:
165
- void runOnQueue (std::function<void ()>&& func) override { func (); }
166
- void runOnQueueSync (std::function<void ()>&& func) override { func (); }
167
- void quitSynchronous () override {}
122
+ RCTModuleData *moduleData_;
168
123
};
169
124
170
125
}
@@ -551,12 +506,13 @@ - (BOOL)moduleIsInitialized:(Class)moduleClass
551
506
if (![moduleData hasInstance ]) {
552
507
continue ;
553
508
}
554
- modules.emplace_back (
555
- new QueueNativeModule (self, std::make_unique<CxxNativeModule>(
556
- _reactInstance, [moduleData.name UTF8String ],
557
- [moduleData] { return [(RCTCxxModule *)(moduleData.instance) move ]; })));
509
+ modules.emplace_back (std::make_unique<CxxNativeModule>(
510
+ _reactInstance,
511
+ [moduleData.name UTF8String ],
512
+ [moduleData] { return [(RCTCxxModule *)(moduleData.instance) move ]; },
513
+ std::make_shared<DispatchMessageQueueThread>(moduleData)));
558
514
} else {
559
- modules.emplace_back (new RCTNativeModule (self, moduleData));
515
+ modules.emplace_back (std::make_unique< RCTNativeModule> (self, moduleData));
560
516
}
561
517
}
562
518
@@ -586,7 +542,6 @@ - (void)_initializeBridge:(std::shared_ptr<JSExecutorFactory>)executorFactory
586
542
std::unique_ptr<RCTInstanceCallback>(new RCTInstanceCallback (self)),
587
543
executorFactory,
588
544
_jsMessageThread,
589
- std::unique_ptr<MessageQueueThread>(new InlineMessageQueueThread),
590
545
std::move ([self _createModuleRegistry ]));
591
546
592
547
#if RCT_PROFILE
0 commit comments