Skip to content

Commit

Permalink
Second part of updates from Wed 24 Jun
Browse files Browse the repository at this point in the history
  • Loading branch information
frantic committed Jun 24, 2015
2 parents 2e4cbc4 + eb9c723 commit 0898bb4
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

jest
.dontMock('EmitterSubscription')
.dontMock('EventSubscription')
.dontMock('EventEmitter')
.dontMock('EventSubscriptionVendor')
.dontMock('NavigationContext')
Expand Down
1 change: 1 addition & 0 deletions Libraries/ReactIOS/renderApplication.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function renderApplication<D, P, S>(
<AppContainer rootTag={rootTag}>
<RootComponent
{...initialProps}
rootTag={rootTag}
/>
</AppContainer>,
rootTag
Expand Down
26 changes: 14 additions & 12 deletions React/Base/RCTConvert.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ + (NSDate *)NSDate:(id)json
}
id value = mapping[json];
if (!value && [json description].length > 0) {
RCTLogError(@"Invalid %s '%@'. should be one of: %@", typeName, json, [mapping allKeys]);
RCTLogError(@"Invalid %s '%@'. should be one of: %@", typeName, json, [[mapping allKeys] sortedArrayUsingSelector: @selector(caseInsensitiveCompare:)]);
}
return value ?: defaultValue;
}
Expand Down Expand Up @@ -550,27 +550,29 @@ + (UIColor *)UIColor:(id)json
}

// Parse color
uint32_t red = 0, green = 0, blue = 0;
CGFloat alpha = 1.0;
double red = 0, green = 0, blue = 0;
double alpha = 1.0;
if ([colorString hasPrefix:@"#"]) {
uint32_t redInt = 0, greenInt = 0, blueInt = 0;
if (colorString.length == 4) { // 3 digit hex
sscanf([colorString UTF8String], "#%01x%01x%01x", &red, &green, &blue);
sscanf([colorString UTF8String], "#%01x%01x%01x", &redInt, &greenInt, &blueInt);
// expand to 6 digit hex
red = red | (red << 4);
green = green | (green << 4);
blue = blue | (blue << 4);
red = redInt | (redInt << 4);
green = greenInt | (greenInt << 4);
blue = blueInt | (blueInt << 4);
} else if (colorString.length == 7) { // 6 digit hex
sscanf(colorString.UTF8String, "#%02x%02x%02x", &red, &green, &blue);
sscanf(colorString.UTF8String, "#%02x%02x%02x", &redInt, &greenInt, &blueInt);
red = redInt;
green = greenInt;
blue = blueInt;
} else {
RCTLogError(@"Invalid hex color %@. Hex colors should be 3 or 6 digits long.", colorString);
alpha = -1;
}
} else if ([colorString hasPrefix:@"rgba("]) {
double tmpAlpha;
sscanf(colorString.UTF8String, "rgba(%u,%u,%u,%lf)", &red, &green, &blue, &tmpAlpha);
alpha = tmpAlpha;
sscanf(colorString.UTF8String, "rgba(%lf,%lf,%lf,%lf)", &red, &green, &blue, &alpha);
} else if ([colorString hasPrefix:@"rgb("]) {
sscanf(colorString.UTF8String, "rgb(%u,%u,%u)", &red, &green, &blue);
sscanf(colorString.UTF8String, "rgb(%lf,%lf,%lf)", &red, &green, &blue);
} else {
RCTLogError(@"Unrecognized color format '%@', must be one of #hex|rgba|rgb or a valid CSS color name.", colorString);
alpha = -1;
Expand Down
5 changes: 5 additions & 0 deletions React/Modules/RCTUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
*/
- (void)registerRootView:(UIView *)rootView;

/**
* Gets the view associated with a reactTag.
*/
- (UIView *)viewForReactTag:(NSNumber *)reactTag;

/**
* Update the frame of a root view. This might be in response to a screen rotation
* or some other layout event outside of the React-managed view hierarchy.
Expand Down
6 changes: 6 additions & 0 deletions React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ - (void)registerRootView:(UIView *)rootView
});
}

- (UIView *)viewForReactTag:(NSNumber *)reactTag
{
RCTAssertMainThread();
return _viewRegistry[reactTag];
}

- (void)setFrame:(CGRect)frame forRootView:(UIView *)rootView
{
RCTAssertMainThread();
Expand Down
8 changes: 5 additions & 3 deletions React/Views/UIView+React.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#import "RCTAssert.h"
#import "RCTLog.h"
#import "RCTWrapperViewController.h"

@implementation UIView (React)

Expand Down Expand Up @@ -91,8 +90,11 @@ - (void)reactSetInheritedBackgroundColor:(UIColor *)inheritedBackgroundColor
- (UIViewController *)backingViewController
{
id responder = [self nextResponder];
if ([responder isKindOfClass:[RCTWrapperViewController class]]) {
return responder;
while (responder) {
if ([responder isKindOfClass:[UIViewController class]]) {
return responder;
}
responder = [responder nextResponder];
}
return nil;
}
Expand Down
Loading

0 comments on commit 0898bb4

Please sign in to comment.