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
|
|
|
|
|
|
|
#import "RCTView.h"
|
|
|
|
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
|
2015-12-01 15:41:20 +00:00
|
|
|
#import "RCTBorderStyle.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
|
|
|
#import "RCTComponent.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
#import "RCTPointerEvents.h"
|
|
|
|
|
|
|
|
@protocol RCTAutoInsetsProtocol;
|
|
|
|
|
2015-05-19 13:21:52 +00:00
|
|
|
@class RCTView;
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
@interface RCTView : UIView
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Accessibility event handlers
|
|
|
|
*/
|
|
|
|
@property (nonatomic, copy) RCTDirectEventBlock onAccessibilityTap;
|
|
|
|
@property (nonatomic, copy) RCTDirectEventBlock onMagicTap;
|
2015-05-19 13:21:52 +00:00
|
|
|
|
2015-03-06 00:36:41 +00:00
|
|
|
/**
|
|
|
|
* Used to control how touch events are processed.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
@property (nonatomic, assign) RCTPointerEvents pointerEvents;
|
|
|
|
|
|
|
|
+ (void)autoAdjustInsetsForView:(UIView<RCTAutoInsetsProtocol> *)parentView
|
|
|
|
withScrollView:(UIScrollView *)scrollView
|
|
|
|
updateOffset:(BOOL)updateOffset;
|
|
|
|
|
2015-03-06 00:36:41 +00:00
|
|
|
/**
|
|
|
|
* Find the first view controller whose view, or any subview is the specified view.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
+ (UIEdgeInsets)contentInsetsForView:(UIView *)curView;
|
|
|
|
|
Implement CSS z-index for iOS
Summary:
This diff implement the CSS z-index for React Native iOS views. We've had numerous pull request for this feature, but they've all attempted to use the `layer.zPosition` property, which is problematic for two reasons:
1. zPosition only affects rendering order, not event processing order. Views with a higher zPosition will appear in front of others in the hierarchy, but won't be the first to receive touch events, and may be blocked by views that are visually behind them.
2. when using a perspective transform matrix, views with a nonzero zPosition will be rendered in a different position due to parallax, which probably isn't desirable.
See https://github.com/facebook/react-native/pull/7825 for further discussion of this problem.
So instead of using `layer.zPosition`, I've implemented this by actually adjusting the order of the subviews within their parent based on the zIndex. This can't be done on the JS side because it would affect layout, which is order-dependent, so I'm doing it inside the view itself.
It works as follows:
1. The `reactSubviews` array is set, whose order matches the order of the JS components and shadowView components, as specified by the UIManager.
2. `didUpdateReactSubviews` is called, which in turn calls `sortedSubviews` (which lazily generates a sorted array of `reactSubviews` by zIndex) and inserts the result into the view.
3. If a subview is added or removed, or the zIndex of any subview is changed, the previous `sortedSubviews` array is cleared and `didUpdateReactSubviews` is called again.
To demonstrate it working, I've modified the UIExplorer example from https://github.com/facebook/react-native/pull/7825
Reviewed By: javache
Differential Revision: D3365717
fbshipit-source-id: b34aa8bfad577bce023f8af5414f9b974aafd8aa
2016-06-07 14:40:25 +00:00
|
|
|
/**
|
|
|
|
* z-index, used to override sibling order in didUpdateReactSubviews. This is
|
|
|
|
* inherited from UIView+React, but we override it here to reduce the boxing
|
|
|
|
* and associated object overheads.
|
|
|
|
*/
|
2016-06-09 16:48:56 +00:00
|
|
|
@property (nonatomic, assign) NSInteger reactZIndex;
|
Implement CSS z-index for iOS
Summary:
This diff implement the CSS z-index for React Native iOS views. We've had numerous pull request for this feature, but they've all attempted to use the `layer.zPosition` property, which is problematic for two reasons:
1. zPosition only affects rendering order, not event processing order. Views with a higher zPosition will appear in front of others in the hierarchy, but won't be the first to receive touch events, and may be blocked by views that are visually behind them.
2. when using a perspective transform matrix, views with a nonzero zPosition will be rendered in a different position due to parallax, which probably isn't desirable.
See https://github.com/facebook/react-native/pull/7825 for further discussion of this problem.
So instead of using `layer.zPosition`, I've implemented this by actually adjusting the order of the subviews within their parent based on the zIndex. This can't be done on the JS side because it would affect layout, which is order-dependent, so I'm doing it inside the view itself.
It works as follows:
1. The `reactSubviews` array is set, whose order matches the order of the JS components and shadowView components, as specified by the UIManager.
2. `didUpdateReactSubviews` is called, which in turn calls `sortedSubviews` (which lazily generates a sorted array of `reactSubviews` by zIndex) and inserts the result into the view.
3. If a subview is added or removed, or the zIndex of any subview is changed, the previous `sortedSubviews` array is cleared and `didUpdateReactSubviews` is called again.
To demonstrate it working, I've modified the UIExplorer example from https://github.com/facebook/react-native/pull/7825
Reviewed By: javache
Differential Revision: D3365717
fbshipit-source-id: b34aa8bfad577bce023f8af5414f9b974aafd8aa
2016-06-07 14:40:25 +00:00
|
|
|
|
2015-03-11 02:03:59 +00:00
|
|
|
/**
|
|
|
|
* This is an optimization used to improve performance
|
|
|
|
* for large scrolling views with many subviews, such as a
|
|
|
|
* list or table. If set to YES, any clipped subviews will
|
|
|
|
* be removed from the view hierarchy whenever -updateClippedSubviews
|
|
|
|
* is called. This would typically be triggered by a scroll event
|
|
|
|
*/
|
|
|
|
@property (nonatomic, assign) BOOL removeClippedSubviews;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide subviews if they are outside the view bounds.
|
|
|
|
* This is an optimisation used predominantly with RKScrollViews
|
|
|
|
* but it is applied recursively to all subviews that have
|
|
|
|
* removeClippedSubviews set to YES
|
|
|
|
*/
|
|
|
|
- (void)updateClippedSubviews;
|
|
|
|
|
2015-05-13 15:22:21 +00:00
|
|
|
/**
|
|
|
|
* Border radii.
|
|
|
|
*/
|
|
|
|
@property (nonatomic, assign) CGFloat borderRadius;
|
|
|
|
@property (nonatomic, assign) CGFloat borderTopLeftRadius;
|
|
|
|
@property (nonatomic, assign) CGFloat borderTopRightRadius;
|
|
|
|
@property (nonatomic, assign) CGFloat borderBottomLeftRadius;
|
|
|
|
@property (nonatomic, assign) CGFloat borderBottomRightRadius;
|
|
|
|
|
2015-03-26 08:43:17 +00:00
|
|
|
/**
|
2015-07-14 11:53:54 +00:00
|
|
|
* Border colors (actually retained).
|
2015-03-26 08:43:17 +00:00
|
|
|
*/
|
|
|
|
@property (nonatomic, assign) CGColorRef borderTopColor;
|
|
|
|
@property (nonatomic, assign) CGColorRef borderRightColor;
|
|
|
|
@property (nonatomic, assign) CGColorRef borderBottomColor;
|
|
|
|
@property (nonatomic, assign) CGColorRef borderLeftColor;
|
|
|
|
@property (nonatomic, assign) CGColorRef borderColor;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Border widths.
|
|
|
|
*/
|
|
|
|
@property (nonatomic, assign) CGFloat borderTopWidth;
|
|
|
|
@property (nonatomic, assign) CGFloat borderRightWidth;
|
|
|
|
@property (nonatomic, assign) CGFloat borderBottomWidth;
|
|
|
|
@property (nonatomic, assign) CGFloat borderLeftWidth;
|
|
|
|
@property (nonatomic, assign) CGFloat borderWidth;
|
|
|
|
|
2015-12-01 15:41:20 +00:00
|
|
|
/**
|
|
|
|
* Border styles.
|
|
|
|
*/
|
|
|
|
@property (nonatomic, assign) RCTBorderStyle borderStyle;
|
|
|
|
|
2016-02-17 00:50:35 +00:00
|
|
|
/**
|
|
|
|
* Insets used when hit testing inside this view.
|
|
|
|
*/
|
|
|
|
@property (nonatomic, assign) UIEdgeInsets hitTestEdgeInsets;
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
@end
|