clean up problems

This commit is contained in:
Hailey
2025-05-12 11:20:47 -07:00
parent 7c587bd98b
commit 6ab0ca2bf6
3 changed files with 47 additions and 20 deletions
@@ -2,8 +2,6 @@
#import <React/RCTEnhancedScrollView.h> #import <React/RCTEnhancedScrollView.h>
#import <React/RCTScrollViewComponentView.h> #import <React/RCTScrollViewComponentView.h>
#import <React/RCTRefreshControl.h>
#import <React/RCTPullToRefreshViewComponentView.h>
#import <react/renderer/components/ScrollForwarderViewSpec/ComponentDescriptors.h> #import <react/renderer/components/ScrollForwarderViewSpec/ComponentDescriptors.h>
#import <react/renderer/components/ScrollForwarderViewSpec/EventEmitters.h> #import <react/renderer/components/ScrollForwarderViewSpec/EventEmitters.h>
#import <react/renderer/components/ScrollForwarderViewSpec/Props.h> #import <react/renderer/components/ScrollForwarderViewSpec/Props.h>
@@ -13,10 +11,14 @@
using namespace facebook::react; using namespace facebook::react;
// How far down a pull needs to be to trigger a refresh
static const CGFloat kPullThreshold = 130.0; static const CGFloat kPullThreshold = 130.0;
static const CGFloat kDampingFactor = 0.55; static const CGFloat kDampingFactor = 0.55;
// The top speed that free scrolling can have
static const CGFloat kMaxVelocity = 5000.0; static const CGFloat kMaxVelocity = 5000.0;
// Free scrolling decay. This seems to be close to the default iOS value
static const CGFloat kVelocityDecay = 0.9875; static const CGFloat kVelocityDecay = 0.9875;
// What scroll release velocity will actually trigger free scrolling
static const CGFloat kMinimumVelocity = 5.0; static const CGFloat kMinimumVelocity = 5.0;
@interface ScrollForwarderView () <RCTScrollForwarderViewViewProtocol, UIGestureRecognizerDelegate> @interface ScrollForwarderView () <RCTScrollForwarderViewViewProtocol, UIGestureRecognizerDelegate>
@@ -24,8 +26,6 @@ static const CGFloat kMinimumVelocity = 5.0;
@end @end
@implementation ScrollForwarderView { @implementation ScrollForwarderView {
UIView * _view;
NSArray<UIGestureRecognizer *> * _cancelGestureRecognizers; NSArray<UIGestureRecognizer *> * _cancelGestureRecognizers;
RCTScrollViewComponentView * _svcv; RCTScrollViewComponentView * _svcv;
CGPoint _initialOffset; CGPoint _initialOffset;
@@ -34,6 +34,7 @@ static const CGFloat kMinimumVelocity = 5.0;
CGFloat _currentVelocity; CGFloat _currentVelocity;
CGFloat _accumulatedTranslation; CGFloat _accumulatedTranslation;
bool _refreshing;
bool _didImpact; bool _didImpact;
} }
@@ -48,25 +49,22 @@ static const CGFloat kMinimumVelocity = 5.0;
static const auto defaultProps = std::make_shared<const ScrollForwarderViewProps>(); static const auto defaultProps = std::make_shared<const ScrollForwarderViewProps>();
_props = defaultProps; _props = defaultProps;
_view = [[UIView alloc] init];
UIPanGestureRecognizer *pg = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)]; UIPanGestureRecognizer *pg = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
pg.delegate = self; pg.delegate = self;
pg.cancelsTouchesInView = false;
[self addGestureRecognizer:pg]; [self addGestureRecognizer:pg];
UITapGestureRecognizer *tg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)]; UITapGestureRecognizer *tg = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[tg setEnabled:true]; [tg setEnabled:false];
tg.delegate = self; tg.delegate = self;
UILongPressGestureRecognizer *lpg = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; UILongPressGestureRecognizer *lpg = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
[lpg setMinimumPressDuration:0.01]; [lpg setMinimumPressDuration:0.01];
[lpg setEnabled:true]; [lpg setEnabled:false];
lpg.delegate = self; lpg.delegate = self;
NSArray<UIGestureRecognizer *> *cancelGestureRecognizers = [NSArray arrayWithObjects:lpg, tg, nil]; NSArray<UIGestureRecognizer *> *cancelGestureRecognizers = [NSArray arrayWithObjects:lpg, tg, nil];
_cancelGestureRecognizers = cancelGestureRecognizers; _cancelGestureRecognizers = cancelGestureRecognizers;
self.contentView = _view;
} }
return self; return self;
@@ -80,7 +78,7 @@ static const CGFloat kMinimumVelocity = 5.0;
[self removeCancelGestureRecognizers]; [self removeCancelGestureRecognizers];
_svcv = nil; _svcv = nil;
for (UIGestureRecognizer *gr in self.gestureRecognizers) { for (UIGestureRecognizer *gr in _cancelGestureRecognizers) {
gr.delegate = nil; gr.delegate = nil;
} }
} }
@@ -133,6 +131,7 @@ static const CGFloat kMinimumVelocity = 5.0;
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{ {
[self stopAnimation]; [self stopAnimation];
[super touchesBegan:touches withEvent:event];
} }
// MARK: - Scroll Forwarding // MARK: - Scroll Forwarding
@@ -212,10 +211,11 @@ static const CGFloat kMinimumVelocity = 5.0;
if (gesture.state == UIGestureRecognizerStateEnded) { if (gesture.state == UIGestureRecognizerStateEnded) {
CGPoint velocity = [gesture velocityInView:self]; CGPoint velocity = [gesture velocityInView:self];
if (sv.contentOffset.y <= -kPullThreshold) { // TODO: enable this again
[self refresh]; // if (sv.contentOffset.y <= -kPullThreshold) {
return; // [self refresh];
} // return;
// }
if (sv.contentOffset.y < 0) { if (sv.contentOffset.y < 0) {
CGPoint newOffset = CGPointMake(sv.contentOffset.x, 0); CGPoint newOffset = CGPointMake(sv.contentOffset.x, 0);
@@ -356,7 +356,25 @@ static const CGFloat kMinimumVelocity = 5.0;
- (void)refresh - (void)refresh
{ {
// TODO: implement if (!_svcv) return;
UIScrollView *sv = _svcv.scrollView;
UIRefreshControl *rc = sv.refreshControl;
if (!rc) return;
[UIView animateWithDuration:0.3
delay:0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^(void) {
// Whenever we call this method, the scrollview will always be at a position of
// -130 or less. Scrolling back to -65 simulates the default behavior of RCTRefreshControl
[sv setContentOffset:CGPointMake(0, -65)];
}
completion:^(__unused BOOL finished) {
[rc beginRefreshing];
}
];
} }
Class<RCTComponentViewProtocol> ScrollForwarderViewCls(void) Class<RCTComponentViewProtocol> ScrollForwarderViewCls(void)
@@ -1,10 +1,12 @@
import { import {
default as NativeScrollForwarderView, default as NativeScrollForwarderView,
NativeProps, type NativeProps,
} from './ScrollForwarderViewNativeComponent' } from './ScrollForwarderViewNativeComponent'
export function ScrollForwarderView({children, ...rest}: NativeProps) { export function ScrollForwarderView({children, ...rest}: NativeProps) {
return ( return (
<NativeScrollForwarderView {...rest}>{children}</NativeScrollForwarderView> <NativeScrollForwarderView {...rest} style={{flex: 1}}>
{children}
</NativeScrollForwarderView>
) )
} }
@@ -1,9 +1,16 @@
import {type ViewProps} from 'react-native'
import {
type BubblingEventHandler,
type Int32,
} from 'react-native/Libraries/Types/CodegenTypes'
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent' import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent'
import type {ViewProps} from 'react-native'
import {Int32} from 'react-native/Libraries/Types/CodegenTypes' type OnRefreshEvent = {}
export interface NativeProps extends ViewProps { export interface NativeProps extends ViewProps {
scrollViewTag?: Int32 scrollViewTag?: Int32
onRefresh?: BubblingEventHandler<OnRefreshEvent>
refreshing?: boolean
} }
export default codegenNativeComponent<NativeProps>('ScrollForwarderView') export default codegenNativeComponent<NativeProps>('ScrollForwarderView')