Skip to content
Open
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 @@ -33,6 +33,8 @@
static NSString *kOnScrollEndEvent = @"onScrollEnded";

static const CGFloat kClippingLeeway = 44.0;
// Well past UIKit's fixed-duration `setContentOffset:animated:` animation.
static const NSTimeInterval kProgrammaticScrollEndFallbackDelay = 1.0;

static UIScrollViewKeyboardDismissMode RCTUIKeyboardDismissModeFromProps(const ScrollViewProps &props)
{
Expand Down Expand Up @@ -112,6 +114,11 @@ @implementation RCTScrollViewComponentView {
// This helps to only update state from `scrollViewDidScroll` in case
// some other part of the system scrolls scroll view.
BOOL _isUserTriggeredScrolling;
// Whether an animated programmatic scroll has dispatched `onMomentumScrollBegin` and still owes
// its `onMomentumScrollEnd`.
BOOL _isProgrammaticScrollAnimating;
// Identifies the latest animated programmatic scroll, so a stale end fallback is ignored.
NSUInteger _programmaticScrollGeneration;
BOOL _shouldUpdateContentInsetAdjustmentBehavior;
BOOL _automaticallyAdjustKeyboardInsets;

Expand Down Expand Up @@ -731,6 +738,8 @@ - (void)prepareForRecycle
_shouldUpdateContentInsetAdjustmentBehavior = YES;
_automaticallyAdjustKeyboardInsets = NO;
_isUserTriggeredScrolling = NO;
_isProgrammaticScrollAnimating = NO;
_programmaticScrollGeneration++;
CGRect oldFrame = self.frame;
self.frame = CGRectZero;
self.frame = oldFrame;
Expand Down Expand Up @@ -816,10 +825,17 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
[self _forceDispatchNextScrollEvent];

// A drag interrupts an animated programmatic scroll without `scrollViewDidEndScrollingAnimation`.
BOOL interruptedProgrammaticScroll = _isProgrammaticScrollAnimating;
_isProgrammaticScrollAnimating = NO;

if (!_eventEmitter) {
return;
}

if (interruptedProgrammaticScroll) {
static_cast<const ScrollViewEventEmitter &>(*_eventEmitter).onMomentumScrollEnd([self _scrollViewMetrics]);
}
static_cast<const ScrollViewEventEmitter &>(*_eventEmitter).onScrollBeginDrag([self _scrollViewMetrics]);
_isUserTriggeredScrolling = YES;
}
Expand Down Expand Up @@ -945,6 +961,7 @@ - (void)_updateContentViewSafeAreaPadding
- (void)_handleScrollEndIfNeeded
{
if (_scrollView.isDecelerating || !_scrollView.isTracking) {
_isProgrammaticScrollAnimating = NO;
if (!_eventEmitter) {
return;
}
Expand All @@ -960,11 +977,16 @@ - (void)_handleFinishedScrolling:(UIScrollView *)scrollView
[self _forceDispatchNextScrollEvent];
[self scrollViewDidScroll:scrollView];

BOOL finishedProgrammaticScroll = _isProgrammaticScrollAnimating;
_isProgrammaticScrollAnimating = NO;

if (!_eventEmitter) {
return;
}

static_cast<const ScrollViewEventEmitter &>(*_eventEmitter).onMomentumScrollEnd([self _scrollViewMetrics]);
if (finishedProgrammaticScroll || !ReactNativeFeatureFlags::fixProgrammaticScrollMomentumEventsIOS()) {
static_cast<const ScrollViewEventEmitter &>(*_eventEmitter).onMomentumScrollEnd([self _scrollViewMetrics]);
}
[self _updateStateWithContentOffset];
}

Expand Down Expand Up @@ -1119,12 +1141,54 @@ - (void)scrollToOffset:(CGPoint)offset animated:(BOOL)animated

[self _forceDispatchNextScrollEvent];

[_scrollView setContentOffset:offset animated:animated];
if (!ReactNativeFeatureFlags::fixProgrammaticScrollMomentumEventsIOS()) {
[_scrollView setContentOffset:offset animated:animated];
if (!animated) {
[self _handleFinishedScrolling:_scrollView];
}
return;
}

if (!animated) {
[_scrollView setContentOffset:offset animated:NO];
// When not animated, the expected workflow in ``scrollViewDidEndScrollingAnimation`` after scrolling is not going
// to get triggered. We will need to manually execute here.
[self _handleFinishedScrolling:_scrollView];
return;
}

// Dispatch begin before starting the animation: UIKit can finish it synchronously, and the end event must never
// precede its begin event.
if (!_isProgrammaticScrollAnimating && _eventEmitter) {
static_cast<const ScrollViewEventEmitter &>(*_eventEmitter).onMomentumScrollBegin([self _scrollViewMetrics]);
}
_isProgrammaticScrollAnimating = YES;
NSUInteger generation = ++_programmaticScrollGeneration;

[_scrollView setContentOffset:offset animated:YES];

if (_isProgrammaticScrollAnimating &&
(self.window == nil || CGPointEqualToPoint(_scrollView.contentOffset, offset))) {
// UIKit applied the offset without animating, so ``scrollViewDidEndScrollingAnimation`` will not be called.
[self _handleFinishedScrolling:_scrollView];
return;
}

// An unmatched begin event makes the JS scroll view capture every touch, so guarantee the end event even if UIKit
// stops the animation without calling ``scrollViewDidEndScrollingAnimation``.
__weak RCTScrollViewComponentView *weakSelf = self;
dispatch_after(
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kProgrammaticScrollEndFallbackDelay * NSEC_PER_SEC)),
dispatch_get_main_queue(),
^{
[weakSelf _finishProgrammaticScrollIfStalled:generation];
});
}

- (void)_finishProgrammaticScrollIfStalled:(NSUInteger)generation
{
if (_isProgrammaticScrollAnimating && generation == _programmaticScrollGeneration) {
[self _handleFinishedScrolling:_scrollView];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<c129d87ae4a503699e961bbefd90ff47>>
* @generated SignedSource<<99c0c14cf6e3eca24e7bf1c7eaf64d07>>
*/

/**
Expand Down Expand Up @@ -402,6 +402,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean = accessor.fixMappingOfEventPrioritiesBetweenFabricAndReact()

/**
* Dispatches `onMomentumScrollBegin` and `onMomentumScrollEnd` as an ordered pair for animated programmatic scrolls on iOS, and neither for non-animated programmatic scrolls.
*/
@JvmStatic
public fun fixProgrammaticScrollMomentumEventsIOS(): Boolean = accessor.fixProgrammaticScrollMomentumEventsIOS()

/**
* Grows lines of text with `lineHeight` to fit taller inline views instead of letting them overflow, keeps lines after an inline view at `lineHeight` on Android, and aligns inline views with the text baseline on iOS.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<bb70e27d2c7bd68046613d2b4dda836c>>
* @generated SignedSource<<cee48ed67cacf26a8625a146d6bd4fbd>>
*/

/**
Expand Down Expand Up @@ -82,6 +82,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
private var enableVirtualViewContainerStateExperimentalCache: Boolean? = null
private var fixBorderlessRippleAndroidCache: Boolean? = null
private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null
private var fixProgrammaticScrollMomentumEventsIOSCache: Boolean? = null
private var fixTextInlineViewLineHeightCache: Boolean? = null
private var fixTextLayoutOnPixelDensityChangeCache: Boolean? = null
private var fixYogaFlexBasisFitContentInMainAxisCache: Boolean? = null
Expand Down Expand Up @@ -678,6 +679,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun fixProgrammaticScrollMomentumEventsIOS(): Boolean {
var cached = fixProgrammaticScrollMomentumEventsIOSCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.fixProgrammaticScrollMomentumEventsIOS()
fixProgrammaticScrollMomentumEventsIOSCache = cached
}
return cached
}

override fun fixTextInlineViewLineHeight(): Boolean {
var cached = fixTextInlineViewLineHeightCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<c283b77ee5b5929aa51edef8acaa1dd2>>
* @generated SignedSource<<ef7526b6b18e20db71fe54d43218ab69>>
*/

/**
Expand Down Expand Up @@ -152,6 +152,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean

@DoNotStrip @JvmStatic public external fun fixProgrammaticScrollMomentumEventsIOS(): Boolean

@DoNotStrip @JvmStatic public external fun fixTextInlineViewLineHeight(): Boolean

@DoNotStrip @JvmStatic public external fun fixTextLayoutOnPixelDensityChange(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a6e573f156e7cde50177a92173623b32>>
* @generated SignedSource<<26569f7cbc370133de7e8948ee2d4151>>
*/

/**
Expand Down Expand Up @@ -147,6 +147,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean = false

override fun fixProgrammaticScrollMomentumEventsIOS(): Boolean = false

override fun fixTextInlineViewLineHeight(): Boolean = false

override fun fixTextLayoutOnPixelDensityChange(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<4d0de8e6c65d709e98e638afb976a665>>
* @generated SignedSource<<f20f5ce06d72bb7256dbc280dbe8b76f>>
*/

/**
Expand Down Expand Up @@ -86,6 +86,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
private var enableVirtualViewContainerStateExperimentalCache: Boolean? = null
private var fixBorderlessRippleAndroidCache: Boolean? = null
private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null
private var fixProgrammaticScrollMomentumEventsIOSCache: Boolean? = null
private var fixTextInlineViewLineHeightCache: Boolean? = null
private var fixTextLayoutOnPixelDensityChangeCache: Boolean? = null
private var fixYogaFlexBasisFitContentInMainAxisCache: Boolean? = null
Expand Down Expand Up @@ -744,6 +745,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}

override fun fixProgrammaticScrollMomentumEventsIOS(): Boolean {
var cached = fixProgrammaticScrollMomentumEventsIOSCache
if (cached == null) {
cached = currentProvider.fixProgrammaticScrollMomentumEventsIOS()
accessedFeatureFlags.add("fixProgrammaticScrollMomentumEventsIOS")
fixProgrammaticScrollMomentumEventsIOSCache = cached
}
return cached
}

override fun fixTextInlineViewLineHeight(): Boolean {
var cached = fixTextInlineViewLineHeightCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<0aa6021a35e690e00686c95c387017f6>>
* @generated SignedSource<<f516272583021236cf5a1594b80104b2>>
*/

/**
Expand Down Expand Up @@ -33,6 +33,8 @@ public open class ReactNativeFeatureFlagsOverrides_RNOSS_Canary_Android : ReactN

override fun fixBorderlessRippleAndroid(): Boolean = true

override fun fixProgrammaticScrollMomentumEventsIOS(): Boolean = true

override fun fixTextInlineViewLineHeight(): Boolean = true

override fun optimizedAnimatedPropUpdates(): Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<337c8d0d14616dccbf881c443ffb0519>>
* @generated SignedSource<<8e0059eadd2b19c49b64bb57121ba723>>
*/

/**
Expand Down Expand Up @@ -147,6 +147,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean

@DoNotStrip public fun fixProgrammaticScrollMomentumEventsIOS(): Boolean

@DoNotStrip public fun fixTextInlineViewLineHeight(): Boolean

@DoNotStrip public fun fixTextLayoutOnPixelDensityChange(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<9ef15f2ab900b3afa8d01fcdbf9de178>>
* @generated SignedSource<<53efcbcc0b7fb4f8da094449e96e1584>>
*/

/**
Expand Down Expand Up @@ -411,6 +411,12 @@ class ReactNativeFeatureFlagsJavaProvider
return method(javaProvider_);
}

bool fixProgrammaticScrollMomentumEventsIOS() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("fixProgrammaticScrollMomentumEventsIOS");
return method(javaProvider_);
}

bool fixTextInlineViewLineHeight() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("fixTextInlineViewLineHeight");
Expand Down Expand Up @@ -947,6 +953,11 @@ bool JReactNativeFeatureFlagsCxxInterop::fixMappingOfEventPrioritiesBetweenFabri
return ReactNativeFeatureFlags::fixMappingOfEventPrioritiesBetweenFabricAndReact();
}

bool JReactNativeFeatureFlagsCxxInterop::fixProgrammaticScrollMomentumEventsIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::fixProgrammaticScrollMomentumEventsIOS();
}

bool JReactNativeFeatureFlagsCxxInterop::fixTextInlineViewLineHeight(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::fixTextInlineViewLineHeight();
Expand Down Expand Up @@ -1349,6 +1360,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"fixMappingOfEventPrioritiesBetweenFabricAndReact",
JReactNativeFeatureFlagsCxxInterop::fixMappingOfEventPrioritiesBetweenFabricAndReact),
makeNativeMethod(
"fixProgrammaticScrollMomentumEventsIOS",
JReactNativeFeatureFlagsCxxInterop::fixProgrammaticScrollMomentumEventsIOS),
makeNativeMethod(
"fixTextInlineViewLineHeight",
JReactNativeFeatureFlagsCxxInterop::fixTextInlineViewLineHeight),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<c7e5acf7c692554ccb953fc404797ba4>>
* @generated SignedSource<<ec2699ae9f8ee37d8776217d3d974dac>>
*/

/**
Expand Down Expand Up @@ -216,6 +216,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool fixMappingOfEventPrioritiesBetweenFabricAndReact(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool fixProgrammaticScrollMomentumEventsIOS(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool fixTextInlineViewLineHeight(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<8fd30d0d29edead0c8d39d9f2107972e>>
* @generated SignedSource<<fefa483947602384bd254d00eec4d699>>
*/

/**
Expand Down Expand Up @@ -274,6 +274,10 @@ bool ReactNativeFeatureFlags::fixMappingOfEventPrioritiesBetweenFabricAndReact()
return getAccessor().fixMappingOfEventPrioritiesBetweenFabricAndReact();
}

bool ReactNativeFeatureFlags::fixProgrammaticScrollMomentumEventsIOS() {
return getAccessor().fixProgrammaticScrollMomentumEventsIOS();
}

bool ReactNativeFeatureFlags::fixTextInlineViewLineHeight() {
return getAccessor().fixTextInlineViewLineHeight();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<c012669db7d678ea9eb9807e7af401a4>>
* @generated SignedSource<<f20f175d0628995e9659684d0803f997>>
*/

/**
Expand Down Expand Up @@ -351,6 +351,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool fixMappingOfEventPrioritiesBetweenFabricAndReact();

/**
* Dispatches `onMomentumScrollBegin` and `onMomentumScrollEnd` as an ordered pair for animated programmatic scrolls on iOS, and neither for non-animated programmatic scrolls.
*/
RN_EXPORT static bool fixProgrammaticScrollMomentumEventsIOS();

/**
* Grows lines of text with `lineHeight` to fit taller inline views instead of letting them overflow, keeps lines after an inline view at `lineHeight` on Android, and aligns inline views with the text baseline on iOS.
*/
Expand Down
Loading
Loading