Skip to content

Commit

Permalink
Move RCTScrollEvent into separate file
Browse files Browse the repository at this point in the history
Summary: Move RCTScrollEvent into separate file and export its header.

Reviewed By: shergin

Differential Revision: D17831709

fbshipit-source-id: f4ee4e09147ef5703b85a10238ddb6cdefdf05a5
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Oct 11, 2019
1 parent 93df739 commit 1ba67fd
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 127 deletions.
4 changes: 2 additions & 2 deletions RNTester/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ DEPENDENCIES:
- Yoga (from `../ReactCommon/yoga`)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
https://github.com/CocoaPods/Specs.git:
- boost-for-react-native

EXTERNAL SOURCES:
Expand Down Expand Up @@ -385,4 +385,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 060903e270072f1e192b064848e6c34528af1c87

COCOAPODS: 1.7.1
COCOAPODS: 1.8.3
23 changes: 23 additions & 0 deletions React/Views/ScrollView/RCTScrollEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// RCTScrollEvent.h
// RCTCxxBridgeApple
//
// Created by Samuel Susla on 08/10/2019.
//

#import <Foundation/Foundation.h>
#import <React/RCTEventDispatcher.h>

@interface RCTScrollEvent : NSObject <RCTEvent>

- (instancetype)initWithEventName:(NSString *)eventName
reactTag:(NSNumber *)reactTag
scrollViewContentOffset:(CGPoint)scrollViewContentOffset
scrollViewContentInset:(UIEdgeInsets)scrollViewContentInset
scrollViewContentSize:(CGSize)scrollViewContentSize
scrollViewFrame:(CGRect)scrollViewFrame
scrollViewZoomScale:(CGFloat)scrollViewZoomScale
userData:(NSDictionary *)userData
coalescingKey:(uint16_t)coalescingKey NS_DESIGNATED_INITIALIZER;

@end
118 changes: 118 additions & 0 deletions React/Views/ScrollView/RCTScrollEvent.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//
// RCTScrollEvent.m
// RCTCxxBridgeApple
//
// Created by Samuel Susla on 08/10/2019.
//

#import "RCTScrollEvent.h"
#import <React/RCTAssert.h>

@implementation RCTScrollEvent
{
CGPoint _scrollViewContentOffset;
UIEdgeInsets _scrollViewContentInset;
CGSize _scrollViewContentSize;
CGRect _scrollViewFrame;
CGFloat _scrollViewZoomScale;
NSDictionary *_userData;
uint16_t _coalescingKey;
}

@synthesize viewTag = _viewTag;
@synthesize eventName = _eventName;

- (instancetype)initWithEventName:(NSString *)eventName
reactTag:(NSNumber *)reactTag
scrollViewContentOffset:(CGPoint)scrollViewContentOffset
scrollViewContentInset:(UIEdgeInsets)scrollViewContentInset
scrollViewContentSize:(CGSize)scrollViewContentSize
scrollViewFrame:(CGRect)scrollViewFrame
scrollViewZoomScale:(CGFloat)scrollViewZoomScale
userData:(NSDictionary *)userData
coalescingKey:(uint16_t)coalescingKey
{
RCTAssertParam(reactTag);

if ((self = [super init])) {
_eventName = [eventName copy];
_viewTag = reactTag;
_scrollViewContentOffset = scrollViewContentOffset;
_scrollViewContentInset = scrollViewContentInset;
_scrollViewContentSize = scrollViewContentSize;
_scrollViewFrame = scrollViewFrame;
_scrollViewZoomScale = scrollViewZoomScale;
_userData = userData;
_coalescingKey = coalescingKey;
}
return self;
}

RCT_NOT_IMPLEMENTED(- (instancetype)init)

- (uint16_t)coalescingKey
{
return _coalescingKey;
}

- (NSDictionary *)body
{
NSDictionary *body = @{
@"contentOffset": @{
@"x": @(_scrollViewContentOffset.x),
@"y": @(_scrollViewContentOffset.y)
},
@"contentInset": @{
@"top": @(_scrollViewContentInset.top),
@"left": @(_scrollViewContentInset.left),
@"bottom": @(_scrollViewContentInset.bottom),
@"right": @(_scrollViewContentInset.right)
},
@"contentSize": @{
@"width": @(_scrollViewContentSize.width),
@"height": @(_scrollViewContentSize.height)
},
@"layoutMeasurement": @{
@"width": @(_scrollViewFrame.size.width),
@"height": @(_scrollViewFrame.size.height)
},
@"zoomScale": @(_scrollViewZoomScale ?: 1),
};

if (_userData) {
NSMutableDictionary *mutableBody = [body mutableCopy];
[mutableBody addEntriesFromDictionary:_userData];
body = mutableBody;
}

return body;
}

- (BOOL)canCoalesce
{
return YES;
}

- (RCTScrollEvent *)coalesceWithEvent:(RCTScrollEvent *)newEvent
{
NSArray<NSDictionary *> *updatedChildFrames = [_userData[@"updatedChildFrames"] arrayByAddingObjectsFromArray:newEvent->_userData[@"updatedChildFrames"]];
if (updatedChildFrames) {
NSMutableDictionary *userData = [newEvent->_userData mutableCopy];
userData[@"updatedChildFrames"] = updatedChildFrames;
newEvent->_userData = userData;
}

return newEvent;
}

+ (NSString *)moduleDotMethod
{
return @"RCTEventEmitter.receiveEvent";
}

- (NSArray *)arguments
{
return @[self.viewTag, RCTNormalizeInputEventName(self.eventName), [self body]];
}

@end
126 changes: 1 addition & 125 deletions React/Views/ScrollView/RCTScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,142 +10,19 @@
#import <UIKit/UIKit.h>

#import "RCTConvert.h"
#import "RCTEventDispatcher.h"
#import "RCTLog.h"
#import "RCTUIManager.h"
#import "RCTUIManagerObserverCoordinator.h"
#import "RCTUIManagerUtils.h"
#import "RCTUtils.h"
#import "UIView+Private.h"
#import "UIView+React.h"
#import "RCTScrollEvent.h"

#if !TARGET_OS_TV
#import "RCTRefreshControl.h"
#endif

@interface RCTScrollEvent : NSObject <RCTEvent>

- (instancetype)initWithEventName:(NSString *)eventName
reactTag:(NSNumber *)reactTag
scrollViewContentOffset:(CGPoint)scrollViewContentOffset
scrollViewContentInset:(UIEdgeInsets)scrollViewContentInset
scrollViewContentSize:(CGSize)scrollViewContentSize
scrollViewFrame:(CGRect)scrollViewFrame
scrollViewZoomScale:(CGFloat)scrollViewZoomScale
userData:(NSDictionary *)userData
coalescingKey:(uint16_t)coalescingKey NS_DESIGNATED_INITIALIZER;

@end

@implementation RCTScrollEvent
{
CGPoint _scrollViewContentOffset;
UIEdgeInsets _scrollViewContentInset;
CGSize _scrollViewContentSize;
CGRect _scrollViewFrame;
CGFloat _scrollViewZoomScale;
NSDictionary *_userData;
uint16_t _coalescingKey;
}

@synthesize viewTag = _viewTag;
@synthesize eventName = _eventName;

- (instancetype)initWithEventName:(NSString *)eventName
reactTag:(NSNumber *)reactTag
scrollViewContentOffset:(CGPoint)scrollViewContentOffset
scrollViewContentInset:(UIEdgeInsets)scrollViewContentInset
scrollViewContentSize:(CGSize)scrollViewContentSize
scrollViewFrame:(CGRect)scrollViewFrame
scrollViewZoomScale:(CGFloat)scrollViewZoomScale
userData:(NSDictionary *)userData
coalescingKey:(uint16_t)coalescingKey
{
RCTAssertParam(reactTag);

if ((self = [super init])) {
_eventName = [eventName copy];
_viewTag = reactTag;
_scrollViewContentOffset = scrollViewContentOffset;
_scrollViewContentInset = scrollViewContentInset;
_scrollViewContentSize = scrollViewContentSize;
_scrollViewFrame = scrollViewFrame;
_scrollViewZoomScale = scrollViewZoomScale;
_userData = userData;
_coalescingKey = coalescingKey;
}
return self;
}

RCT_NOT_IMPLEMENTED(- (instancetype)init)

- (uint16_t)coalescingKey
{
return _coalescingKey;
}

- (NSDictionary *)body
{
NSDictionary *body = @{
@"contentOffset": @{
@"x": @(_scrollViewContentOffset.x),
@"y": @(_scrollViewContentOffset.y)
},
@"contentInset": @{
@"top": @(_scrollViewContentInset.top),
@"left": @(_scrollViewContentInset.left),
@"bottom": @(_scrollViewContentInset.bottom),
@"right": @(_scrollViewContentInset.right)
},
@"contentSize": @{
@"width": @(_scrollViewContentSize.width),
@"height": @(_scrollViewContentSize.height)
},
@"layoutMeasurement": @{
@"width": @(_scrollViewFrame.size.width),
@"height": @(_scrollViewFrame.size.height)
},
@"zoomScale": @(_scrollViewZoomScale ?: 1),
};

if (_userData) {
NSMutableDictionary *mutableBody = [body mutableCopy];
[mutableBody addEntriesFromDictionary:_userData];
body = mutableBody;
}

return body;
}

- (BOOL)canCoalesce
{
return YES;
}

- (RCTScrollEvent *)coalesceWithEvent:(RCTScrollEvent *)newEvent
{
NSArray<NSDictionary *> *updatedChildFrames = [_userData[@"updatedChildFrames"] arrayByAddingObjectsFromArray:newEvent->_userData[@"updatedChildFrames"]];
if (updatedChildFrames) {
NSMutableDictionary *userData = [newEvent->_userData mutableCopy];
userData[@"updatedChildFrames"] = updatedChildFrames;
newEvent->_userData = userData;
}

return newEvent;
}

+ (NSString *)moduleDotMethod
{
return @"RCTEventEmitter.receiveEvent";
}

- (NSArray *)arguments
{
return @[self.viewTag, RCTNormalizeInputEventName(self.eventName), [self body]];
}

@end

/**
* Include a custom scroll view subclass because we want to limit certain
* default UIKit behaviors such as textFields automatically scrolling
Expand All @@ -161,7 +38,6 @@ @interface RCTCustomScrollView : UIScrollView<UIGestureRecognizerDelegate>

@end


@implementation RCTCustomScrollView

- (instancetype)initWithFrame:(CGRect)frame
Expand Down

0 comments on commit 1ba67fd

Please sign in to comment.