Remove gating for subview clipping

Summary:
changelog: [internal]

Remove gating for subview clipping

Reviewed By: philIip

Differential Revision: D32594194

fbshipit-source-id: e35e698cc3303f289cdd44a7f34274ea046dfd81
This commit is contained in:
Samuel Susla 2021-11-25 08:07:29 -08:00 коммит произвёл Facebook GitHub Bot
Родитель b2f3cd2309
Коммит 3ba237b663
5 изменённых файлов: 4 добавлений и 108 удалений

Просмотреть файл

@ -15,9 +15,3 @@ RCT_EXTERN NSString *const RCTUserInterfaceStyleDidChangeNotificationTraitCollec
*/
RCT_EXTERN BOOL RCTExperimentGetPreemptiveViewAllocationDisabled(void);
RCT_EXTERN void RCTExperimentSetPreemptiveViewAllocationDisabled(BOOL value);
/*
* Remove clipped subviews
*/
RCT_EXTERN BOOL RCTGetRemoveClippedSubviewsEnabled(void);
RCT_EXTERN void RCTSetRemoveClippedSubviewsEnabled(BOOL value);

Просмотреть файл

@ -24,18 +24,3 @@ void RCTExperimentSetPreemptiveViewAllocationDisabled(BOOL value)
{
RCTExperimentPreemptiveViewAllocationDisabled = value;
}
/*
* Remove clipped subviews
*/
static BOOL RCTRemoveClippedSubviewsEnabled = NO;
BOOL RCTGetRemoveClippedSubviewsEnabled(void)
{
return RCTRemoveClippedSubviewsEnabled;
}
void RCTSetRemoveClippedSubviewsEnabled(BOOL value)
{
RCTRemoveClippedSubviewsEnabled = value;
}

Просмотреть файл

@ -87,8 +87,6 @@ static void RCTSendPaperScrollEvent_DEPRECATED(UIScrollView *scrollView, NSInteg
BOOL _isUserTriggeredScrolling;
CGPoint _contentOffsetWhenClipped;
NSMutableArray<UIView<RCTComponentViewProtocol> *> *_childComponentViews;
BOOL _subviewClippingEnabled;
}
+ (RCTScrollViewComponentView *_Nullable)findScrollViewComponentViewForView:(UIView *)view
@ -105,15 +103,12 @@ static void RCTSendPaperScrollEvent_DEPRECATED(UIScrollView *scrollView, NSInteg
static const auto defaultProps = std::make_shared<const ScrollViewProps>();
_props = defaultProps;
_childComponentViews = [NSMutableArray new];
_scrollView = [[RCTEnhancedScrollView alloc] initWithFrame:self.bounds];
_scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
_scrollView.delaysContentTouches = NO;
((RCTEnhancedScrollView *)_scrollView).overridingDelegate = self;
_isUserTriggeredScrolling = NO;
[self addSubview:_scrollView];
_subviewClippingEnabled = RCTGetRemoveClippedSubviewsEnabled();
_containerView = [[UIView alloc] initWithFrame:CGRectZero];
[_scrollView addSubview:_containerView];
@ -324,24 +319,11 @@ static void RCTSendPaperScrollEvent_DEPRECATED(UIScrollView *scrollView, NSInteg
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
{
if (_subviewClippingEnabled) {
[_containerView insertSubview:childComponentView atIndex:index];
} else {
[_childComponentViews insertObject:childComponentView atIndex:index];
}
}
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
{
if (!_subviewClippingEnabled) {
RCTAssert(
[_childComponentViews objectAtIndex:index] == childComponentView,
@"Attempt to unmount improperly mounted component view.");
[_childComponentViews removeObjectAtIndex:index];
}
// In addition to removing a view from `_childComponentViews`,
// we have to unmount views immediately to not mess with recycling.
[childComponentView removeFromSuperview];
}
@ -626,68 +608,8 @@ static void RCTSendPaperScrollEvent_DEPRECATED(UIScrollView *scrollView, NSInteg
- (void)_remountChildren
{
if (_subviewClippingEnabled) {
[_scrollView updateClippedSubviewsWithClipRect:CGRectInset(_scrollView.bounds, -kClippingLeeway, -kClippingLeeway)
relativeToView:_scrollView];
} else {
CGRect visibleFrame = [_scrollView convertRect:_scrollView.bounds toView:_containerView];
visibleFrame = CGRectInset(visibleFrame, -kClippingLeeway, -kClippingLeeway);
// `zoomScale` is negative in RTL. Absolute value is needed.
CGFloat scale = 1.0 / std::abs(_scrollView.zoomScale);
visibleFrame.origin.x *= scale;
visibleFrame.origin.y *= scale;
visibleFrame.size.width *= scale;
visibleFrame.size.height *= scale;
#ifndef NDEBUG
NSMutableArray<UIView<RCTComponentViewProtocol> *> *expectedSubviews = [NSMutableArray new];
#endif
NSInteger mountedIndex = 0;
for (UIView *componentView in _childComponentViews) {
BOOL shouldBeMounted = YES;
BOOL isMounted = componentView.superview != nil;
// It's simpler and faster to not mess with views that are not `RCTViewComponentView` subclasses.
if ([componentView isKindOfClass:[RCTViewComponentView class]]) {
RCTViewComponentView *viewComponentView = (RCTViewComponentView *)componentView;
auto layoutMetrics = viewComponentView->_layoutMetrics;
if (layoutMetrics.overflowInset == EdgeInsets{}) {
shouldBeMounted = CGRectIntersectsRect(visibleFrame, componentView.frame);
}
}
if (shouldBeMounted != isMounted) {
if (shouldBeMounted) {
[_containerView insertSubview:componentView atIndex:mountedIndex];
} else {
[componentView removeFromSuperview];
}
}
if (shouldBeMounted) {
mountedIndex++;
}
#ifndef NDEBUG
if (shouldBeMounted) {
[expectedSubviews addObject:componentView];
}
#endif
}
#ifndef NDEBUG
RCTAssert(
_containerView.subviews.count == expectedSubviews.count,
@"-[RCTScrollViewComponentView _remountChildren]: Inconsistency detected.");
for (NSInteger i = 0; i < expectedSubviews.count; i++) {
RCTAssert(
[_containerView.subviews objectAtIndex:i] == [expectedSubviews objectAtIndex:i],
@"-[RCTScrollViewComponentView _remountChildren]: Inconsistency detected.");
}
#endif
}
}
#pragma mark - RCTScrollableProtocol

Просмотреть файл

@ -193,8 +193,7 @@ using namespace facebook::react;
needsInvalidateLayer = YES;
}
if (RCTGetRemoveClippedSubviewsEnabled() &&
oldViewProps.removeClippedSubviews != newViewProps.removeClippedSubviews) {
if (oldViewProps.removeClippedSubviews != newViewProps.removeClippedSubviews) {
_removeClippedSubviews = newViewProps.removeClippedSubviews;
if (_removeClippedSubviews && self.subviews.count > 0) {
_reactSubviews = [NSMutableArray arrayWithArray:self.subviews];

Просмотреть файл

@ -255,10 +255,6 @@ static BackgroundExecutor RCTGetBackgroundExecutor()
RCTExperimentSetPreemptiveViewAllocationDisabled(YES);
}
if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:enable_remove_clipped_subviews_ios")) {
RCTSetRemoveClippedSubviewsEnabled(YES);
}
auto componentRegistryFactory =
[factory = wrapManagedObject(_mountingManager.componentViewRegistry.componentViewFactory)](
EventDispatcher::Weak const &eventDispatcher, ContextContainer::Shared const &contextContainer) {