6
6
*/
7
7
8
8
#include " FabricMountingManager.h"
9
+ #include " CppViewMutationsWrapper.h"
9
10
#include " EventEmitterWrapper.h"
10
11
#include " StateWrapperImpl.h"
11
12
#include " viewPropConversions.h"
@@ -38,8 +39,10 @@ static bool getFeatureFlagValue(const char *name) {
38
39
39
40
FabricMountingManager::FabricMountingManager (
40
41
std::shared_ptr<const ReactNativeConfig> &config,
42
+ std::shared_ptr<const CppComponentRegistry> &cppComponentRegistry,
41
43
global_ref<jobject> &javaUIManager)
42
44
: javaUIManager_(javaUIManager),
45
+ cppComponentRegistry_ (cppComponentRegistry),
43
46
enableEarlyEventEmitterUpdate_(
44
47
config->getBool (" react_fabric:enable_early_event_emitter_update" )),
45
48
disablePreallocateViews_(
@@ -82,6 +85,8 @@ static inline int getIntBufferSizeForType(CppMountItem::Type mountItemType) {
82
85
return 7 ; // tag, parentTag, x, y, w, h, DisplayType
83
86
case CppMountItem::Type::UpdateOverflowInset:
84
87
return 5 ; // tag, left, top, right, bottom
88
+ case CppMountItem::Type::RunCPPMutations:
89
+ return 1 ;
85
90
case CppMountItem::Undefined:
86
91
case CppMountItem::Multiple:
87
92
return -1 ;
@@ -124,7 +129,8 @@ static inline void computeBufferSizes(
124
129
std::vector<CppMountItem> &cppUpdatePaddingMountItems,
125
130
std::vector<CppMountItem> &cppUpdateLayoutMountItems,
126
131
std::vector<CppMountItem> &cppUpdateOverflowInsetMountItems,
127
- std::vector<CppMountItem> &cppUpdateEventEmitterMountItems) {
132
+ std::vector<CppMountItem> &cppUpdateEventEmitterMountItems,
133
+ ShadowViewMutationList &cppViewMutations) {
128
134
CppMountItem::Type lastType = CppMountItem::Type::Undefined;
129
135
int numSameType = 0 ;
130
136
for (auto const &mountItem : cppCommonMountItems) {
@@ -183,6 +189,11 @@ static inline void computeBufferSizes(
183
189
cppDeleteMountItems.size (),
184
190
batchMountItemIntsSize,
185
191
batchMountItemObjectsSize);
192
+
193
+ if (cppViewMutations.size () > 0 ) {
194
+ batchMountItemIntsSize++;
195
+ batchMountItemObjectsSize++;
196
+ }
186
197
}
187
198
188
199
static inline void writeIntBufferTypePreamble (
@@ -293,7 +304,7 @@ void FabricMountingManager::executeMount(
293
304
std::vector<CppMountItem> cppUpdateLayoutMountItems;
294
305
std::vector<CppMountItem> cppUpdateOverflowInsetMountItems;
295
306
std::vector<CppMountItem> cppUpdateEventEmitterMountItems;
296
-
307
+ auto cppViewMutations = ShadowViewMutationList ();
297
308
{
298
309
std::lock_guard allocatedViewsLock (allocatedViewsMutex_);
299
310
@@ -318,6 +329,25 @@ void FabricMountingManager::executeMount(
318
329
319
330
bool isVirtual = mutation.mutatedViewIsVirtual ();
320
331
332
+ // Detect if the mutation instruction belongs to C++ view managers
333
+ if (cppComponentRegistry_) {
334
+ auto componentName = newChildShadowView.componentName
335
+ ? newChildShadowView.componentName
336
+ : oldChildShadowView.componentName ;
337
+ auto name = std::string (componentName);
338
+ if (cppComponentRegistry_->containsComponentManager (name)) {
339
+ // is this thread safe?
340
+ cppViewMutations.push_back (mutation);
341
+
342
+ // This is a hack that could be avoided by using Portals
343
+ // Only execute mutations instructions for Root C++ ViewManagers
344
+ // because Root C++ Components have a Android view counterpart.
345
+ if (!cppComponentRegistry_->isRootComponent (name)) {
346
+ continue ;
347
+ }
348
+ }
349
+ }
350
+
321
351
switch (mutationType) {
322
352
case ShadowViewMutation::Create: {
323
353
bool revisionCheck =
@@ -502,7 +532,8 @@ void FabricMountingManager::executeMount(
502
532
cppUpdatePaddingMountItems,
503
533
cppUpdateLayoutMountItems,
504
534
cppUpdateOverflowInsetMountItems,
505
- cppUpdateEventEmitterMountItems);
535
+ cppUpdateEventEmitterMountItems,
536
+ cppViewMutations);
506
537
507
538
static auto createMountItemsIntBufferBatchContainer =
508
539
jni::findClassStatic (UIManagerJavaDescriptor)
@@ -809,6 +840,36 @@ void FabricMountingManager::executeMount(
809
840
}
810
841
}
811
842
843
+ if (cppViewMutations.size () > 0 ) {
844
+ writeIntBufferTypePreamble (
845
+ CppMountItem::Type::RunCPPMutations,
846
+ 1 ,
847
+ env,
848
+ intBufferArray,
849
+ intBufferPosition);
850
+
851
+ // TODO review this logic and memory mamangement
852
+ // this might not be necessary:
853
+ // temp[0] = 1234;
854
+ // env->SetIntArrayRegion(intBufferArray, intBufferPosition, 1, temp);
855
+ // intBufferPosition += 1;
856
+
857
+ // Do not hold a reference to javaCppMutations from the C++ side.
858
+ auto javaCppMutations = CppViewMutationsWrapper::newObjectJavaArgs ();
859
+ CppViewMutationsWrapper *cppViewMutationsWrapper = cthis (javaCppMutations);
860
+
861
+ // TODO move this to init methods
862
+ cppViewMutationsWrapper->cppComponentRegistry = cppComponentRegistry_;
863
+ // TODO is moving the cppViewMutations safe / thread safe?
864
+ // cppViewMutations will be accessed from the UI Thread in a near future
865
+ // can they dissapear?
866
+ cppViewMutationsWrapper->cppViewMutations =
867
+ std::make_shared<std::vector<facebook::react::ShadowViewMutation>>(
868
+ std::move (cppViewMutations));
869
+
870
+ (*objBufferArray)[objBufferPosition++] = javaCppMutations.get ();
871
+ }
872
+
812
873
// If there are no items, we pass a nullptr instead of passing the object
813
874
// through the JNI
814
875
auto batch = createMountItemsIntBufferBatchContainer (
0 commit comments