Merge pull request #139 from frantic/oss-up-2015-03-11

Updates from Wed Mar 11
This commit is contained in:
Alexander Kotliarskyi 2015-03-11 13:10:45 -07:00
commit 516fe6ff71
36 changed files with 418 additions and 185 deletions

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule ActivityIndicatorExample
*/
'use strict';

View File

@ -1,9 +1,6 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule AdSupportIOSExample
*/
/* eslint no-console: 0 */
'use strict';
var AdSupportIOS = require('AdSupportIOS');

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule CameraRollExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule DatePickerExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule ExpandingTextExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule GeolocationExample
*/
/* eslint no-console: 0 */
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule ImageExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule LayoutExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @provides ListViewSimpleExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule MapViewExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule NavigatorIOSExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule PickerExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule PointerEventsExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule ScrollViewExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule SliderExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule StatusBarIOSExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule SwitchExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule TabBarExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule TextExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule TextInputExample
*/
'use strict';

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule TouchableExample
*/
'use strict';

View File

@ -12,12 +12,12 @@
134180011AA9153C003F314A /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13417FEF1AA914B8003F314A /* libRCTText.a */; };
134180021AA9153C003F314A /* libReactKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 13417FFF1AA91531003F314A /* libReactKit.a */; };
1341802C1AA9178B003F314A /* libRCTNetwork.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1341802B1AA91779003F314A /* libRCTNetwork.a */; };
134454601AAFCABD003F0779 /* libRCTAdSupport.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1344545A1AAFCAAE003F0779 /* libRCTAdSupport.a */; };
134A8A2A1AACED7A00945AAE /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 134A8A251AACED6A00945AAE /* libRCTGeolocation.a */; };
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB11A68108700A75B9A /* LaunchScreen.xib */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
832C81C71AAF73C5007FA2F7 /* libRCTAdSupport.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832C81A61AAF6EFF007FA2F7 /* libRCTAdSupport.a */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -56,6 +56,13 @@
remoteGlobalIDString = 58B511DB1A9E6C8500147676;
remoteInfo = RCTNetwork;
};
134454591AAFCAAE003F0779 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 134454551AAFCAAE003F0779 /* RCTAdSupport.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 832C81801AAF6DEF007FA2F7;
remoteInfo = RCTAdSupport;
};
134A8A241AACED6A00945AAE /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 134A8A201AACED6A00945AAE /* RCTGeolocation.xcodeproj */;
@ -63,13 +70,6 @@
remoteGlobalIDString = 134814201AA4EA6300B7C361;
remoteInfo = RCTGeolocation;
};
832C81A51AAF6EFF007FA2F7 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 832C81A11AAF6EFE007FA2F7 /* RCTAdSupport.xcodeproj */;
proxyType = 2;
remoteGlobalIDString = 832C81801AAF6DEF007FA2F7;
remoteInfo = RCTAdSupport;
};
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
@ -80,6 +80,7 @@
13417FEA1AA914B8003F314A /* RCTText.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTText.xcodeproj; path = ../../Libraries/Text/RCTText.xcodeproj; sourceTree = "<group>"; };
13417FFA1AA91531003F314A /* ReactKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ReactKit.xcodeproj; path = ../../ReactKit/ReactKit.xcodeproj; sourceTree = "<group>"; };
134180261AA91779003F314A /* RCTNetwork.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTNetwork.xcodeproj; path = ../../Libraries/Network/RCTNetwork.xcodeproj; sourceTree = "<group>"; };
134454551AAFCAAE003F0779 /* RCTAdSupport.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAdSupport.xcodeproj; path = ../../Libraries/AdSupport/RCTAdSupport.xcodeproj; sourceTree = "<group>"; };
134A8A201AACED6A00945AAE /* RCTGeolocation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTGeolocation.xcodeproj; path = ../../Libraries/Geolocation/RCTGeolocation.xcodeproj; sourceTree = "<group>"; };
13B07F961A680F5B00A75B9A /* UIExplorer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UIExplorer.app; sourceTree = BUILT_PRODUCTS_DIR; };
13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
@ -88,7 +89,6 @@
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
832C81A11AAF6EFE007FA2F7 /* RCTAdSupport.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAdSupport.xcodeproj; path = ../../Libraries/AdSupport/RCTAdSupport.xcodeproj; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -103,7 +103,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
832C81C71AAF73C5007FA2F7 /* libRCTAdSupport.a in Frameworks */,
134454601AAFCABD003F0779 /* libRCTAdSupport.a in Frameworks */,
134A8A2A1AACED7A00945AAE /* libRCTGeolocation.a in Frameworks */,
1341802C1AA9178B003F314A /* libRCTNetwork.a in Frameworks */,
134180011AA9153C003F314A /* libRCTText.a in Frameworks */,
@ -136,7 +136,7 @@
isa = PBXGroup;
children = (
13417FFA1AA91531003F314A /* ReactKit.xcodeproj */,
832C81A11AAF6EFE007FA2F7 /* RCTAdSupport.xcodeproj */,
134454551AAFCAAE003F0779 /* RCTAdSupport.xcodeproj */,
134A8A201AACED6A00945AAE /* RCTGeolocation.xcodeproj */,
13417FE31AA91428003F314A /* RCTImage.xcodeproj */,
134180261AA91779003F314A /* RCTNetwork.xcodeproj */,
@ -177,6 +177,14 @@
name = Products;
sourceTree = "<group>";
};
134454561AAFCAAE003F0779 /* Products */ = {
isa = PBXGroup;
children = (
1344545A1AAFCAAE003F0779 /* libRCTAdSupport.a */,
);
name = Products;
sourceTree = "<group>";
};
134A8A211AACED6A00945AAE /* Products */ = {
isa = PBXGroup;
children = (
@ -198,14 +206,6 @@
name = UIExplorer;
sourceTree = "<group>";
};
832C81A21AAF6EFE007FA2F7 /* Products */ = {
isa = PBXGroup;
children = (
832C81A61AAF6EFF007FA2F7 /* libRCTAdSupport.a */,
);
name = Products;
sourceTree = "<group>";
};
83CBB9F61A601CBA00E9B192 = {
isa = PBXGroup;
children = (
@ -291,8 +291,8 @@
projectDirPath = "";
projectReferences = (
{
ProductGroup = 832C81A21AAF6EFE007FA2F7 /* Products */;
ProjectRef = 832C81A11AAF6EFE007FA2F7 /* RCTAdSupport.xcodeproj */;
ProductGroup = 134454561AAFCAAE003F0779 /* Products */;
ProjectRef = 134454551AAFCAAE003F0779 /* RCTAdSupport.xcodeproj */;
},
{
ProductGroup = 134A8A211AACED6A00945AAE /* Products */;
@ -352,6 +352,13 @@
remoteRef = 1341802A1AA91779003F314A /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
1344545A1AAFCAAE003F0779 /* libRCTAdSupport.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTAdSupport.a;
remoteRef = 134454591AAFCAAE003F0779 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
134A8A251AACED6A00945AAE /* libRCTGeolocation.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
@ -359,13 +366,6 @@
remoteRef = 134A8A241AACED6A00945AAE /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
832C81A61AAF6EFF007FA2F7 /* libRCTAdSupport.a */ = {
isa = PBXReferenceProxy;
fileType = archive.ar;
path = libRCTAdSupport.a;
remoteRef = 832C81A51AAF6EFF007FA2F7 /* PBXContainerItemProxy */;
sourceTree = BUILT_PRODUCTS_DIR;
};
/* End PBXReferenceProxy section */
/* Begin PBXResourcesBuildPhase section */

View File

@ -1,7 +1,5 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
*
* @providesModule ViewExample
*/
'use strict';

View File

@ -1,5 +1,7 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#import <AdSupport/ASIdentifierManager.h>
#import "RCTBridgeModule.h"
@interface RCTAdSupport : NSObject <RCTBridgeModule>

View File

@ -2,8 +2,6 @@
#import "RCTAdSupport.h"
#import <AdSupport/ASIdentifierManager.h>
@implementation RCTAdSupport
- (void)getAdvertisingId:(RCTResponseSenderBlock)callback withErrorCallback:(RCTResponseSenderBlock)errorCallback

View File

@ -19,12 +19,13 @@
+ (float)float:(id)json;
+ (int)int:(id)json;
+ (NSInteger)NSInteger:(id)json;
+ (NSUInteger)NSUInteger:(id)json;
+ (NSArray *)NSArray:(id)json;
+ (NSDictionary *)NSDictionary:(id)json;
+ (NSString *)NSString:(id)json;
+ (NSNumber *)NSNumber:(id)json;
+ (NSInteger)NSInteger:(id)json;
+ (NSUInteger)NSUInteger:(id)json;
+ (NSURL *)NSURL:(id)json;
+ (NSURLRequest *)NSURLRequest:(id)json;
@ -57,6 +58,11 @@
+ (UIFont *)UIFont:(UIFont *)font withFamily:(id)json;
+ (UIFont *)UIFont:(UIFont *)font withFamily:(id)json size:(id)json weight:(id)json;
+ (NSArray *)NSStringArray:(id)json;
+ (NSArray *)NSNumberArray:(id)json;
+ (NSArray *)UIColorArray:(id)json;
+ (NSArray *)CGColorArray:(id)json;
+ (BOOL)css_overflow:(id)json;
+ (css_flex_direction_t)css_flex_direction_t:(id)json;
+ (css_justify_t)css_justify_t:(id)json;

View File

@ -92,6 +92,19 @@ RCT_CONVERTER_CUSTOM(type, name, [json getter])
} \
}
#define RCT_ARRAY_CONVERTER(type) \
+ (NSArray *)type##Array:(id)json \
{ \
NSMutableArray *values = [[NSMutableArray alloc] init]; \
for (id jsonValue in [self NSArray:json]) { \
id value = [self type:jsonValue]; \
if (!value) { \
[values addObject:value]; \
} \
} \
return values; \
}
@implementation RCTConvert
RCT_CONVERTER(BOOL, BOOL, boolValue)
@ -99,12 +112,13 @@ RCT_CONVERTER(double, double, doubleValue)
RCT_CONVERTER(float, float, floatValue)
RCT_CONVERTER(int, int, intValue)
RCT_CONVERTER(NSInteger, NSInteger, integerValue)
RCT_CONVERTER_CUSTOM(NSUInteger, NSUInteger, [json unsignedIntegerValue])
RCT_CONVERTER_CUSTOM(NSArray *, NSArray, [NSArray arrayWithArray:json])
RCT_CONVERTER_CUSTOM(NSDictionary *, NSDictionary, [NSDictionary dictionaryWithDictionary:json])
RCT_CONVERTER(NSString *, NSString, description)
RCT_CONVERTER_CUSTOM(NSNumber *, NSNumber, @([json doubleValue]))
RCT_CONVERTER(NSInteger, NSInteger, integerValue)
RCT_CONVERTER_CUSTOM(NSUInteger, NSUInteger, [json unsignedIntegerValue])
+ (NSURL *)NSURL:(id)json
{
@ -137,17 +151,12 @@ RCT_CONVERTER_CUSTOM(NSTimeInterval, NSTimeInterval, [json doubleValue] / 1000.0
// JS standard for time zones is minutes.
RCT_CONVERTER_CUSTOM(NSTimeZone *, NSTimeZone, [NSTimeZone timeZoneForSecondsFromGMT:[json doubleValue] * 60.0])
/**
* NOTE: We don't deliberately don't support NSTextAlignmentJustified in the
* X-platform RCTText implementation because it isn't available on Android.
* We may wish to support this for iOS-specific controls such as UILabel.
*/
RCT_ENUM_CONVERTER(NSTextAlignment, (@{
@"auto": @(NSTextAlignmentNatural),
@"left": @(NSTextAlignmentLeft),
@"center": @(NSTextAlignmentCenter),
@"right": @(NSTextAlignmentRight),
/* @"justify": @(NSTextAlignmentJustify), */
@"justify": @(NSTextAlignmentJustified),
}), NSTextAlignmentNatural, integerValue)
RCT_ENUM_CONVERTER(NSWritingDirection, (@{
@ -491,7 +500,7 @@ RCT_STRUCT_CONVERTER(CGAffineTransform, (@[@"a", @"b", @"c", @"d", @"tx", @"ty"]
}
// Get font family
NSString *familyName = [RCTConvert NSString:family];
NSString *familyName = [self NSString:family];
if (familyName) {
if ([UIFont fontNamesForFamilyName:familyName].count == 0) {
font = [UIFont fontWithName:familyName size:fontDescriptor.pointSize];
@ -511,7 +520,7 @@ RCT_STRUCT_CONVERTER(CGAffineTransform, (@[@"a", @"b", @"c", @"d", @"tx", @"ty"]
}
// Get font weight
NSString *fontWeight = [RCTConvert NSString:weight];
NSString *fontWeight = [self NSString:weight];
if (fontWeight) {
static NSSet *values;
@ -539,6 +548,20 @@ RCT_STRUCT_CONVERTER(CGAffineTransform, (@[@"a", @"b", @"c", @"d", @"tx", @"ty"]
return [UIFont fontWithDescriptor:fontDescriptor size:fontDescriptor.pointSize];
}
RCT_ARRAY_CONVERTER(NSString)
RCT_ARRAY_CONVERTER(NSNumber)
RCT_ARRAY_CONVERTER(UIColor)
// Can't use RCT_ARRAY_CONVERTER due to bridged cast
+ (NSArray *)CGColorArray:(id)json
{
NSMutableArray *colors = [[NSMutableArray alloc] init];
for (id value in [self NSArray:json]) {
[colors addObject:(__bridge id)[self CGColor:value]];
}
return colors;
}
typedef BOOL css_overflow;
RCT_ENUM_CONVERTER(css_overflow, (@{
@ -596,15 +619,31 @@ RCT_ENUM_CONVERTER(RCTAnimationType, (@{
static NSString *RCTGuessTypeEncoding(id target, NSString *key, id value, NSString *encoding)
{
/**
* NOTE: the property names below may seem weird, but it's
* because they are tested as case-sensitive suffixes, so
* "ffset" will match any of the following
*
* - offset
* - contentOffset
*/
// TODO (#5906496): handle more cases
if ([key rangeOfString:@"color" options:NSCaseInsensitiveSearch].location != NSNotFound) {
if ([key hasSuffix:@"olor"]) {
if ([target isKindOfClass:[CALayer class]]) {
return @(@encode(CGColorRef));
} else {
return @"@\"UIColor\"";
}
} else if ([key hasSuffix:@"Inset"] || [key hasSuffix:@"Insets"]) {
return @(@encode(UIEdgeInsets));
} else if ([key hasSuffix:@"rame"] || [key hasSuffix:@"ounds"]) {
return @(@encode(CGRect));
} else if ([key hasSuffix:@"ffset"] || [key hasSuffix:@"osition"]) {
return @(@encode(CGPoint));
} else if ([key hasSuffix:@"ize"]) {
return @(@encode(CGSize));
}
return nil;
}
@ -690,7 +729,8 @@ static id RCTConvertValueWithEncoding(id value, NSString *encoding)
return converter ? converter(value) : value;
}
static NSString *RCTPropertyEncoding(id target, NSString *key, id value) {
static NSString *RCTPropertyEncoding(id target, NSString *key, id value)
{
// Check target class for property definition
NSString *encoding = nil;
objc_property_t property = class_getProperty([target class], [key UTF8String]);
@ -728,15 +768,16 @@ static NSString *RCTPropertyEncoding(id target, NSString *key, id value) {
}
return encoding;
// id encoding means unknown, as opposed to nil which means no setter exists.
return encoding ?: @(@encode(id));
}
static id RCTConvertValueWithExplicitEncoding(id target, NSString *key, id json, NSString *encoding) {
if (!encoding) return nil;
static id RCTConvertValueWithExplicitEncoding(id target, NSString *key, id json, NSString *encoding)
{
// Special case for numeric encodings, which may be enums
if ([json isKindOfClass:[NSString class]] &&
[@"iIsSlLqQ" rangeOfString:[encoding substringToIndex:1]].length) {
([encoding isEqualToString:@(@encode(id))] ||
[@"iIsSlLqQ" rangeOfString:[encoding substringToIndex:1]].length)) {
/**
* NOTE: the property names below may seem weird, but it's
@ -780,7 +821,8 @@ static id RCTConvertValueWithExplicitEncoding(id target, NSString *key, id json,
return RCTConvertValueWithEncoding(json, encoding);
}
id RCTConvertValue(id target, NSString *key, id json) {
id RCTConvertValue(id target, NSString *key, id json)
{
NSString *encoding = RCTPropertyEncoding(target, key, json);
return RCTConvertValueWithExplicitEncoding(target, key, json, encoding);
}
@ -797,54 +839,15 @@ BOOL RCTSetProperty(id target, NSString *keypath, id value)
}
}
// Get encoding
NSString *encoding = RCTPropertyEncoding(target, key, value);
if (!encoding) return NO;
value = RCTConvertValueWithExplicitEncoding(target, keypath, value, encoding);
// Special case for numeric encodings, which may be enums
if ([value isKindOfClass:[NSString class]] &&
[@"iIsSlLqQ" rangeOfString:[encoding substringToIndex:1]].location != NSNotFound) {
/**
* NOTE: the property names below may seem weird, but it's
* because they are tested as case-sensitive suffixes, so
* "apitalizationType" will match any of the following
*
* - capitalizationType
* - autocapitalizationType
* - autoCapitalizationType
* - titleCapitalizationType
* - etc.
*/
static NSDictionary *converters = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
converters =
@{
@"apitalizationType": ^(id val) {
return [RCTConvert UITextAutocapitalizationType:val];
},
@"eyboardType": ^(id val) {
return [RCTConvert UIKeyboardType:val];
},
@"extAlignment": ^(id val) {
return [RCTConvert NSTextAlignment:val];
},
@"ointerEvents": ^(id val) {
return [RCTConvert RCTPointerEvents:val];
},
};
});
for (NSString *subkey in converters) {
if ([key hasSuffix:subkey]) {
NSInteger (^converter)(NSString *) = converters[subkey];
value = @(converter(value));
break;
}
}
if (!encoding) {
return NO;
}
// Convert value
value = RCTConvertValueWithExplicitEncoding(target, keypath, value, encoding);
// Another nasty special case
if ([target isKindOfClass:[UITextField class]]) {
static NSDictionary *specialCases = nil;

View File

@ -11,18 +11,18 @@ static BOOL RCTViewControllerBasedStatusBarAppearance()
static BOOL value;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
value = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"] boolValue];
value = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIViewControllerBasedStatusBarAppearance"] ?: @YES boolValue];
});
return value;
}
- (void)setStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated
{
RCT_EXPORT();
dispatch_async(dispatch_get_main_queue(), ^{
if (RCTViewControllerBasedStatusBarAppearance()) {
RCTLogError(@"RCTStatusBarManager module requires that the \
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO");
@ -36,9 +36,9 @@ static BOOL RCTViewControllerBasedStatusBarAppearance()
- (void)setHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation
{
RCT_EXPORT();
dispatch_async(dispatch_get_main_queue(), ^{
if (RCTViewControllerBasedStatusBarAppearance()) {
RCTLogError(@"RCTStatusBarManager module requires that the \
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO");

View File

@ -1058,25 +1058,6 @@ static void RCTSetShadowViewProps(NSDictionary *props, RCTShadowView *shadowView
}];
}
- (void)getScrollViewContentSize:(NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback failCallback:(RCTResponseSenderBlock)failCallback
{
RCT_EXPORT();
[self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
UIView *view = viewRegistry[reactTag];
if (!view) {
NSString *error = [[NSString alloc] initWithFormat:@"cannot find view with tag %@", reactTag];
RCTLogError(@"%@", error);
failCallback(@[@{@"error": error}]);
return;
}
CGSize size = ((id<RCTScrollableProtocol>)view).contentSize;
NSDictionary *dict = @{@"width" : @(size.width), @"height" : @(size.height)};
callback(@[dict]);
}];
}
/**
* JS sets what *it* considers to be the responder. Later, scroll views can use
* this in order to determine if scrolling is appropriate.

View File

@ -259,14 +259,14 @@ CGFloat const ZINDEX_STICKY_HEADER = 50;
- (instancetype)initWithEventDispatcher:(RCTEventDispatcher *)eventDispatcher
{
if ((self = [super initWithFrame:CGRectZero])) {
_eventDispatcher = eventDispatcher;
_scrollView = [[RCTCustomScrollView alloc] initWithFrame:CGRectZero];
_scrollView.delegate = self;
_scrollView.delaysContentTouches = NO;
_automaticallyAdjustContentInsets = YES;
_contentInset = UIEdgeInsetsZero;
_throttleScrollCallbackMS = 0;
_lastScrollDispatchTime = CACurrentMediaTime();
_cachedChildFrames = [[NSMutableArray alloc] init];
@ -337,6 +337,8 @@ CGFloat const ZINDEX_STICKY_HEADER = 50;
[RCTView autoAdjustInsetsForView:self
withScrollView:_scrollView
updateOffset:YES];
[self updateClippedSubviews];
}
- (void)setContentInset:(UIEdgeInsets)contentInset
@ -387,9 +389,11 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidZoom, RCTScrollEventTypeMove)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self updateClippedSubviews];
NSTimeInterval now = CACurrentMediaTime();
NSTimeInterval throttleScrollCallbackSeconds = _throttleScrollCallbackMS / 1000.0;
/**
* TODO: this logic looks wrong, and it may be because it is. Currently, if _throttleScrollCallbackMS
* is set to zero (the default), the "didScroll" event is only sent once per scroll, instead of repeatedly
@ -398,11 +402,11 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidZoom, RCTScrollEventTypeMove)
*/
if (_allowNextScrollNoMatterWhat ||
(_throttleScrollCallbackMS != 0 && throttleScrollCallbackSeconds < (now - _lastScrollDispatchTime))) {
// Calculate changed frames
NSMutableArray *updatedChildFrames = [[NSMutableArray alloc] init];
[[_contentView reactSubviews] enumerateObjectsUsingBlock:^(UIView *subview, NSUInteger idx, BOOL *stop) {
// Check if new or changed
CGRect newFrame = subview.frame;
BOOL frameChanged = NO;
@ -413,7 +417,7 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidZoom, RCTScrollEventTypeMove)
frameChanged = YES;
_cachedChildFrames[idx] = [NSValue valueWithCGRect:newFrame];
}
// Create JS frame object
if (frameChanged) {
[updatedChildFrames addObject: @{
@ -424,9 +428,9 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidZoom, RCTScrollEventTypeMove)
@"height": @(newFrame.size.height),
}];
}
}];
// If there are new frames, add them to event data
NSDictionary *userData = nil;
if (updatedChildFrames.count > 0) {
@ -568,13 +572,7 @@ RCT_SCROLL_EVENT_HANDLER(scrollViewDidZoom, RCTScrollEventTypeMove)
- (BOOL)respondsToSelector:(SEL)aSelector
{
if ([super respondsToSelector:aSelector]) {
return YES;
}
if ([NSStringFromSelector(aSelector) hasPrefix:@"set"]) {
return [_scrollView respondsToSelector:aSelector];
}
return NO;
return [super respondsToSelector:aSelector] || [_scrollView respondsToSelector:aSelector];
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key

View File

@ -5,6 +5,8 @@
#import "RCTBridge.h"
#import "RCTConvert.h"
#import "RCTScrollView.h"
#import "RCTSparseArray.h"
#import "RCTUIManager.h"
@implementation RCTScrollViewManager
@ -52,4 +54,25 @@ RCT_EXPORT_VIEW_PROPERTY(contentOffset);
};
}
- (void)getContentSize:(NSNumber *)reactTag
callback:(RCTResponseSenderBlock)callback
{
RCT_EXPORT();
[self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
UIView *view = viewRegistry[reactTag];
if (!view) {
RCTLogError(@"Cannot find view with tag %@", reactTag);
return;
}
CGSize size = ((id<RCTScrollableProtocol>)view).contentSize;
callback(@[@{
@"width" : @(size.width),
@"height" : @(size.height)
}]);
}];
}
@end

View File

@ -8,7 +8,7 @@
*/
@protocol RCTScrollableProtocol
@property (nonatomic, readwrite, weak) NSObject<UIScrollViewDelegate> *nativeMainScrollDelegate;
@property (nonatomic, weak) NSObject<UIScrollViewDelegate> *nativeMainScrollDelegate;
@property (nonatomic, readonly) CGSize contentSize;
- (void)scrollToOffset:(CGPoint)offset;

View File

@ -99,7 +99,6 @@
// 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];
//[RCTView addViewController:_tabController toBackingViewControllerForView:self];
if (_tabsChanged) {

View File

@ -24,4 +24,21 @@
*/
+ (UIEdgeInsets)contentInsetsForView:(UIView *)curView;
/**
* 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;
@end

View File

@ -7,6 +7,65 @@
#import "RCTLog.h"
#import "UIView+ReactKit.h"
@implementation UIView (RCTViewUnmounting)
- (void)react_remountAllSubviews
{
// Normal views don't support unmounting, so all
// this does is forward message to our subviews,
// in case any of those do support it
for (UIView *subview in self.subviews) {
[subview react_remountAllSubviews];
}
}
- (void)react_updateClippedSubviewsWithClipRect:(CGRect)clipRect relativeToView:(UIView *)clipView
{
// Even though we don't support subview unmounting
// we do support clipsToBounds, so if that's enabled
// we'll update the clipping
if (self.clipsToBounds && [self.subviews count] > 0) {
clipRect = [clipView convertRect:clipRect toView:self];
clipRect = CGRectIntersection(clipRect, self.bounds);
clipView = self;
}
// Normal views don't support unmounting, so all
// this does is forward message to our subviews,
// in case any of those do support it
for (UIView *subview in self.subviews) {
[subview react_updateClippedSubviewsWithClipRect:clipRect relativeToView:clipView];
}
}
- (UIView *)react_findClipView
{
UIView *testView = self;
UIView *clipView = nil;
CGRect clipRect = self.bounds;
while (testView) {
if (testView.clipsToBounds) {
if (clipView) {
CGRect testRect = [clipView convertRect:clipRect toView:testView];
if (!CGRectContainsRect(testView.bounds, testRect)) {
clipView = testView;
clipRect = CGRectIntersection(testView.bounds, testRect);
}
} else {
clipView = testView;
clipRect = [self convertRect:self.bounds toView:clipView];
}
}
testView = testView.superview;
}
return clipView ?: self.window;
}
@end
static NSString *RCTRecursiveAccessibilityLabel(UIView *view)
{
NSMutableString *str = [NSMutableString stringWithString:@""];
@ -23,6 +82,9 @@ static NSString *RCTRecursiveAccessibilityLabel(UIView *view)
}
@implementation RCTView
{
NSMutableArray *_reactSubviews;
}
- (NSString *)accessibilityLabel
{
@ -115,4 +177,193 @@ static NSString *RCTRecursiveAccessibilityLabel(UIView *view)
return UIEdgeInsetsZero;
}
#pragma mark - View unmounting
- (void)react_remountAllSubviews
{
if (_reactSubviews) {
NSInteger index = 0;
for (UIView *view in _reactSubviews) {
if (view.superview != self) {
if (index < [self subviews].count) {
[self insertSubview:view atIndex:index];
} else {
[self addSubview:view];
}
[view react_remountAllSubviews];
}
index++;
}
} else {
// If react_subviews is nil, we must already be showing all subviews
[super react_remountAllSubviews];
}
}
- (void)remountSubview:(UIView *)view
{
// Calculate insertion index for view
NSInteger index = 0;
for (UIView *subview in _reactSubviews) {
if (subview == view) {
[self insertSubview:view atIndex:index];
break;
}
if (subview.superview) {
// View is mounted, so bump the index
index++;
}
}
}
- (void)mountOrUnmountSubview:(UIView *)view withClipRect:(CGRect)clipRect relativeToView:(UIView *)clipView
{
if (view.clipsToBounds) {
// View has cliping enabled, so we can easily test if it is partially
// or completely within the clipRect, and mount or unmount it accordingly
if (CGRectIntersectsRect(clipRect, view.frame)) {
// View is at least partially visible, so remount it if unmounted
if (view.superview == nil) {
[self remountSubview:view];
}
// Then test its subviews
if (CGRectContainsRect(clipRect, view.frame)) {
[view react_remountAllSubviews];
} else {
[view react_updateClippedSubviewsWithClipRect:clipRect relativeToView:clipView];
}
} else if (view.superview) {
// View is completely outside the clipRect, so unmount it
[view removeFromSuperview];
}
} else {
// View has clipping disabled, so there's no way to tell if it has
// any visible subviews without an expensive recursive test, so we'll
// just add it.
if (view.superview == nil) {
[self remountSubview:view];
}
// Check if subviews need to be mounted/unmounted
[view react_updateClippedSubviewsWithClipRect:clipRect relativeToView:clipView];
}
}
- (void)react_updateClippedSubviewsWithClipRect:(CGRect)clipRect relativeToView:(UIView *)clipView
{
// TODO (#5906496): for scrollviews (the primary use-case) we could
// optimize this by only doing a range check along the scroll axis,
// instead of comparing the whole frame
if (_reactSubviews == nil) {
// Use default behavior if unmounting is disabled
return [super react_updateClippedSubviewsWithClipRect:clipRect relativeToView:clipView];
}
if ([_reactSubviews count] == 0) {
// Do nothing if we have no subviews
return;
}
if (CGSizeEqualToSize(self.bounds.size, CGSizeZero)) {
// Do nothing if layout hasn't happened yet
return;
}
// Convert clipping rect to local coordinates
clipRect = [clipView convertRect:clipRect toView:self];
clipView = self;
if (self.clipsToBounds) {
clipRect = CGRectIntersection(clipRect, self.bounds);
}
// Mount / unmount views
for (UIView *view in _reactSubviews) {
[self mountOrUnmountSubview:view withClipRect:clipRect relativeToView:clipView];
}
}
- (void)setRemoveClippedSubviews:(BOOL)removeClippedSubviews
{
if (removeClippedSubviews && !_reactSubviews) {
_reactSubviews = [self.subviews mutableCopy];
} else if (!removeClippedSubviews && _reactSubviews) {
[self react_remountAllSubviews];
_reactSubviews = nil;
}
}
- (BOOL)removeClippedSubviews
{
return _reactSubviews != nil;
}
- (void)insertReactSubview:(UIView *)view atIndex:(NSInteger)atIndex
{
if (_reactSubviews == nil) {
[self insertSubview:view atIndex:atIndex];
} else {
[_reactSubviews insertObject:view atIndex:atIndex];
// Find a suitable view to use for clipping
UIView *clipView = [self react_findClipView];
if (clipView) {
// If possible, don't add subviews if they are clipped
[self mountOrUnmountSubview:view withClipRect:clipView.bounds relativeToView:clipView];
} else {
// Fallback if we can't find a suitable clipView
[self remountSubview:view];
}
}
}
- (void)removeReactSubview:(UIView *)subview
{
[_reactSubviews removeObject:subview];
[subview removeFromSuperview];
}
- (NSArray *)reactSubviews
{
// The _reactSubviews array is only used when we have hidden
// offscreen views. If _reactSubviews is nil, we can assume
// that [self reactSubviews] and [self subviews] are the same
return _reactSubviews ?: [self subviews];
}
- (void)updateClippedSubviews
{
// Find a suitable view to use for clipping
UIView *clipView = [self react_findClipView];
if (clipView) {
[self react_updateClippedSubviewsWithClipRect:clipView.bounds relativeToView:clipView];
}
}
- (void)layoutSubviews
{
// TODO (#5906496): this a nasty performance drain, but necessary
// to prevent gaps appearing when the loading spinner disappears.
// We might be able to fix this another way by triggering a call
// to updateClippedSubviews manually after loading
[super layoutSubviews];
if (_reactSubviews) {
[self updateClippedSubviews];
}
}
@end

View File

@ -99,8 +99,8 @@
- (void)loadView
{
// add a wrapper so that UIViewControllerWrapperView (managed by the
// UINavigationController) doesn't end up resetting the frames for
// Add a wrapper so that the wrapper view managed by the
// UINavigationController doesn't end up resetting the frames for
//`contentView` which is a react-managed view.
_wrapperView = [[UIView alloc] initWithFrame:_contentView.bounds];
[_wrapperView addSubview:_contentView];