From 4d83cfbc50fde20f6af2a7ea7edcc218e6a0159c Mon Sep 17 00:00:00 2001 From: Martin Kralik Date: Wed, 3 Feb 2016 05:22:16 -0800 Subject: [PATCH] added RCTTouchEvent (5/7) Summary: This diff adds an implementation of `RCTEvent` protocol which represents touch events. It's basically a copy of this code: https://github.com/facebook/react-native/blob/c14cc123d5be04f109ba2209a3393ee2ffa84149/React/Base/RCTTouchHandler.m#L194-L196 which is replaced using `RCTTouchEvent` in the next diff (D2884593). public ___ //This diff is part of a larger stack. For high level overview what's going on jump to D2884593.// Reviewed By: nicklockwood Differential Revision: D2884592 fb-gh-sync-id: e35addcf15a7012f89644200a08f5856c7f57299 --- React/Base/RCTTouchEvent.h | 23 +++++++++++++++ React/Base/RCTTouchEvent.m | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 React/Base/RCTTouchEvent.h create mode 100644 React/Base/RCTTouchEvent.m diff --git a/React/Base/RCTTouchEvent.h b/React/Base/RCTTouchEvent.h new file mode 100644 index 000000000..5fe3951dc --- /dev/null +++ b/React/Base/RCTTouchEvent.h @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import + +#import "RCTEventDispatcher.h" + +/** + * Represents a touch event, which may be composed of several touches (one for every finger). + * For more information on contents of passed data structures see RCTTouchHandler. + */ +@interface RCTTouchEvent : NSObject + +- (instancetype)initWithEventName:(NSString *)eventName + reactTouches:(NSArray *)reactTouches + changedIndexes:(NSArray *)changedIndexes NS_DESIGNATED_INITIALIZER; +@end diff --git a/React/Base/RCTTouchEvent.m b/React/Base/RCTTouchEvent.m new file mode 100644 index 000000000..780a7bec0 --- /dev/null +++ b/React/Base/RCTTouchEvent.m @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import "RCTTouchEvent.h" + +@implementation RCTTouchEvent +{ + NSArray *_reactTouches; + NSArray *_changedIndexes; +} + +@synthesize eventName = _eventName; +@synthesize viewTag = _viewTag; + +- (instancetype)initWithEventName:(NSString *)eventName + reactTouches:(NSArray *)reactTouches + changedIndexes:(NSArray *)changedIndexes +{ + if (self = [super init]) { + _eventName = eventName; + _reactTouches = reactTouches; + _changedIndexes = changedIndexes; + } + return self; +} + +RCT_NOT_IMPLEMENTED(- (instancetype)init) + +#pragma mark - RCTEvent + +- (BOOL)canCoalesce +{ + return NO; +} + +- (id)coalesceWithEvent:(id)newEvent +{ + return newEvent; +} + ++ (NSString *)moduleDotMethod +{ + return @"RCTEventEmitter.receiveTouches"; +} + +- (NSArray *)arguments +{ + return @[RCTNormalizeInputEventName(_eventName), _reactTouches, _changedIndexes]; +} + +@end