2015-03-23 20:28:42 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-08-06 22:44:15 +00:00
|
|
|
#import <CoreGraphics/CoreGraphics.h>
|
|
|
|
|
Added mechanism for directly mapping JS event handlers to blocks
Summary:
Currently, the system for mapping JS event handlers to blocks is quite clean on the JS side, but is clunky on the native side. The event property is passed as a boolean, which can then be checked by the native side, and if true, the native side is supposed to send an event via the event dispatcher.
This diff adds the facility to declare the property as a block instead. This means that the event side can simply call the block, and it will automatically send the event. Because the blocks for bubbling and direct events are named differently, we can also use this to generate the event registration data and get rid of the arrays of event names.
The name of the event is inferred from the property name, which means that the property for an event called "load" must be called `onLoad` or the mapping won't work. This can be optionally remapped to a different property name on the view itself if necessary, e.g.
RCT_REMAP_VIEW_PROPERTY(onLoad, loadEventBlock, RCTDirectEventBlock)
If you don't want to use this mechanism then for now it is still possible to declare the property as a BOOL instead and use the old mechanism (this approach is now deprecated however, and may eventually be removed altogether).
2015-09-02 12:58:10 +00:00
|
|
|
/**
|
|
|
|
* These block types can be used for mapping input event handlers from JS to view
|
|
|
|
* properties. Unlike JS method callbacks, these can be called multiple times.
|
|
|
|
*/
|
|
|
|
typedef void (^RCTDirectEventBlock)(NSDictionary *body);
|
|
|
|
typedef void (^RCTBubblingEventBlock)(NSDictionary *body);
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-08-06 22:44:15 +00:00
|
|
|
* Logical node in a tree of application components. Both `ShadowView` and
|
|
|
|
* `UIView` conforms to this. Allows us to write utilities that reason about
|
|
|
|
* trees generally.
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
2015-08-06 22:44:15 +00:00
|
|
|
@protocol RCTComponent <NSObject>
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-03-01 23:33:55 +00:00
|
|
|
@property (nonatomic, copy) NSNumber *reactTag;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-08-06 22:44:15 +00:00
|
|
|
- (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex;
|
|
|
|
- (void)removeReactSubview:(id<RCTComponent>)subview;
|
2015-11-03 22:45:46 +00:00
|
|
|
- (NSArray<id<RCTComponent>> *)reactSubviews;
|
2015-08-06 22:44:15 +00:00
|
|
|
- (id<RCTComponent>)reactSuperview;
|
2015-02-20 04:10:52 +00:00
|
|
|
- (NSNumber *)reactTagAtPoint:(CGPoint)point;
|
|
|
|
|
2015-03-25 00:37:03 +00:00
|
|
|
// View/ShadowView is a root view
|
2015-02-20 04:10:52 +00:00
|
|
|
- (BOOL)isReactRootView;
|
|
|
|
|
|
|
|
@optional
|
|
|
|
|
2015-11-27 10:51:58 +00:00
|
|
|
/**
|
|
|
|
* Called each time props have been set.
|
|
|
|
* Not all props have to be set - React can set only changed ones.
|
|
|
|
* @param changedProps String names of all set props.
|
|
|
|
*/
|
|
|
|
- (void)didSetProps:(NSArray<NSString *> *)changedProps;
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
// TODO: Deprecate this
|
2015-03-01 23:33:55 +00:00
|
|
|
// This method is called after layout has been performed for all views known
|
|
|
|
// to the RCTViewManager. It is only called on UIViews, not shadow views.
|
2015-02-20 04:10:52 +00:00
|
|
|
- (void)reactBridgeDidFinishTransaction;
|
|
|
|
|
|
|
|
@end
|
2015-03-06 00:36:41 +00:00
|
|
|
|
|
|
|
// TODO: this is kinda dumb - let's come up with a
|
2015-04-27 20:55:01 +00:00
|
|
|
// better way of identifying root React views please!
|
2015-07-31 18:23:29 +00:00
|
|
|
static inline BOOL RCTIsReactRootView(NSNumber *reactTag)
|
|
|
|
{
|
2015-03-06 00:36:41 +00:00
|
|
|
return reactTag.integerValue % 10 == 1;
|
|
|
|
}
|