From 4bec099f7e2138145f1e8346ba322e0cf00c0afd Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Sat, 22 May 2021 12:18:00 -0700 Subject: [PATCH] Add option to disable sending scroll events to Paper Summary: Changelog: [internal] Originally added in D17814260 (https://github.com/facebook/react-native/commit/ffc7ec992c66417039b0fa14f1afd54a9cd2f882) to make parallax effect work in Dating. This diff hides it behind a flag so we can properly evaluate what's the cost of sending scroll events to Paper. Reviewed By: JoshuaGross Differential Revision: D28608283 fbshipit-source-id: fa4d8944ad6b5e767363e231942f13fec9d18cb5 --- React/Base/RCTConstants.h | 6 ++++++ React/Base/RCTConstants.m | 15 +++++++++++++++ .../ScrollView/RCTScrollViewComponentView.mm | 6 +++++- React/Fabric/RCTSurfacePresenter.mm | 4 ++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/React/Base/RCTConstants.h b/React/Base/RCTConstants.h index c6e287605d4..80dfd9675f0 100644 --- a/React/Base/RCTConstants.h +++ b/React/Base/RCTConstants.h @@ -17,6 +17,12 @@ RCT_EXTERN NSString *const RCTUserInterfaceStyleDidChangeNotificationTraitCollec RCT_EXTERN BOOL RCTExperimentGetOnDemandViewMounting(void); RCT_EXTERN void RCTExperimentSetOnDemandViewMounting(BOOL value); +/* + * Allows sending scroll events to Paper. + */ +RCT_EXTERN BOOL RCTExperimentGetSendScrollEventToPaper(void); +RCT_EXTERN void RCTExperimentSetSendScrollEventToPaper(BOOL value); + /* * Preemptive View Allocation */ diff --git a/React/Base/RCTConstants.m b/React/Base/RCTConstants.m index ecd001c493d..16d8e5913ee 100644 --- a/React/Base/RCTConstants.m +++ b/React/Base/RCTConstants.m @@ -25,6 +25,21 @@ void RCTExperimentSetOnDemandViewMounting(BOOL value) RCTExperimentOnDemandViewMounting = value; } +/* + * Send scroll events to Paper. + */ +static BOOL RCTExperimentSendScrollEventToPaper = YES; + +BOOL RCTExperimentGetSendScrollEventToPaper() +{ + return RCTExperimentSendScrollEventToPaper; +} + +void RCTExperimentSetSendScrollEventToPaper(BOOL value) +{ + RCTExperimentSendScrollEventToPaper = value; +} + /* * Preemptive View Allocation */ diff --git a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm index 9ba3054513b..4cd8858df34 100644 --- a/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm @@ -87,6 +87,7 @@ static void RCTSendPaperScrollEvent_DEPRECATED(UIScrollView *scrollView, NSInteg BOOL _isUserTriggeredScrolling; BOOL _isOnDemandViewMountingEnabled; + BOOL _sendScrollEventToPaper; CGPoint _contentOffsetWhenClipped; NSMutableArray *> *_childComponentViews; } @@ -106,6 +107,7 @@ static void RCTSendPaperScrollEvent_DEPRECATED(UIScrollView *scrollView, NSInteg _props = defaultProps; _isOnDemandViewMountingEnabled = RCTExperimentGetOnDemandViewMounting(); + _sendScrollEventToPaper = RCTExperimentGetSendScrollEventToPaper(); _childComponentViews = [[NSMutableArray alloc] init]; _scrollView = [[RCTEnhancedScrollView alloc] initWithFrame:self.bounds]; @@ -419,7 +421,9 @@ static void RCTSendPaperScrollEvent_DEPRECATED(UIScrollView *scrollView, NSInteg } // Once Fabric implements proper NativeAnimationDriver, this should be removed. // This is just a workaround to allow animations based on onScroll event. - RCTSendPaperScrollEvent_DEPRECATED(scrollView, self.tag); + if (_sendScrollEventToPaper) { + RCTSendPaperScrollEvent_DEPRECATED(scrollView, self.tag); + } } [self _remountChildrenIfNeeded]; diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index 43b154efdb6..212a8463c02 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -257,6 +257,10 @@ static BackgroundExecutor RCTGetBackgroundExecutor() RCTExperimentSetOnDemandViewMounting(YES); } + if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:disable_sending_scroll_events_to_paper")) { + RCTExperimentSetSendScrollEventToPaper(NO); + } + if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:preemptive_view_allocation_disabled_ios")) { RCTExperimentSetPreemptiveViewAllocationDisabled(YES); }