-
Notifications
You must be signed in to change notification settings - Fork 24.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move RCTScrollEvent into separate file
Summary: Move RCTScrollEvent into separate file and export its header. Reviewed By: shergin Differential Revision: D17831709 fbshipit-source-id: f4ee4e09147ef5703b85a10238ddb6cdefdf05a5
- Loading branch information
1 parent
93df739
commit 1ba67fd
Showing
4 changed files
with
144 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters