Skip to content

Commit

Permalink
Add support for ScrollView.onScroll animations
Browse files Browse the repository at this point in the history
Summary: To enable onScroll animations with Fabric's scrollView on iOS, we dispatch onScroll event to Paper's eventDispatcher as well as to Fabric's one. One we have a proper NativeAnimationDriver in place, we will get rid of this.

Reviewed By: shergin

Differential Revision: D17814260

fbshipit-source-id: f04faf59cdfd4ea5cede513388e30500b4cb2ad5
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Oct 11, 2019
1 parent 90977b0 commit ffc7ec9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#import "RCTScrollViewComponentView.h"

#import <React/RCTAssert.h>
#import <React/RCTBridge+Private.h>
#import <React/RCTScrollEvent.h>

#import <react/components/scrollview/ScrollViewComponentDescriptor.h>
#import <react/components/scrollview/ScrollViewEventEmitter.h>
Expand All @@ -20,6 +22,21 @@

using namespace facebook::react;

static void RCTSendPaperScrollEvent_DEPRECATED(UIScrollView *scrollView, NSInteger tag)
{
static uint16_t coalescingKey = 0;
RCTScrollEvent *scrollEvent = [[RCTScrollEvent alloc] initWithEventName:@"onScroll"
reactTag:[NSNumber numberWithInt:tag]
scrollViewContentOffset:scrollView.contentOffset
scrollViewContentInset:scrollView.contentInset
scrollViewContentSize:scrollView.contentSize
scrollViewFrame:scrollView.frame
scrollViewZoomScale:scrollView.zoomScale
userData:nil
coalescingKey:coalescingKey];
[[RCTBridge currentBridge].eventDispatcher sendEvent:scrollEvent];
}

@interface RCTScrollViewComponentView () <UIScrollViewDelegate>

@end
Expand Down Expand Up @@ -211,6 +228,9 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
if ((_lastScrollEventDispatchTime == 0) || (now - _lastScrollEventDispatchTime > _scrollEventThrottle)) {
_lastScrollEventDispatchTime = now;
std::static_pointer_cast<ScrollViewEventEmitter const>(_eventEmitter)->onScroll([self _scrollViewMetrics]);
// Once Fabric implements proper NativeAnimationDriver, this should be removed.
// This is just a workaround to allow animations based on onScroll event.
RCTSendPaperScrollEvent_DEPRECATED(scrollView, self.tag);
}
}

Expand Down
17 changes: 16 additions & 1 deletion React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,22 @@ - (void)registerRootView:(RCTRootContentView *)rootView
- (NSString *)viewNameForReactTag:(NSNumber *)reactTag
{
RCTAssertUIManagerQueue();
return _shadowViewRegistry[reactTag].viewName;
NSString *name = _shadowViewRegistry[reactTag].viewName;
if (name) {
return name;
}

UIView *view = _viewRegistry[reactTag];

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"

if ([view respondsToSelector:@selector(componentViewName_DO_NOT_USE_THIS_IS_BROKEN)]) {
return [view performSelector:@selector(componentViewName_DO_NOT_USE_THIS_IS_BROKEN)];
}

#pragma clang diagnostic pop
return nil;
}

- (UIView *)viewForReactTag:(NSNumber *)reactTag
Expand Down

0 comments on commit ffc7ec9

Please sign in to comment.