This commit is contained in:
Nick Lockwood 2015-07-31 11:23:29 -07:00
parent b807c51bbe
commit 1fb26d4319
17 changed files with 59 additions and 91 deletions

View File

@ -62,7 +62,7 @@
[_reactSubviews removeObject:subview];
}
- (NSMutableArray *)reactSubviews
- (NSArray *)reactSubviews
{
return _reactSubviews;
}

View File

@ -72,7 +72,7 @@ extern NSString *const RCTContentDidAppearNotification;
/**
* The backing view controller of the root view.
*/
@property (nonatomic, weak) UIViewController *backingViewController;
@property (nonatomic, weak) UIViewController *reactViewController;
/**
* The React-managed contents view of the root view.

View File

@ -110,9 +110,9 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
_contentView.backgroundColor = backgroundColor;
}
- (UIViewController *)backingViewController
- (UIViewController *)reactViewController
{
return _backingViewController ?: [super backingViewController];
return _reactViewController ?: [super reactViewController];
}
- (BOOL)canBecomeFirstResponder

View File

@ -73,7 +73,7 @@ RCT_NOT_IMPLEMENTED(-initWithFrame:(CGRect)frame)
[super didMoveToSuperview];
if (self.superview) {
[self.backingViewController presentViewController:_modalViewController animated:self.animated completion:nil];
[self.reactViewController presentViewController:_modalViewController animated:self.animated completion:nil];
} else {
[_modalViewController dismissViewControllerAnimated:self.animated completion:nil];
}

View File

@ -322,7 +322,7 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
_navigationController.delegate = nil;
}
- (UIViewController *)backingViewController
- (UIViewController *)reactViewController
{
return _navigationController;
}
@ -444,7 +444,7 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
{
// we can't hook up the VC hierarchy in 'init' because the subviews aren't
// hooked up yet, so we do it on demand here
[self addControllerToClosestParent:_navigationController];
[self reactAddControllerToClosestParent:_navigationController];
NSUInteger viewControllerCount = _navigationController.viewControllers.count;
// The "react count" is the count of views that are visible on the navigation

View File

@ -63,8 +63,6 @@ RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
RCT_EXPORT_VIEW_PROPERTY(scrollIndicatorInsets, UIEdgeInsets)
RCT_REMAP_VIEW_PROPERTY(contentOffset, scrollView.contentOffset, CGPoint)
RCT_DEPRECATED_VIEW_PROPERTY(throttleScrollCallbackMS, scrollEventThrottle)
- (NSDictionary *)constantsToExport
{
return @{

View File

@ -67,37 +67,34 @@ typedef void (^RCTApplierBlock)(RCTSparseArray *viewRegistry);
/**
* Border. Defaults to { 0, 0, 0, 0 }.
*/
@property (nonatomic, assign) CGFloat borderWidth;
@property (nonatomic, assign) CGFloat borderTopWidth;
@property (nonatomic, assign) CGFloat borderLeftWidth;
@property (nonatomic, assign) CGFloat borderBottomWidth;
@property (nonatomic, assign) CGFloat borderRightWidth;
- (void)setBorderWidth:(CGFloat)value;
/**
* Margin. Defaults to { 0, 0, 0, 0 }.
*/
@property (nonatomic, assign) CGFloat margin;
@property (nonatomic, assign) CGFloat marginVertical;
@property (nonatomic, assign) CGFloat marginHorizontal;
@property (nonatomic, assign) CGFloat marginTop;
@property (nonatomic, assign) CGFloat marginLeft;
@property (nonatomic, assign) CGFloat marginBottom;
@property (nonatomic, assign) CGFloat marginRight;
- (void)setMargin:(CGFloat)margin;
- (void)setMarginVertical:(CGFloat)margin;
- (void)setMarginHorizontal:(CGFloat)margin;
/**
* Padding. Defaults to { 0, 0, 0, 0 }.
*/
@property (nonatomic, assign) CGFloat padding;
@property (nonatomic, assign) CGFloat paddingVertical;
@property (nonatomic, assign) CGFloat paddingHorizontal;
@property (nonatomic, assign) CGFloat paddingTop;
@property (nonatomic, assign) CGFloat paddingLeft;
@property (nonatomic, assign) CGFloat paddingBottom;
@property (nonatomic, assign) CGFloat paddingRight;
- (void)setPadding:(CGFloat)padding;
- (void)setPaddingVertical:(CGFloat)padding;
- (void)setPaddingHorizontal:(CGFloat)padding;
- (UIEdgeInsets)paddingAsInsets;
/**

View File

@ -47,7 +47,7 @@
RCT_NOT_IMPLEMENTED(-initWithFrame:(CGRect)frame)
RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
- (UIViewController *)backingViewController
- (UIViewController *)reactViewController
{
return _tabController;
}
@ -92,13 +92,13 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:(NSCoder *)aDecoder)
{
// we can't hook up the VC hierarchy in 'init' because the subviews aren't
// hooked up yet, so we do it on demand here whenever a transaction has finished
[self addControllerToClosestParent:_tabController];
[self reactAddControllerToClosestParent:_tabController];
if (_tabsChanged) {
NSMutableArray *viewControllers = [NSMutableArray array];
for (RCTTabBarItem *tab in [self reactSubviews]) {
UIViewController *controller = tab.backingViewController;
UIViewController *controller = tab.reactViewController;
if (!controller) {
controller = [[RCTWrapperViewController alloc] initWithContentView:tab
eventDispatcher:_eventDispatcher];

View File

@ -82,9 +82,9 @@
_barItem.badgeValue = oldItem.badgeValue;
}
- (UIViewController *)backingViewController
- (UIViewController *)reactViewController
{
return self.superview.backingViewController;
return self.superview.reactViewController;
}
@end

View File

@ -229,7 +229,7 @@ RCT_NOT_IMPLEMENTED(-initWithCoder:unused)
+ (UIEdgeInsets)contentInsetsForView:(UIView *)view
{
while (view) {
UIViewController *controller = view.backingViewController;
UIViewController *controller = view.reactViewController;
if (controller) {
return (UIEdgeInsets){
controller.topLayoutGuide.length, 0,

View File

@ -21,6 +21,11 @@
typedef void (^RCTViewManagerUIBlock)(RCTUIManager *uiManager, RCTSparseArray *viewRegistry);
/**
* Underlying implementation of RCT_EXPORT_XXX macros. Ignore this.
*/
RCT_EXTERN void RCTSetViewProperty(NSString *, NSString *, SEL, id, id, id);
@interface RCTViewManager : NSObject <RCTBridgeModule>
/**
@ -108,20 +113,14 @@ typedef void (^RCTViewManagerUIBlock)(RCTUIManager *uiManager, RCTSparseArray *v
* This macro maps a named property on the module to an arbitrary key path
* within the view or shadowView.
*/
#define RCT_REMAP_VIEW_PROPERTY(name, keyPath, type) \
RCT_CUSTOM_VIEW_PROPERTY(name, type, UIView) { \
if ((json && !RCTSetProperty(view, @#keyPath, @selector(type:), json)) || \
(!json && !RCTCopyProperty(view, defaultView, @#keyPath))) { \
RCTLogError(@"%@ does not have setter for `%s` property", [view class], #name); \
} \
#define RCT_REMAP_VIEW_PROPERTY(name, keyPath, type) \
RCT_CUSTOM_VIEW_PROPERTY(name, type, UIView) { \
RCTSetViewProperty(@#name, @#keyPath, @selector(type:), view, defaultView, json); \
}
#define RCT_REMAP_SHADOW_PROPERTY(name, keyPath, type) \
RCT_CUSTOM_SHADOW_PROPERTY(name, type, RCTShadowView) { \
if ((json && !RCTSetProperty(view, @#keyPath, @selector(type:), json)) || \
(!json && !RCTCopyProperty(view, defaultView, @#keyPath))) { \
RCTLogError(@"%@ does not have setter for `%s` property", [view class], #name); \
} \
#define RCT_REMAP_SHADOW_PROPERTY(name, keyPath, type) \
RCT_CUSTOM_SHADOW_PROPERTY(name, type, RCTShadowView) { \
RCTSetViewProperty(@#name, @#keyPath, @selector(type:), view, defaultView, json); \
}
/**
@ -137,29 +136,4 @@ RCT_CUSTOM_SHADOW_PROPERTY(name, type, RCTShadowView) { \
+ (NSString *)getPropConfigShadow_##name { return @#type; } \
- (void)set_##name:(id)json forShadowView:(viewClass *)view withDefaultView:(viewClass *)defaultView
/**
* These are useful in cases where the module's superclass handles a
* property, but you wish to "unhandle" it, so it will be ignored.
*/
#define RCT_IGNORE_VIEW_PROPERTY(name) \
- (void)set_##name:(id)value forView:(id)view withDefaultView:(id)defaultView {}
#define RCT_IGNORE_SHADOW_PROPERTY(name) \
- (void)set_##name:(id)value forShadowView:(id)view withDefaultView:(id)defaultView {}
/**
* Used for when view property names change. Will log an error when used.
*/
#define RCT_DEPRECATED_VIEW_PROPERTY(oldName, newName) \
- (void)set_##oldName:(id)json forView:(id)view withDefaultView:(id)defaultView { \
RCTLogError(@"Property '%s' has been replaced by '%s'.", #oldName, #newName); \
[self set_##newName:json forView:view withDefaultView:defaultView]; \
}
#define RCT_DEPRECATED_SHADOW_PROPERTY(oldName, newName) \
- (void)set_##oldName:(id)json forShadowView:(id)view withDefaultView:(id)defaultView { \
RCTLogError(@"Property '%s' has been replaced by '%s'.", #oldName, #newName); \
[self set_##newName:json forView:view withDefaultView:defaultView]; \
}
@end

View File

@ -43,6 +43,15 @@ RCT_MULTI_ENUM_CONVERTER(UIAccessibilityTraits, (@{
@end
void RCTSetViewProperty(NSString *name, NSString *keyPath, SEL type,
id view, id defaultView, id json)
{
if ((json && !RCTSetProperty(view, keyPath, type, json)) ||
(!json && !RCTCopyProperty(view, defaultView, keyPath))) {
RCTLogError(@"%@ does not have setter for `%@` property", [view class], name);
}
}
@implementation RCTViewManager
@synthesize bridge = _bridge;
@ -144,19 +153,9 @@ RCT_CUSTOM_VIEW_PROPERTY(removeClippedSubviews, BOOL, RCTView)
}
RCT_CUSTOM_VIEW_PROPERTY(borderRadius, CGFloat, RCTView) {
if ([view respondsToSelector:@selector(setBorderRadius:)]) {
if (json) {
view.borderRadius = [RCTConvert CGFloat:json];
} else if ([view respondsToSelector:@selector(borderRadius)]) {
view.borderRadius = [defaultView borderRadius];
} else {
view.borderRadius = defaultView.layer.cornerRadius;
}
view.borderRadius = json ? [RCTConvert CGFloat:json] : defaultView.borderRadius;
} else {
if (json) {
view.layer.cornerRadius = [RCTConvert CGFloat:json];
} else {
view.layer.cornerRadius = defaultView.layer.cornerRadius;
}
view.layer.cornerRadius = json ? [RCTConvert CGFloat:json] : defaultView.layer.cornerRadius;
}
}
RCT_CUSTOM_VIEW_PROPERTY(borderColor, CGColor, RCTView)
@ -245,9 +244,7 @@ RCT_EXPORT_SHADOW_PROPERTY(borderTopWidth, CGFloat)
RCT_EXPORT_SHADOW_PROPERTY(borderRightWidth, CGFloat)
RCT_EXPORT_SHADOW_PROPERTY(borderBottomWidth, CGFloat)
RCT_EXPORT_SHADOW_PROPERTY(borderLeftWidth, CGFloat)
RCT_CUSTOM_SHADOW_PROPERTY(borderWidth, CGFloat, __unused RCTShadowView) {
[view setBorderWidth:[RCTConvert CGFloat:json]];
}
RCT_EXPORT_SHADOW_PROPERTY(borderWidth, CGFloat)
RCT_EXPORT_SHADOW_PROPERTY(marginTop, CGFloat)
RCT_EXPORT_SHADOW_PROPERTY(marginRight, CGFloat)

View File

@ -18,7 +18,7 @@
- (void)insertReactSubview:(id<RCTViewNodeProtocol>)subview atIndex:(NSInteger)atIndex;
- (void)removeReactSubview:(id<RCTViewNodeProtocol>)subview;
- (NSMutableArray *)reactSubviews;
- (NSArray *)reactSubviews;
- (id<RCTViewNodeProtocol>)reactSuperview;
- (NSNumber *)reactTagAtPoint:(CGPoint)point;
@ -36,6 +36,7 @@
// TODO: this is kinda dumb - let's come up with a
// better way of identifying root React views please!
static inline BOOL RCTIsReactRootView(NSNumber *reactTag) {
static inline BOOL RCTIsReactRootView(NSNumber *reactTag)
{
return reactTag.integerValue % 10 == 1;
}

View File

@ -9,6 +9,12 @@
#import "RCTView.h"
/**
* Special scheme used to pass messages to the injectedJavaScript
* code without triggering a page load. Usage:
*
* window.location.href = RCTJSNavigationScheme + '://hello'
*/
extern NSString *const RCTJSNavigationScheme;
@class RCTEventDispatcher;

View File

@ -18,11 +18,6 @@
#import "RCTView.h"
#import "UIView+React.h"
// Special scheme that allow JS to notify the WebView to emit
// navigation event.
//
// JavaScript Example:
// window.location.href = 'react-js-navigation://hello'
NSString *const RCTJSNavigationScheme = @"react-js-navigation";
@interface RCTWebView () <UIWebViewDelegate, RCTAutoInsetsProtocol>

View File

@ -29,7 +29,7 @@
/**
* This method finds and returns the containing view controller for the view.
*/
- (UIViewController *)backingViewController;
- (UIViewController *)reactViewController;
/**
* This method attaches the specified controller as a child of the
@ -37,7 +37,7 @@
* controller is found (which may happen if the view is not currently
* attached to the view hierarchy).
*/
- (void)addControllerToClosestParent:(UIViewController *)controller;
- (void)reactAddControllerToClosestParent:(UIViewController *)controller;
/**
* Responder overrides - to be deprecated.

View File

@ -87,7 +87,7 @@
self.backgroundColor = inheritedBackgroundColor;
}
- (UIViewController *)backingViewController
- (UIViewController *)reactViewController
{
id responder = [self nextResponder];
while (responder) {
@ -99,14 +99,14 @@
return nil;
}
- (void)addControllerToClosestParent:(UIViewController *)controller
- (void)reactAddControllerToClosestParent:(UIViewController *)controller
{
if (!controller.parentViewController) {
UIView *parentView = (UIView *)self.reactSuperview;
while (parentView) {
if (parentView.backingViewController) {
[parentView.backingViewController addChildViewController:controller];
[controller didMoveToParentViewController:parentView.backingViewController];
if (parentView.reactViewController) {
[parentView.reactViewController addChildViewController:controller];
[controller didMoveToParentViewController:parentView.reactViewController];
break;
}
parentView = (UIView *)parentView.reactSuperview;