mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Revert D41273822: Add fabric support for maintainVisibleContentPosition on iOS
Differential Revision: D41273822 (https://github.com/facebook/react-native/commit/ecf967a51d358f3759acbf7795675f52d7190280) Original commit changeset: 7900898f2828 Original Phabricator Diff: D41273822 (https://github.com/facebook/react-native/commit/ecf967a51d358f3759acbf7795675f52d7190280) fbshipit-source-id: 0f4b9695c805407b9a41b0fec63784bd0e84be43
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d31670b4d9
commit
9d98e2cb07
@@ -22,7 +22,6 @@
|
||||
#import "RCTConversions.h"
|
||||
#import "RCTEnhancedScrollView.h"
|
||||
#import "RCTFabricComponentsPlugins.h"
|
||||
#import "RCTPullToRefreshViewComponentView.h"
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
@@ -100,11 +99,6 @@ static void RCTSendScrollEventForNativeAnimations_DEPRECATED(UIScrollView *scrol
|
||||
BOOL _shouldUpdateContentInsetAdjustmentBehavior;
|
||||
|
||||
CGPoint _contentOffsetWhenClipped;
|
||||
|
||||
__weak UIView *_contentView;
|
||||
|
||||
CGRect _prevFirstVisibleFrame;
|
||||
__weak UIView *_firstVisibleView;
|
||||
}
|
||||
|
||||
+ (RCTScrollViewComponentView *_Nullable)findScrollViewComponentViewForView:(UIView *)view
|
||||
@@ -154,17 +148,10 @@ static void RCTSendScrollEventForNativeAnimations_DEPRECATED(UIScrollView *scrol
|
||||
|
||||
#pragma mark - RCTMountingTransactionObserving
|
||||
|
||||
- (void)mountingTransactionWillMount:(const facebook::react::MountingTransaction &)transaction
|
||||
withSurfaceTelemetry:(const facebook::react::SurfaceTelemetry &)surfaceTelemetry
|
||||
{
|
||||
[self _prepareForMaintainVisibleScrollPosition];
|
||||
}
|
||||
|
||||
- (void)mountingTransactionDidMount:(MountingTransaction const &)transaction
|
||||
withSurfaceTelemetry:(facebook::react::SurfaceTelemetry const &)surfaceTelemetry
|
||||
{
|
||||
[self _remountChildren];
|
||||
[self _adjustForMaintainVisibleContentPosition];
|
||||
}
|
||||
|
||||
#pragma mark - RCTComponentViewProtocol
|
||||
@@ -349,23 +336,11 @@ static void RCTSendScrollEventForNativeAnimations_DEPRECATED(UIScrollView *scrol
|
||||
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
|
||||
{
|
||||
[_containerView insertSubview:childComponentView atIndex:index];
|
||||
if ([childComponentView isKindOfClass:RCTPullToRefreshViewComponentView.class]) {
|
||||
// Ignore the pull to refresh component.
|
||||
} else {
|
||||
RCTAssert(_contentView == nil, @"RCTScrollView may only contain a single subview.");
|
||||
_contentView = childComponentView;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
|
||||
{
|
||||
[childComponentView removeFromSuperview];
|
||||
if ([childComponentView isKindOfClass:RCTPullToRefreshViewComponentView.class]) {
|
||||
// Ignore the pull to refresh component.
|
||||
} else {
|
||||
RCTAssert(_contentView == childComponentView, @"Attempted to remove non-existent subview");
|
||||
_contentView = nil;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -428,9 +403,6 @@ static void RCTSendScrollEventForNativeAnimations_DEPRECATED(UIScrollView *scrol
|
||||
CGRect oldFrame = self.frame;
|
||||
self.frame = CGRectZero;
|
||||
self.frame = oldFrame;
|
||||
_contentView = nil;
|
||||
_prevFirstVisibleFrame = CGRectZero;
|
||||
_firstVisibleView = nil;
|
||||
[super prepareForRecycle];
|
||||
}
|
||||
|
||||
@@ -711,74 +683,6 @@ static void RCTSendScrollEventForNativeAnimations_DEPRECATED(UIScrollView *scrol
|
||||
[self.scrollViewDelegateSplitter removeDelegate:scrollListener];
|
||||
}
|
||||
|
||||
#pragma mark - Maintain visible content position
|
||||
|
||||
- (void)_prepareForMaintainVisibleScrollPosition
|
||||
{
|
||||
const auto &props = *std::static_pointer_cast<const ScrollViewProps>(_props);
|
||||
if (!props.maintainVisibleContentPosition) {
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL horizontal = _scrollView.contentSize.width > self.frame.size.width;
|
||||
int minIdx = props.maintainVisibleContentPosition.value().minIndexForVisible;
|
||||
for (NSUInteger ii = minIdx; ii < _contentView.subviews.count; ++ii) {
|
||||
// Find the first entirely visible view.
|
||||
UIView *subview = _contentView.subviews[ii];
|
||||
BOOL hasNewView = NO;
|
||||
if (horizontal) {
|
||||
hasNewView = subview.frame.origin.x > _scrollView.contentOffset.x;
|
||||
} else {
|
||||
hasNewView = subview.frame.origin.y > _scrollView.contentOffset.y;
|
||||
}
|
||||
if (hasNewView || ii == _contentView.subviews.count - 1) {
|
||||
_prevFirstVisibleFrame = subview.frame;
|
||||
_firstVisibleView = subview;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_adjustForMaintainVisibleContentPosition
|
||||
{
|
||||
const auto &props = *std::static_pointer_cast<const ScrollViewProps>(_props);
|
||||
if (!props.maintainVisibleContentPosition) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::optional<int> autoscrollThreshold = props.maintainVisibleContentPosition.value().autoscrollToTopThreshold;
|
||||
BOOL horizontal = _scrollView.contentSize.width > self.frame.size.width;
|
||||
// TODO: detect and handle/ignore re-ordering
|
||||
if (horizontal) {
|
||||
CGFloat deltaX = _firstVisibleView.frame.origin.x - _prevFirstVisibleFrame.origin.x;
|
||||
if (ABS(deltaX) > 0.5) {
|
||||
CGFloat x = _scrollView.contentOffset.x;
|
||||
[self _forceDispatchNextScrollEvent];
|
||||
_scrollView.contentOffset = CGPointMake(_scrollView.contentOffset.x + deltaX, _scrollView.contentOffset.y);
|
||||
if (autoscrollThreshold) {
|
||||
// If the offset WAS within the threshold of the start, animate to the start.
|
||||
if (x <= autoscrollThreshold.value()) {
|
||||
[self scrollToOffset:CGPointMake(0, _scrollView.contentOffset.y) animated:YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
CGRect newFrame = _firstVisibleView.frame;
|
||||
CGFloat deltaY = newFrame.origin.y - _prevFirstVisibleFrame.origin.y;
|
||||
if (ABS(deltaY) > 0.5) {
|
||||
CGFloat y = _scrollView.contentOffset.y;
|
||||
[self _forceDispatchNextScrollEvent];
|
||||
_scrollView.contentOffset = CGPointMake(_scrollView.contentOffset.x, _scrollView.contentOffset.y + deltaY);
|
||||
if (autoscrollThreshold) {
|
||||
// If the offset WAS within the threshold of the start, animate to the start.
|
||||
if (y <= autoscrollThreshold.value()) {
|
||||
[self scrollToOffset:CGPointMake(_scrollView.contentOffset.x, 0) animated:YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Class<RCTComponentViewProtocol> RCTScrollViewCls(void)
|
||||
|
||||
@@ -127,15 +127,6 @@ ScrollViewProps::ScrollViewProps(
|
||||
"keyboardDismissMode",
|
||||
sourceProps.keyboardDismissMode,
|
||||
{})),
|
||||
maintainVisibleContentPosition(
|
||||
CoreFeatures::enablePropIteratorSetter
|
||||
? sourceProps.maintainVisibleContentPosition
|
||||
: convertRawProp(
|
||||
context,
|
||||
rawProps,
|
||||
"maintainVisibleContentPosition",
|
||||
sourceProps.maintainVisibleContentPosition,
|
||||
{})),
|
||||
maximumZoomScale(
|
||||
CoreFeatures::enablePropIteratorSetter
|
||||
? sourceProps.maximumZoomScale
|
||||
@@ -346,7 +337,6 @@ void ScrollViewProps::setProp(
|
||||
RAW_SET_PROP_SWITCH_CASE_BASIC(directionalLockEnabled);
|
||||
RAW_SET_PROP_SWITCH_CASE_BASIC(indicatorStyle);
|
||||
RAW_SET_PROP_SWITCH_CASE_BASIC(keyboardDismissMode);
|
||||
RAW_SET_PROP_SWITCH_CASE_BASIC(maintainVisibleContentPosition);
|
||||
RAW_SET_PROP_SWITCH_CASE_BASIC(maximumZoomScale);
|
||||
RAW_SET_PROP_SWITCH_CASE_BASIC(minimumZoomScale);
|
||||
RAW_SET_PROP_SWITCH_CASE_BASIC(scrollEnabled);
|
||||
@@ -423,10 +413,6 @@ SharedDebugStringConvertibleList ScrollViewProps::getDebugProps() const {
|
||||
"keyboardDismissMode",
|
||||
keyboardDismissMode,
|
||||
defaultScrollViewProps.keyboardDismissMode),
|
||||
debugStringConvertibleItem(
|
||||
"maintainVisibleContentPosition",
|
||||
maintainVisibleContentPosition,
|
||||
defaultScrollViewProps.maintainVisibleContentPosition),
|
||||
debugStringConvertibleItem(
|
||||
"maximumZoomScale",
|
||||
maximumZoomScale,
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
#include <react/renderer/components/view/ViewProps.h>
|
||||
#include <react/renderer/core/PropsParserContext.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
@@ -45,8 +43,6 @@ class ScrollViewProps final : public ViewProps {
|
||||
bool directionalLockEnabled{};
|
||||
ScrollViewIndicatorStyle indicatorStyle{};
|
||||
ScrollViewKeyboardDismissMode keyboardDismissMode{};
|
||||
std::optional<ScrollViewMaintainVisibleContentPosition>
|
||||
maintainVisibleContentPosition{};
|
||||
Float maximumZoomScale{1.0f};
|
||||
Float minimumZoomScale{1.0f};
|
||||
bool scrollEnabled{true};
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include <folly/dynamic.h>
|
||||
#include <react/renderer/components/scrollview/primitives.h>
|
||||
#include <react/renderer/core/PropsParserContext.h>
|
||||
#include <react/renderer/core/propsConversions.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
@@ -99,26 +98,6 @@ inline void fromRawValue(
|
||||
abort();
|
||||
}
|
||||
|
||||
inline void fromRawValue(
|
||||
const PropsParserContext &context,
|
||||
const RawValue &value,
|
||||
ScrollViewMaintainVisibleContentPosition &result) {
|
||||
auto map = (butter::map<std::string, RawValue>)value;
|
||||
|
||||
auto minIndexForVisible = map.find("minIndexForVisible");
|
||||
if (minIndexForVisible != map.end()) {
|
||||
fromRawValue(
|
||||
context, minIndexForVisible->second, result.minIndexForVisible);
|
||||
}
|
||||
auto autoscrollToTopThreshold = map.find("autoscrollToTopThreshold");
|
||||
if (autoscrollToTopThreshold != map.end()) {
|
||||
fromRawValue(
|
||||
context,
|
||||
autoscrollToTopThreshold->second,
|
||||
result.autoscrollToTopThreshold);
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string toString(const ScrollViewSnapToAlignment &value) {
|
||||
switch (value) {
|
||||
case ScrollViewSnapToAlignment::Start:
|
||||
@@ -130,8 +109,6 @@ inline std::string toString(const ScrollViewSnapToAlignment &value) {
|
||||
}
|
||||
}
|
||||
|
||||
#if RN_DEBUG_STRING_CONVERTIBLE
|
||||
|
||||
inline std::string toString(const ScrollViewIndicatorStyle &value) {
|
||||
switch (value) {
|
||||
case ScrollViewIndicatorStyle::Default:
|
||||
@@ -167,17 +144,5 @@ inline std::string toString(const ContentInsetAdjustmentBehavior &value) {
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string toString(
|
||||
const std::optional<ScrollViewMaintainVisibleContentPosition> &value) {
|
||||
if (!value) {
|
||||
return "null";
|
||||
}
|
||||
return "{minIndexForVisible: " + toString(value.value().minIndexForVisible) +
|
||||
", autoscrollToTopThreshold: " +
|
||||
toString(value.value().autoscrollToTopThreshold) + "}";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
@@ -25,20 +23,5 @@ enum class ContentInsetAdjustmentBehavior {
|
||||
Always
|
||||
};
|
||||
|
||||
class ScrollViewMaintainVisibleContentPosition final {
|
||||
public:
|
||||
int minIndexForVisible{0};
|
||||
std::optional<int> autoscrollToTopThreshold{};
|
||||
|
||||
bool operator==(const ScrollViewMaintainVisibleContentPosition &rhs) const {
|
||||
return std::tie(this->minIndexForVisible, this->autoscrollToTopThreshold) ==
|
||||
std::tie(rhs.minIndexForVisible, rhs.autoscrollToTopThreshold);
|
||||
}
|
||||
|
||||
bool operator!=(const ScrollViewMaintainVisibleContentPosition &rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include <climits>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
@@ -99,14 +98,6 @@ std::string toString(float const &value);
|
||||
std::string toString(double const &value);
|
||||
std::string toString(void const *value);
|
||||
|
||||
template <typename T>
|
||||
std::string toString(const std::optional<T> &value) {
|
||||
if (!value) {
|
||||
return "null";
|
||||
}
|
||||
return toString(value.value());
|
||||
}
|
||||
|
||||
/*
|
||||
* *Informal* `DebugStringConvertible` interface.
|
||||
*
|
||||
|
||||
@@ -76,7 +76,7 @@ class AppendingList extends React.Component<
|
||||
<ScrollView
|
||||
automaticallyAdjustContentInsets={false}
|
||||
maintainVisibleContentPosition={{
|
||||
minIndexForVisible: 0,
|
||||
minIndexForVisible: 1,
|
||||
autoscrollToTopThreshold: 10,
|
||||
}}
|
||||
nestedScrollEnabled
|
||||
|
||||
Reference in New Issue
Block a user