8
8
#include " FabricMountingManager.h"
9
9
#include " EventEmitterWrapper.h"
10
10
#include " StateWrapperImpl.h"
11
+ #include " viewPropConversions.h"
11
12
12
13
#include < react/jni/ReadableNativeMap.h>
13
14
#include < react/renderer/components/scrollview/ScrollViewProps.h>
@@ -177,11 +178,6 @@ static inline void writeIntBufferTypePreamble(
177
178
}
178
179
}
179
180
180
- inline local_ref<ReadableMap::javaobject> castReadableMap (
181
- local_ref<ReadableNativeMap::javaobject> const &nativeMap) {
182
- return make_local (reinterpret_cast <ReadableMap::javaobject>(nativeMap.get ()));
183
- }
184
-
185
181
inline local_ref<ReadableArray::javaobject> castReadableArray (
186
182
local_ref<ReadableNativeArray::javaobject> const &nativeArray) {
187
183
return make_local (
@@ -222,6 +218,22 @@ static inline float scale(Float value, Float pointScaleFactor) {
222
218
return result;
223
219
}
224
220
221
+ local_ref<jobject> FabricMountingManager::getProps (
222
+ ShadowView const &oldShadowView,
223
+ ShadowView const &newShadowView) {
224
+ if (useMapBufferForViewProps_ &&
225
+ newShadowView.traits .check (ShadowNodeTraits::Trait::View)) {
226
+ auto oldProps = oldShadowView.props != nullptr
227
+ ? static_cast <ViewProps const &>(*oldShadowView.props )
228
+ : ViewProps{};
229
+ auto newProps = static_cast <ViewProps const &>(*newShadowView.props );
230
+ return ReadableMapBuffer::createWithContents (
231
+ viewPropsDiff (oldProps, newProps));
232
+ } else {
233
+ return ReadableNativeMap::newObjectCxxArgs (newShadowView.props ->rawProps );
234
+ }
235
+ }
236
+
225
237
void FabricMountingManager::executeMount (
226
238
MountingCoordinator::Shared const &mountingCoordinator) {
227
239
std::lock_guard<std::recursive_mutex> lock (commitMutex_);
@@ -308,7 +320,8 @@ void FabricMountingManager::executeMount(
308
320
if (!isVirtual) {
309
321
if (oldChildShadowView.props != newChildShadowView.props ) {
310
322
cppUpdatePropsMountItems.push_back (
311
- CppMountItem::UpdatePropsMountItem (newChildShadowView));
323
+ CppMountItem::UpdatePropsMountItem (
324
+ oldChildShadowView, newChildShadowView));
312
325
}
313
326
if (oldChildShadowView.state != newChildShadowView.state ) {
314
327
cppUpdateStateMountItems.push_back (
@@ -367,7 +380,7 @@ void FabricMountingManager::executeMount(
367
380
shouldRememberAllocatedViews_ ? allocationCheck : revisionCheck;
368
381
if (shouldCreateView) {
369
382
cppUpdatePropsMountItems.push_back (
370
- CppMountItem::UpdatePropsMountItem (newChildShadowView));
383
+ CppMountItem::UpdatePropsMountItem ({}, newChildShadowView));
371
384
}
372
385
373
386
// State
@@ -484,7 +497,6 @@ void FabricMountingManager::executeMount(
484
497
485
498
// Allocate the intBuffer and object array, now that we know exact sizes
486
499
// necessary
487
- // TODO: don't allocate at all if size is zero
488
500
jintArray intBufferArray = env->NewIntArray (batchMountItemIntsSize);
489
501
local_ref<JArrayClass<jobject>> objBufferArray =
490
502
JArrayClass<jobject>::newArray (batchMountItemObjectsSize);
@@ -525,10 +537,8 @@ void FabricMountingManager::executeMount(
525
537
int isLayoutable =
526
538
mountItem.newChildShadowView .layoutMetrics != EmptyLayoutMetrics ? 1
527
539
: 0 ;
528
-
529
- local_ref<ReadableMap::javaobject> props =
530
- castReadableMap (ReadableNativeMap::newObjectCxxArgs (
531
- mountItem.newChildShadowView .props ->rawProps ));
540
+ local_ref<JObject> props =
541
+ getProps (mountItem.oldChildShadowView , mountItem.newChildShadowView );
532
542
533
543
// Do not hold onto Java object from C
534
544
// We DO want to hold onto C object from Java, since we don't know the
@@ -584,11 +594,8 @@ void FabricMountingManager::executeMount(
584
594
temp[0 ] = mountItem.newChildShadowView .tag ;
585
595
env->SetIntArrayRegion (intBufferArray, intBufferPosition, 1 , temp);
586
596
intBufferPosition += 1 ;
587
-
588
- auto newProps = mountItem.newChildShadowView .props ->rawProps ;
589
- local_ref<ReadableMap::javaobject> newPropsReadableMap =
590
- castReadableMap (ReadableNativeMap::newObjectCxxArgs (newProps));
591
- (*objBufferArray)[objBufferPosition++] = newPropsReadableMap.get ();
597
+ (*objBufferArray)[objBufferPosition++] =
598
+ getProps (mountItem.oldChildShadowView , mountItem.newChildShadowView );
592
599
}
593
600
}
594
601
if (!cppUpdateStateMountItems.empty ()) {
@@ -795,15 +802,11 @@ void FabricMountingManager::preallocateShadowView(
795
802
796
803
bool isLayoutableShadowNode = shadowView.layoutMetrics != EmptyLayoutMetrics;
797
804
798
- static auto preallocateView = jni::findClassStatic (UIManagerJavaDescriptor)
799
- ->getMethod <void (
800
- jint,
801
- jint,
802
- jstring,
803
- ReadableMap::javaobject,
804
- jobject,
805
- jobject,
806
- jboolean)>(" preallocateView" );
805
+ static auto preallocateView =
806
+ jni::findClassStatic (UIManagerJavaDescriptor)
807
+ ->getMethod <void (
808
+ jint, jint, jstring, jobject, jobject, jobject, jboolean)>(
809
+ " preallocateView" );
807
810
808
811
// Do not hold onto Java object from C
809
812
// We DO want to hold onto C object from Java, since we don't know the
@@ -826,8 +829,8 @@ void FabricMountingManager::preallocateShadowView(
826
829
}
827
830
}
828
831
829
- local_ref<ReadableMap::javaobject > props = castReadableMap (
830
- ReadableNativeMap::newObjectCxxArgs (shadowView. props -> rawProps ));
832
+ local_ref<JObject > props = getProps ({}, shadowView);
833
+
831
834
auto component = getPlatformComponentName (shadowView);
832
835
833
836
preallocateView (
@@ -942,6 +945,8 @@ FabricMountingManager::FabricMountingManager(
942
945
useOverflowInset_ = doesUseOverflowInset ();
943
946
shouldRememberAllocatedViews_ = config->getBool (
944
947
" react_native_new_architecture:remember_views_on_mount_android" );
948
+ useMapBufferForViewProps_ = config->getBool (
949
+ " react_native_new_architecture:use_mapbuffer_for_viewprops" );
945
950
}
946
951
947
952
} // namespace react
0 commit comments