From cd5f0bd95cdbb07a79ca2998b7728394f7ff009d Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sun, 25 Nov 2018 22:15:00 -0800 Subject: [PATCH] Fabric: Stopping creating ShadowView instances for non-View ShadowNodes Summary: Apparently, the previous behavior brings more problems than some *possible-in-the-future* features and flexibility. The new model allows us to easily implement "nested text" feature. (We temporary hope the old behavious for Android only for compatibility reasons.) Reviewed By: mdvacca Differential Revision: D13176277 fbshipit-source-id: 01f7bfb3c2e70cc89d76ecb78add016ee91cbd63 --- React/Fabric/RCTScheduler.mm | 4 ++++ ReactCommon/fabric/uimanager/Differentiator.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/React/Fabric/RCTScheduler.mm b/React/Fabric/RCTScheduler.mm index 8276a68c9..1b6c8b797 100644 --- a/React/Fabric/RCTScheduler.mm +++ b/React/Fabric/RCTScheduler.mm @@ -28,6 +28,10 @@ public: } void schedulerDidRequestPreliminaryViewAllocation(SurfaceId surfaceId, ComponentName componentName, bool isLayoutable, ComponentHandle componentHandle) override { + if (!isLayoutable) { + return; + } + RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_; [scheduler.delegate schedulerOptimisticallyCreateComponentViewWithComponentHandle:componentHandle]; } diff --git a/ReactCommon/fabric/uimanager/Differentiator.cpp b/ReactCommon/fabric/uimanager/Differentiator.cpp index 3b6f1f891..9bac22008 100644 --- a/ReactCommon/fabric/uimanager/Differentiator.cpp +++ b/ReactCommon/fabric/uimanager/Differentiator.cpp @@ -20,7 +20,17 @@ static void sliceChildShadowNodeViewPairsRecursively( const auto layoutableShadowNode = dynamic_cast(childShadowNode.get()); +#ifndef ANDROID + // New approach (iOS): + // Non-view components are treated as layout-only views (they aren't + // represented as `ShadowView`s). + if (!layoutableShadowNode || layoutableShadowNode->isLayoutOnly()) { +#else + // Previous approach (Android): + // Non-view components are treated as normal views with an empty layout + // (they are represented as `ShadowView`s). if (layoutableShadowNode && layoutableShadowNode->isLayoutOnly()) { +#endif sliceChildShadowNodeViewPairsRecursively( pairList, layoutOffset + shadowView.layoutMetrics.frame.origin,