Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -620,16 +620,16 @@ - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompo

/*
* Returns whether or not the scroll view interaction should be blocked because
* JavaScript was found to be the responder.
* an ancestor is the JavaScript responder and blocks native responders.
*/
- (BOOL)_shouldDisableScrollInteraction
{
UIView *ancestorView = self.superview;

while (ancestorView) {
if ([ancestorView respondsToSelector:@selector(isJSResponder)]) {
BOOL isJSResponder = ((UIView<RCTComponentViewProtocol> *)ancestorView).isJSResponder;
if (isJSResponder) {
if ([ancestorView respondsToSelector:@selector(blocksNativeResponder)]) {
BOOL blocksNativeResponder = ((UIView<RCTComponentViewProtocol> *)ancestorView).blocksNativeResponder;
if (blocksNativeResponder) {
return YES;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ @implementation RCTViewComponentView {
NSMutableArray<CALayer *> *_backgroundImageLayers;
BOOL _needsInvalidateLayer;
BOOL _isJSResponder;
BOOL _blocksNativeResponder;
BOOL _removeClippedSubviews;
NSMutableArray<UIView *> *_reactSubviews;
NSSet<NSString *> *_Nullable _propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN;
Expand Down Expand Up @@ -847,6 +848,16 @@ - (void)setIsJSResponder:(BOOL)isJSResponder
_isJSResponder = isJSResponder;
}

- (BOOL)blocksNativeResponder
{
return _blocksNativeResponder;
}

- (void)setBlocksNativeResponder:(BOOL)blocksNativeResponder
{
_blocksNativeResponder = blocksNativeResponder;
}

- (void)finalizeUpdates:(RNComponentViewUpdateMask)updateMask
{
[super finalizeUpdates:updateMask];
Expand Down Expand Up @@ -896,6 +907,7 @@ - (void)prepareForRecycle
_propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN = nil;
_eventEmitter.reset();
_isJSResponder = NO;
_blocksNativeResponder = NO;
_removeClippedSubviews = NO;
_reactSubviews = [NSMutableArray new];
_layoutMetrics = EmptyLayoutMetrics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ typedef NS_OPTIONS(NSInteger, RNComponentViewUpdateMask) {
- (BOOL)isJSResponder;
- (void)setIsJSResponder:(BOOL)isJSResponder;

/*
* Whether the view is the JavaScript responder and asked to block native
* responders, such as an enclosing scroll view, when it was granted the
* responder (the `blockNativeResponder` argument of `setIsJSResponder`).
*/
- (BOOL)blocksNativeResponder;
- (void)setBlocksNativeResponder:(BOOL)blocksNativeResponder;

/*
* This is broken. Do not use.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ - (void)setIsJSResponder:(BOOL)isJSResponder
RCTExecuteOnMainQueue(^{
UIView<RCTComponentViewProtocol> *componentView = [self->_componentViewRegistry findComponentViewWithTag:reactTag];
[componentView setIsJSResponder:isJSResponder];
[componentView setBlocksNativeResponder:isJSResponder && blockNativeResponder];
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ NS_ASSUME_NONNULL_BEGIN

- (void)setIsJSResponder:(BOOL)isJSResponder;

- (void)setBlocksNativeResponder:(BOOL)blocksNativeResponder;

- (void)setPropKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN:(nullable NSSet<NSString *> *)props;
- (nullable NSSet<NSString *> *)propKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ - (void)setIsJSResponder:(BOOL)isJSResponder
// Default implementation does nothing.
}

- (BOOL)blocksNativeResponder
{
// Default implementation always returns `NO`.
return NO;
}

- (void)setBlocksNativeResponder:(BOOL)blocksNativeResponder
{
// Default implementation does nothing.
}

- (void)setPropKeysManagedByAnimated_DO_NOT_USE_THIS_IS_BROKEN:(nullable NSSet<NSString *> *)propKeys
{
// Default implementation does nothing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/

#import <React/RCTComponentViewFactory.h>
#import <React/RCTComponentViewRegistry.h>
#import <React/RCTEnhancedScrollView.h>
#import <React/RCTMountingManager.h>
#import <React/RCTScrollContentViewComponentView.h>
#import <React/RCTScrollViewComponentView.h>
#import <React/RCTViewComponentView.h>
#import <XCTest/XCTest.h>
#import <react/featureflags/ReactNativeFeatureFlags.h>
#import <react/featureflags/ReactNativeFeatureFlagsDefaults.h>
Expand All @@ -19,6 +23,7 @@
#import <react/renderer/core/EventDispatcher.h>
#import <react/renderer/core/EventQueueProcessor.h>
#import <react/renderer/core/StateUpdate.h>
#import <react/renderer/mounting/ShadowView.h>
#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
#import <react/utils/ContextContainer.h>

Expand Down Expand Up @@ -228,6 +233,36 @@ - (void)testAutomaticallyAdjustKeyboardInsetsAcrossRecycling
XCTAssertEqual(view.scrollView.contentInset.bottom, 50);
}

- (void)testAncestorJSResponderDisablesScrollingOnlyWhileItBlocksNativeResponder
{
RCTMountingManager *mountingManager = [RCTMountingManager new];
RCTComponentViewRegistry *registry = mountingManager.componentViewRegistry;
[registry.componentViewFactory registerComponentViewClass:[RCTViewComponentView class]];

facebook::react::ShadowView ancestorShadowView{};
ancestorShadowView.tag = 2;
UIView *ancestor =
[registry dequeueComponentViewWithComponentHandle:[RCTViewComponentView componentDescriptorProvider].handle
tag:ancestorShadowView.tag]
.view;
RCTScrollViewComponentView *view = [[RCTScrollViewComponentView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[ancestor addSubview:view];
UIView *contentView = [UIView new];

[mountingManager setIsJSResponder:YES blockNativeResponder:NO forShadowView:ancestorShadowView];
XCTAssertTrue([view.scrollView touchesShouldCancelInContentView:contentView]);

[mountingManager setIsJSResponder:YES blockNativeResponder:YES forShadowView:ancestorShadowView];
XCTAssertFalse([view.scrollView touchesShouldCancelInContentView:contentView]);

[mountingManager setIsJSResponder:NO blockNativeResponder:YES forShadowView:ancestorShadowView];
XCTAssertTrue([view.scrollView touchesShouldCancelInContentView:contentView]);

[mountingManager setIsJSResponder:YES blockNativeResponder:YES forShadowView:ancestorShadowView];
[ancestor prepareForRecycle];
XCTAssertTrue([view.scrollView touchesShouldCancelInContentView:contentView]);
}

// XCTest assertion macros use variadic reporting and catch framework exceptions by value.
// NOLINTBEGIN(cppcoreguidelines-pro-type-vararg, misc-throw-by-value-catch-by-reference)
- (void)testSafeAreaCorrectionPreservesPullToRefreshInset
Expand Down
3 changes: 3 additions & 0 deletions scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ category UIView(ComponentViewProtocol) {
public virtual void invalidate();
public virtual void mountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void prepareForRecycle();
public virtual void setBlocksNativeResponder:(BOOL blocksNativeResponder);
public virtual void setIsJSResponder:(BOOL isJSResponder);
public virtual void unmountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void updateClippedSubviewsWithClipRect:relativeToView:(CGRect clipRect, UIView* clipView);
Expand Down Expand Up @@ -2575,6 +2576,7 @@ protocol RCTComponentViewFactoryComponentProvider : public NSObject {
}

protocol RCTComponentViewProtocol : public NSObject {
public virtual BOOL blocksNativeResponder();
public virtual BOOL isJSResponder();
public virtual facebook::react::Props::Shared props();
public virtual static facebook::react::ComponentDescriptorProvider componentDescriptorProvider();
Expand All @@ -2584,6 +2586,7 @@ protocol RCTComponentViewProtocol : public NSObject {
public virtual void invalidate();
public virtual void mountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void prepareForRecycle();
public virtual void setBlocksNativeResponder:(BOOL blocksNativeResponder);
public virtual void setIsJSResponder:(BOOL isJSResponder);
public virtual void unmountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void updateEventEmitter:(const facebook::react::EventEmitter::Shared& eventEmitter);
Expand Down
3 changes: 3 additions & 0 deletions scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ category UIView(ComponentViewProtocol) {
public virtual void invalidate();
public virtual void mountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void prepareForRecycle();
public virtual void setBlocksNativeResponder:(BOOL blocksNativeResponder);
public virtual void setIsJSResponder:(BOOL isJSResponder);
public virtual void unmountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void updateClippedSubviewsWithClipRect:relativeToView:(CGRect clipRect, UIView* clipView);
Expand Down Expand Up @@ -2633,6 +2634,7 @@ protocol RCTComponentViewFactoryComponentProvider : public NSObject {
}

protocol RCTComponentViewProtocol : public NSObject {
public virtual BOOL blocksNativeResponder();
public virtual BOOL isJSResponder();
public virtual facebook::react::Props::Shared props();
public virtual static facebook::react::ComponentDescriptorProvider componentDescriptorProvider();
Expand All @@ -2642,6 +2644,7 @@ protocol RCTComponentViewProtocol : public NSObject {
public virtual void invalidate();
public virtual void mountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void prepareForRecycle();
public virtual void setBlocksNativeResponder:(BOOL blocksNativeResponder);
public virtual void setIsJSResponder:(BOOL isJSResponder);
public virtual void unmountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void updateEventEmitter:(const facebook::react::EventEmitter::Shared& eventEmitter);
Expand Down
3 changes: 3 additions & 0 deletions scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ category UIView(ComponentViewProtocol) {
public virtual void invalidate();
public virtual void mountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void prepareForRecycle();
public virtual void setBlocksNativeResponder:(BOOL blocksNativeResponder);
public virtual void setIsJSResponder:(BOOL isJSResponder);
public virtual void unmountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void updateClippedSubviewsWithClipRect:relativeToView:(CGRect clipRect, UIView* clipView);
Expand Down Expand Up @@ -2568,6 +2569,7 @@ protocol RCTComponentViewFactoryComponentProvider : public NSObject {
}

protocol RCTComponentViewProtocol : public NSObject {
public virtual BOOL blocksNativeResponder();
public virtual BOOL isJSResponder();
public virtual facebook::react::Props::Shared props();
public virtual static facebook::react::ComponentDescriptorProvider componentDescriptorProvider();
Expand All @@ -2577,6 +2579,7 @@ protocol RCTComponentViewProtocol : public NSObject {
public virtual void invalidate();
public virtual void mountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void prepareForRecycle();
public virtual void setBlocksNativeResponder:(BOOL blocksNativeResponder);
public virtual void setIsJSResponder:(BOOL isJSResponder);
public virtual void unmountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void updateEventEmitter:(const facebook::react::EventEmitter::Shared& eventEmitter);
Expand Down
3 changes: 3 additions & 0 deletions scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ category UIView(ComponentViewProtocol) {
public virtual void invalidate();
public virtual void mountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void prepareForRecycle();
public virtual void setBlocksNativeResponder:(BOOL blocksNativeResponder);
public virtual void setIsJSResponder:(BOOL isJSResponder);
public virtual void unmountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void updateClippedSubviewsWithClipRect:relativeToView:(CGRect clipRect, UIView* clipView);
Expand Down Expand Up @@ -2575,6 +2576,7 @@ protocol RCTComponentViewFactoryComponentProvider : public NSObject {
}

protocol RCTComponentViewProtocol : public NSObject {
public virtual BOOL blocksNativeResponder();
public virtual BOOL isJSResponder();
public virtual facebook::react::Props::Shared props();
public virtual static facebook::react::ComponentDescriptorProvider componentDescriptorProvider();
Expand All @@ -2584,6 +2586,7 @@ protocol RCTComponentViewProtocol : public NSObject {
public virtual void invalidate();
public virtual void mountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void prepareForRecycle();
public virtual void setBlocksNativeResponder:(BOOL blocksNativeResponder);
public virtual void setIsJSResponder:(BOOL isJSResponder);
public virtual void unmountChildComponentView:index:(UIView<RCTComponentViewProtocol>* childComponentView, NSInteger index);
public virtual void updateEventEmitter:(const facebook::react::EventEmitter::Shared& eventEmitter);
Expand Down
Loading