diff --git a/Examples/UIExplorer/UIExplorer.xcodeproj/project.pbxproj b/Examples/UIExplorer/UIExplorer.xcodeproj/project.pbxproj index 274b0a0ad..6c4cf8a2e 100644 --- a/Examples/UIExplorer/UIExplorer.xcodeproj/project.pbxproj +++ b/Examples/UIExplorer/UIExplorer.xcodeproj/project.pbxproj @@ -32,7 +32,6 @@ 1497CFAF1B21F5E400C1F8F2 /* RCTConvert_NSURLTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1497CFA71B21F5E400C1F8F2 /* RCTConvert_NSURLTests.m */; }; 1497CFB01B21F5E400C1F8F2 /* RCTConvert_UIFontTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1497CFA81B21F5E400C1F8F2 /* RCTConvert_UIFontTests.m */; }; 1497CFB11B21F5E400C1F8F2 /* RCTEventDispatcherTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1497CFA91B21F5E400C1F8F2 /* RCTEventDispatcherTests.m */; }; - 1497CFB21B21F5E400C1F8F2 /* RCTSparseArrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1497CFAA1B21F5E400C1F8F2 /* RCTSparseArrayTests.m */; }; 1497CFB31B21F5E400C1F8F2 /* RCTUIManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1497CFAB1B21F5E400C1F8F2 /* RCTUIManagerTests.m */; }; 14AADF051AC3DBB1002390C9 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14AADF041AC3DB95002390C9 /* libReact.a */; }; 14B6DA821B276C5900BF4DD1 /* libRCTTest.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 58005BEE1ABA80530062E044 /* libRCTTest.a */; }; @@ -209,7 +208,6 @@ 1497CFA71B21F5E400C1F8F2 /* RCTConvert_NSURLTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTConvert_NSURLTests.m; sourceTree = ""; }; 1497CFA81B21F5E400C1F8F2 /* RCTConvert_UIFontTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTConvert_UIFontTests.m; sourceTree = ""; }; 1497CFA91B21F5E400C1F8F2 /* RCTEventDispatcherTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTEventDispatcherTests.m; sourceTree = ""; }; - 1497CFAA1B21F5E400C1F8F2 /* RCTSparseArrayTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTSparseArrayTests.m; sourceTree = ""; }; 1497CFAB1B21F5E400C1F8F2 /* RCTUIManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTUIManagerTests.m; sourceTree = ""; }; 14AADEFF1AC3DB95002390C9 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = ../../React/React.xcodeproj; sourceTree = ""; }; 14D6D7021B220AE3001FB087 /* NSNotificationCenter+OCMAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSNotificationCenter+OCMAdditions.h"; sourceTree = ""; }; @@ -400,7 +398,6 @@ 13DF61B51B67A45000EDB188 /* RCTMethodArgumentTests.m */, 1393D0371B68CD1300E1B601 /* RCTModuleMethodTests.m */, 138D6A161B53CD440074A87E /* RCTShadowViewTests.m */, - 1497CFAA1B21F5E400C1F8F2 /* RCTSparseArrayTests.m */, 1497CFAB1B21F5E400C1F8F2 /* RCTUIManagerTests.m */, 143BC57E1B21E18100462512 /* Info.plist */, 14D6D7101B220EB3001FB087 /* libOCMock.a */, @@ -852,7 +849,6 @@ 1497CFB01B21F5E400C1F8F2 /* RCTConvert_UIFontTests.m in Sources */, 144D21241B2204C5006DB32B /* RCTImageUtilTests.m in Sources */, 1393D0381B68CD1300E1B601 /* RCTModuleMethodTests.m in Sources */, - 1497CFB21B21F5E400C1F8F2 /* RCTSparseArrayTests.m in Sources */, 1300627F1B59179B0043FE5A /* RCTGzipTests.m in Sources */, 1497CFAF1B21F5E400C1F8F2 /* RCTConvert_NSURLTests.m in Sources */, 1497CFAE1B21F5E400C1F8F2 /* RCTContextExecutorTests.m in Sources */, @@ -991,6 +987,12 @@ PRODUCT_BUNDLE_IDENTIFIER = com.facebook.internal.uiexplorer.local; PRODUCT_NAME = UIExplorer; TARGETED_DEVICE_FAMILY = "1,2"; + WARNING_CFLAGS = ( + "-Wextra", + "-Wall", + "-Wincompatible-pointer-types", + "-Wincompatible-pointer-types-discards-qualifiers", + ); }; name = Debug; }; @@ -1011,6 +1013,12 @@ PRODUCT_BUNDLE_IDENTIFIER = com.facebook.internal.uiexplorer.local; PRODUCT_NAME = UIExplorer; TARGETED_DEVICE_FAMILY = "1,2"; + WARNING_CFLAGS = ( + "-Wextra", + "-Wall", + "-Wincompatible-pointer-types", + "-Wincompatible-pointer-types-discards-qualifiers", + ); }; name = Release; }; diff --git a/Examples/UIExplorer/UIExplorerIntegrationTests/RCTUIManagerScenarioTests.m b/Examples/UIExplorer/UIExplorerIntegrationTests/RCTUIManagerScenarioTests.m index 137612b9e..520c9beda 100644 --- a/Examples/UIExplorer/UIExplorerIntegrationTests/RCTUIManagerScenarioTests.m +++ b/Examples/UIExplorer/UIExplorerIntegrationTests/RCTUIManagerScenarioTests.m @@ -14,7 +14,6 @@ #import #import -#import "RCTSparseArray.h" #import "RCTUIManager.h" #import "UIView+React.h" @@ -26,9 +25,9 @@ addChildReactTags:(NSArray *)addChildReactTags addAtIndices:(NSArray *)addAtIndices removeAtIndices:(NSArray *)removeAtIndices - registry:(RCTSparseArray *)registry; + registry:(NSMutableDictionary> *)registry; -@property (nonatomic, readonly) RCTSparseArray *viewRegistry; +@property (nonatomic, readonly) NSMutableDictionary *viewRegistry; @end @@ -50,13 +49,13 @@ for (NSInteger i = 1; i <= 20; i++) { UIView *registeredView = [UIView new]; registeredView.reactTag = @(i); - _uiManager.viewRegistry[i] = registeredView; + _uiManager.viewRegistry[@(i)] = registeredView; } } - (void)testManagingChildrenToAddViews { - UIView *containerView = _uiManager.viewRegistry[20]; + UIView *containerView = _uiManager.viewRegistry[@20]; NSMutableArray *addedViews = [NSMutableArray array]; NSArray *tagsToAdd = @[@1, @2, @3, @4, @5]; @@ -72,7 +71,7 @@ addChildReactTags:tagsToAdd addAtIndices:addAtIndices removeAtIndices:nil - registry:_uiManager.viewRegistry]; + registry:(NSMutableDictionary> *)_uiManager.viewRegistry]; XCTAssertTrue([[containerView reactSubviews] count] == 5, @"Expect to have 5 react subviews after calling manage children \ @@ -86,7 +85,7 @@ - (void)testManagingChildrenToRemoveViews { - UIView *containerView = _uiManager.viewRegistry[20]; + UIView *containerView = _uiManager.viewRegistry[@20]; NSMutableArray *removedViews = [NSMutableArray array]; NSArray *removeAtIndices = @[@0, @4, @8, @12, @16]; @@ -95,7 +94,7 @@ [removedViews addObject:_uiManager.viewRegistry[reactTag]]; } for (NSInteger i = 2; i < 20; i++) { - UIView *view = _uiManager.viewRegistry[i]; + UIView *view = _uiManager.viewRegistry[@(i)]; [containerView addSubview:view]; } @@ -106,7 +105,7 @@ addChildReactTags:nil addAtIndices:nil removeAtIndices:removeAtIndices - registry:_uiManager.viewRegistry]; + registry:(NSMutableDictionary> *)_uiManager.viewRegistry]; XCTAssertEqual(containerView.reactSubviews.count, (NSUInteger)13, @"Expect to have 13 react subviews after calling manage children\ @@ -119,7 +118,7 @@ _uiManager.viewRegistry[view.reactTag] = view; } for (NSInteger i = 2; i < 20; i++) { - UIView *view = _uiManager.viewRegistry[i]; + UIView *view = _uiManager.viewRegistry[@(i)]; if (![removedViews containsObject:view]) { XCTAssertTrue([view superview] == containerView, @"Should not have removed view with react tag %ld during delete but did", (long)i); @@ -138,7 +137,7 @@ // [11,5,1,2,7,8,12,10] - (void)testManagingChildrenToAddRemoveAndMove { - UIView *containerView = _uiManager.viewRegistry[20]; + UIView *containerView = _uiManager.viewRegistry[@20]; NSArray *removeAtIndices = @[@2, @3, @5, @8]; NSArray *addAtIndices = @[@0, @6]; @@ -155,7 +154,7 @@ } for (NSInteger i = 1; i < 11; i++) { - UIView *view = _uiManager.viewRegistry[i]; + UIView *view = _uiManager.viewRegistry[@(i)]; [containerView addSubview:view]; } @@ -165,7 +164,7 @@ addChildReactTags:tagsToAdd addAtIndices:addAtIndices removeAtIndices:removeAtIndices - registry:_uiManager.viewRegistry]; + registry:(NSMutableDictionary> *)_uiManager.viewRegistry]; XCTAssertTrue([[containerView reactSubviews] count] == 8, @"Expect to have 8 react subviews after calling manage children,\ @@ -180,7 +179,7 @@ // Clean up after ourselves for (NSInteger i = 1; i < 13; i++) { - UIView *view = _uiManager.viewRegistry[i]; + UIView *view = _uiManager.viewRegistry[@(i)]; [view removeFromSuperview]; } for (UIView *view in viewsToRemove) { diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m index 7802f4ad1..c201f5799 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTBridgeTests.m @@ -31,7 +31,7 @@ @interface TestExecutor : NSObject -@property (nonatomic, readonly, copy) NSMutableDictionary *injectedStuff; +@property (nonatomic, readonly, copy) NSMutableDictionary *injectedStuff; @end @@ -137,7 +137,7 @@ _Pragma("clang diagnostic pop") RUN_RUNLOOP_WHILE(!(injectedStuff = executor.injectedStuff[@"__fbBatchedBridgeConfig"])); __block NSNumber *testModuleID = nil; - __block NSDictionary *testConstants = nil; + __block NSDictionary *testConstants = nil; __block NSNumber *testMethodID = nil; NSArray *remoteModuleConfig = RCTJSONParse(injectedStuff, NULL)[@"remoteModuleConfig"]; @@ -165,7 +165,7 @@ _Pragma("clang diagnostic pop") RUN_RUNLOOP_WHILE(!(injectedStuff = executor.injectedStuff[@"__fbBatchedBridgeConfig"])); __block NSNumber *testModuleID = nil; - __block NSDictionary *testConstants = nil; + __block NSDictionary *testConstants = nil; __block NSNumber *testMethodID = nil; NSArray *remoteModuleConfig = RCTJSONParse(injectedStuff, NULL)[@"remoteModuleConfig"]; @@ -211,7 +211,7 @@ RCT_EXPORT_METHOD(testMethod:(NSInteger)integer XCTAssertNotNil(callback); } -- (NSDictionary *)constantsToExport +- (NSDictionary *)constantsToExport { return @{@"eleventyMillion": @42}; } diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTEventDispatcherTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTEventDispatcherTests.m index bfa52b94f..5761849d6 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTEventDispatcherTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTEventDispatcherTests.m @@ -26,7 +26,7 @@ @implementation RCTTestEvent -- (instancetype)initWithViewTag:(NSNumber *)viewTag eventName:(NSString *)eventName body:(NSDictionary *)body +- (instancetype)initWithViewTag:(NSNumber *)viewTag eventName:(NSString *)eventName body:(NSDictionary *)body { if (self = [super initWithViewTag:viewTag eventName:eventName body:body]) { self.canCoalesce = YES; @@ -50,7 +50,7 @@ RCTEventDispatcher *_eventDispatcher; NSString *_eventName; - NSDictionary *_body; + NSDictionary *_body; RCTTestEvent *_testEvent; NSString *_JSMethod; } diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTGzipTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTGzipTests.m index ceb58b972..69162a764 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTGzipTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTGzipTests.m @@ -20,7 +20,7 @@ extern BOOL RCTIsGzippedData(NSData *data); @interface RCTNetworking (Private) -- (void)buildRequest:(NSDictionary *)query +- (void)buildRequest:(NSDictionary *)query completionBlock:(void (^)(NSURLRequest *request))block; @end diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTJSONTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTJSONTests.m index b8951ca02..fd8343c08 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTJSONTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTJSONTests.m @@ -23,14 +23,14 @@ - (void)testEncodingObject { - NSDictionary *obj = @{@"foo": @"bar"}; + NSDictionary *obj = @{@"foo": @"bar"}; NSString *json = @"{\"foo\":\"bar\"}"; XCTAssertEqualObjects(json, RCTJSONStringify(obj, NULL)); } - (void)testEncodingArray { - NSArray *array = @[@"foo", @"bar"]; + NSArray *array = @[@"foo", @"bar"]; NSString *json = @"[\"foo\",\"bar\"]"; XCTAssertEqualObjects(json, RCTJSONStringify(array, NULL)); } @@ -44,14 +44,14 @@ - (void)testDecodingObject { - NSDictionary *obj = @{@"foo": @"bar"}; + NSDictionary *obj = @{@"foo": @"bar"}; NSString *json = @"{\"foo\":\"bar\"}"; XCTAssertEqualObjects(obj, RCTJSONParse(json, NULL)); } - (void)testDecodingArray { - NSArray *array = @[@"foo", @"bar"]; + NSArray *array = @[@"foo", @"bar"]; NSString *json = @"[\"foo\",\"bar\"]"; XCTAssertEqualObjects(array, RCTJSONParse(json, NULL)); } @@ -66,14 +66,14 @@ - (void)testDecodingMutableArray { NSString *json = @"[1,2,3]"; - NSMutableArray *array = RCTJSONParseMutable(json, NULL); + NSMutableArray *array = RCTJSONParseMutable(json, NULL); XCTAssertNoThrow([array addObject:@4]); XCTAssertEqualObjects(array, (@[@1, @2, @3, @4])); } - (void)testLeadingWhitespace { - NSDictionary *obj = @{@"foo": @"bar"}; + NSDictionary *obj = @{@"foo": @"bar"}; NSString *json = @" \r\n\t{\"foo\":\"bar\"}"; XCTAssertEqualObjects(obj, RCTJSONParse(json, NULL)); } diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTSparseArrayTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTSparseArrayTests.m deleted file mode 100644 index 57e7a0bf2..000000000 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTSparseArrayTests.m +++ /dev/null @@ -1,55 +0,0 @@ -/** - * The examples provided by Facebook are for non-commercial testing and - * evaluation purposes only. - * - * Facebook reserves all rights not expressly granted. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL - * FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#import - -#import "RCTSparseArray.h" -#import "UIView+React.h" - -@interface RCTSparseArrayTests : XCTestCase - -@end - -@implementation RCTSparseArrayTests - -- (void)testDictionary -{ - id myView = [UIView new]; - myView.reactTag = @4; - - id myOtherView = [UIView new]; - myOtherView.reactTag = @5; - - RCTSparseArray *registry = [RCTSparseArray new]; - XCTAssertNil(registry[@4], @"how did you have a view when none are registered?"); - XCTAssertNil(registry[@5], @"how did you have a view when none are registered?"); - - registry[myView.reactTag] = myView; - XCTAssertEqual(registry[@4], myView); - XCTAssertNil(registry[@5], @"didn't register other view yet"); - - registry[myOtherView.reactTag] = myOtherView; - XCTAssertEqual(registry[@4], myView); - XCTAssertEqual(registry[@5], myOtherView); - - registry[myView.reactTag] = nil; - XCTAssertNil(registry[@4]); - XCTAssertEqual(registry[@5], myOtherView); - - registry[myOtherView.reactTag] = nil; - XCTAssertNil(registry[@4], @"how did you have a view when none are registered?"); - XCTAssertNil(registry[@5], @"how did you have a view when none are registered?"); -} - -@end diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTUIManagerTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTUIManagerTests.m index 9be80dca9..4ae4b9f5c 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTUIManagerTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTUIManagerTests.m @@ -14,7 +14,6 @@ #import -#import "RCTSparseArray.h" #import "RCTUIManager.h" #import "UIView+React.h" @@ -26,9 +25,9 @@ addChildReactTags:(NSArray *)addChildReactTags addAtIndices:(NSArray *)addAtIndices removeAtIndices:(NSArray *)removeAtIndices - registry:(RCTSparseArray *)registry; + registry:(NSDictionary> *)registry; -@property (nonatomic, readonly) RCTSparseArray *viewRegistry; +@property (nonatomic, copy, readonly) NSMutableDictionary *viewRegistry; @end @@ -50,13 +49,13 @@ for (NSInteger i = 1; i <= 20; i++) { UIView *registeredView = [UIView new]; registeredView.reactTag = @(i); - _uiManager.viewRegistry[i] = registeredView; + _uiManager.viewRegistry[@(i)] = registeredView; } } - (void)testManagingChildrenToAddViews { - UIView *containerView = _uiManager.viewRegistry[20]; + UIView *containerView = _uiManager.viewRegistry[@20]; NSMutableArray *addedViews = [NSMutableArray array]; NSArray *tagsToAdd = @[@1, @2, @3, @4, @5]; @@ -86,7 +85,7 @@ - (void)testManagingChildrenToRemoveViews { - UIView *containerView = _uiManager.viewRegistry[20]; + UIView *containerView = _uiManager.viewRegistry[@20]; NSMutableArray *removedViews = [NSMutableArray array]; NSArray *removeAtIndices = @[@0, @4, @8, @12, @16]; @@ -95,7 +94,7 @@ [removedViews addObject:_uiManager.viewRegistry[reactTag]]; } for (NSInteger i = 2; i < 20; i++) { - UIView *view = _uiManager.viewRegistry[i]; + UIView *view = _uiManager.viewRegistry[@(i)]; [containerView addSubview:view]; } @@ -119,7 +118,7 @@ _uiManager.viewRegistry[view.reactTag] = view; } for (NSInteger i = 2; i < 20; i++) { - UIView *view = _uiManager.viewRegistry[i]; + UIView *view = _uiManager.viewRegistry[@(i)]; if (![removedViews containsObject:view]) { XCTAssertTrue([view superview] == containerView, @"Should not have removed view with react tag %ld during delete but did", (long)i); @@ -138,7 +137,7 @@ // [11,5,1,2,7,8,12,10] - (void)testManagingChildrenToAddRemoveAndMove { - UIView *containerView = _uiManager.viewRegistry[20]; + UIView *containerView = _uiManager.viewRegistry[@20]; NSArray *removeAtIndices = @[@2, @3, @5, @8]; NSArray *addAtIndices = @[@0, @6]; @@ -155,7 +154,7 @@ } for (NSInteger i = 1; i < 11; i++) { - UIView *view = _uiManager.viewRegistry[i]; + UIView *view = _uiManager.viewRegistry[@(i)]; [containerView addSubview:view]; } @@ -180,7 +179,7 @@ // Clean up after ourselves for (NSInteger i = 1; i < 13; i++) { - UIView *view = _uiManager.viewRegistry[i]; + UIView *view = _uiManager.viewRegistry[@(i)]; [view removeFromSuperview]; } for (UIView *view in viewsToRemove) { diff --git a/Libraries/CameraRoll/RCTCameraRollManager.m b/Libraries/CameraRoll/RCTCameraRollManager.m index e2044f03c..b1c285186 100644 --- a/Libraries/CameraRoll/RCTCameraRollManager.m +++ b/Libraries/CameraRoll/RCTCameraRollManager.m @@ -46,7 +46,7 @@ RCT_ENUM_CONVERTER(ALAssetsGroupType, (@{ + (ALAssetsFilter *)ALAssetsFilter:(id)json { - static NSDictionary *options; + static NSDictionary *options; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ options = @{ @@ -102,29 +102,31 @@ RCT_EXPORT_METHOD(saveImageWithTag:(NSString *)imageTag }]; } -- (void)callCallback:(RCTResponseSenderBlock)callback - withAssets:(NSArray *)assets - hasNextPage:(BOOL)hasNextPage +static void RCTCallCallback(RCTResponseSenderBlock callback, + NSArray *> *assets, + BOOL hasNextPage) { if (!assets.count) { callback(@[@{ - @"edges": assets, - @"page_info": @{ - @"has_next_page": @NO} - }]); + @"edges": assets, + @"page_info": @{ + @"has_next_page": @NO, + } + }]); return; } callback(@[@{ - @"edges": assets, - @"page_info": @{ - @"start_cursor": assets[0][@"node"][@"image"][@"uri"], - @"end_cursor": assets[assets.count - 1][@"node"][@"image"][@"uri"], - @"has_next_page": @(hasNextPage)} - }]); + @"edges": assets, + @"page_info": @{ + @"start_cursor": assets[0][@"node"][@"image"][@"uri"], + @"end_cursor": assets[assets.count - 1][@"node"][@"image"][@"uri"], + @"has_next_page": @(hasNextPage), + } + }]); } RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params - callback:(RCTResponseSenderBlock)callback + successCallback:(RCTResponseSenderBlock)successCallback errorCallback:(RCTResponseErrorBlock)errorCallback) { NSUInteger first = [RCTConvert NSInteger:params[@"first"]]; @@ -136,7 +138,7 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params BOOL __block foundAfter = NO; BOOL __block hasNextPage = NO; BOOL __block calledCallback = NO; - NSMutableArray *assets = [NSMutableArray new]; + NSMutableArray *> *assets = [NSMutableArray new]; [_bridge.assetsLibrary enumerateGroupsWithTypes:groupTypes usingBlock:^(ALAssetsGroup *group, BOOL *stopGroups) { if (group && (groupName == nil || [groupName isEqualToString:[group valueForProperty:ALAssetsGroupPropertyName]])) { @@ -156,7 +158,7 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params *stopGroups = YES; hasNextPage = YES; RCTAssert(calledCallback == NO, @"Called the callback before we finished processing the results."); - [self callCallback:callback withAssets:assets hasNextPage:hasNextPage]; + RCTCallCallback(successCallback, assets, hasNextPage); calledCallback = YES; return; } @@ -164,33 +166,32 @@ RCT_EXPORT_METHOD(getPhotos:(NSDictionary *)params CLLocation *loc = [result valueForProperty:ALAssetPropertyLocation]; NSDate *date = [result valueForProperty:ALAssetPropertyDate]; [assets addObject:@{ - @"node": @{ - @"type": [result valueForProperty:ALAssetPropertyType], - @"group_name": [group valueForProperty:ALAssetsGroupPropertyName], - @"image": @{ - @"uri": uri, - @"height": @(dimensions.height), - @"width": @(dimensions.width), - @"isStored": @YES, - }, - @"timestamp": @(date.timeIntervalSince1970), - @"location": loc ? - @{ - @"latitude": @(loc.coordinate.latitude), - @"longitude": @(loc.coordinate.longitude), - @"altitude": @(loc.altitude), - @"heading": @(loc.course), - @"speed": @(loc.speed), - } : @{}, - } - }]; + @"node": @{ + @"type": [result valueForProperty:ALAssetPropertyType], + @"group_name": [group valueForProperty:ALAssetsGroupPropertyName], + @"image": @{ + @"uri": uri, + @"height": @(dimensions.height), + @"width": @(dimensions.width), + @"isStored": @YES, + }, + @"timestamp": @(date.timeIntervalSince1970), + @"location": loc ? @{ + @"latitude": @(loc.coordinate.latitude), + @"longitude": @(loc.coordinate.longitude), + @"altitude": @(loc.altitude), + @"heading": @(loc.course), + @"speed": @(loc.speed), + } : @{}, + } + }]; } }]; } else { // Sometimes the enumeration continues even if we set stop above, so we guard against calling the callback // multiple times here. if (!calledCallback) { - [self callCallback:callback withAssets:assets hasNextPage:hasNextPage]; + RCTCallCallback(successCallback, assets, hasNextPage); calledCallback = YES; } } diff --git a/Libraries/CameraRoll/RCTImagePickerManager.m b/Libraries/CameraRoll/RCTImagePickerManager.m index d6f8846c0..9f7daa622 100644 --- a/Libraries/CameraRoll/RCTImagePickerManager.m +++ b/Libraries/CameraRoll/RCTImagePickerManager.m @@ -9,6 +9,8 @@ */ #import "RCTImagePickerManager.h" + +#import "RCTConvert.h" #import "RCTRootView.h" #import "RCTLog.h" #import "RCTUtils.h" @@ -66,7 +68,7 @@ RCT_EXPORT_METHOD(openCameraDialog:(NSDictionary *)config imagePicker.delegate = self; imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; - if ([config[@"videoMode"] boolValue]) { + if ([RCTConvert BOOL:config[@"videoMode"]]) { imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo; } @@ -93,10 +95,10 @@ RCT_EXPORT_METHOD(openSelectDialog:(NSDictionary *)config imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; NSMutableArray *allowedTypes = [NSMutableArray new]; - if ([config[@"showImages"] boolValue]) { + if ([RCTConvert BOOL:config[@"showImages"]]) { [allowedTypes addObject:(NSString *)kUTTypeImage]; } - if ([config[@"showVideos"] boolValue]) { + if ([RCTConvert BOOL:config[@"showVideos"]]) { [allowedTypes addObject:(NSString *)kUTTypeMovie]; } @@ -110,7 +112,7 @@ RCT_EXPORT_METHOD(openSelectDialog:(NSDictionary *)config } - (void)imagePickerController:(UIImagePickerController *)picker -didFinishPickingMediaWithInfo:(NSDictionary *)info +didFinishPickingMediaWithInfo:(NSDictionary *)info { NSUInteger index = [_pickers indexOfObject:picker]; RCTResponseSenderBlock callback = _pickerCallbacks[index]; diff --git a/Libraries/CameraRoll/RCTPhotoLibraryImageLoader.m b/Libraries/CameraRoll/RCTPhotoLibraryImageLoader.m index d0e5b6459..33a9cb31b 100644 --- a/Libraries/CameraRoll/RCTPhotoLibraryImageLoader.m +++ b/Libraries/CameraRoll/RCTPhotoLibraryImageLoader.m @@ -50,7 +50,7 @@ RCT_EXPORT_MODULE() PHImageRequestOptions *imageOptions = [PHImageRequestOptions new]; if (progressHandler) { - imageOptions.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) { + imageOptions.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) { static const double multiplier = 1e6; progressHandler(progress * multiplier, multiplier); }; @@ -80,7 +80,7 @@ RCT_EXPORT_MODULE() targetSize:targetSize contentMode:contentMode options:imageOptions - resultHandler:^(UIImage *result, NSDictionary *info) { + resultHandler:^(UIImage *result, NSDictionary *info) { if (result) { completionHandler(nil, result); } else { diff --git a/Libraries/Geolocation/RCTLocationObserver.m b/Libraries/Geolocation/RCTLocationObserver.m index b97011630..ab02bd582 100644 --- a/Libraries/Geolocation/RCTLocationObserver.m +++ b/Libraries/Geolocation/RCTLocationObserver.m @@ -37,7 +37,7 @@ typedef struct { + (RCTLocationOptions)RCTLocationOptions:(id)json { - NSDictionary *options = [RCTConvert NSDictionary:json]; + NSDictionary *options = [RCTConvert NSDictionary:json]; return (RCTLocationOptions){ .timeout = [RCTConvert NSTimeInterval:options[@"timeout"]] ?: INFINITY, .maximumAge = [RCTConvert NSTimeInterval:options[@"maximumAge"]] ?: INFINITY, @@ -47,7 +47,7 @@ typedef struct { @end -static NSDictionary *RCTPositionError(RCTPositionErrorCode code, NSString *msg /* nil for default */) +static NSDictionary *RCTPositionError(RCTPositionErrorCode code, NSString *msg /* nil for default */) { if (!msg) { switch (code) { @@ -99,7 +99,7 @@ static NSDictionary *RCTPositionError(RCTPositionErrorCode code, NSString *msg / @implementation RCTLocationObserver { CLLocationManager *_locationManager; - NSDictionary *_lastLocationEvent; + NSDictionary *_lastLocationEvent; NSMutableArray *_pendingRequests; BOOL _observingLocation; RCTLocationOptions _observerOptions; @@ -295,7 +295,7 @@ RCT_EXPORT_METHOD(getCurrentPosition:(RCTLocationOptions)options - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { // Check error type - NSDictionary *jsError = nil; + NSDictionary *jsError = nil; switch (error.code) { case kCLErrorDenied: jsError = RCTPositionError(RCTPositionErrorDenied, nil); diff --git a/Libraries/Image/RCTGIFImageDecoder.m b/Libraries/Image/RCTGIFImageDecoder.m index 473210025..b90375856 100644 --- a/Libraries/Image/RCTGIFImageDecoder.m +++ b/Libraries/Image/RCTGIFImageDecoder.m @@ -34,7 +34,7 @@ RCT_EXPORT_MODULE() completionHandler:(RCTImageLoaderCompletionBlock)completionHandler { CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL); - NSDictionary *properties = (__bridge_transfer NSDictionary *)CGImageSourceCopyProperties(imageSource, NULL); + NSDictionary *properties = (__bridge_transfer NSDictionary *)CGImageSourceCopyProperties(imageSource, NULL); NSUInteger loopCount = [properties[(id)kCGImagePropertyGIFDictionary][(id)kCGImagePropertyGIFLoopCount] unsignedIntegerValue]; UIImage *image = nil; @@ -51,8 +51,8 @@ RCT_EXPORT_MODULE() image = [UIImage imageWithCGImage:imageRef scale:scale orientation:UIImageOrientationUp]; } - NSDictionary *frameProperties = (__bridge_transfer NSDictionary *)CGImageSourceCopyPropertiesAtIndex(imageSource, i, NULL); - NSDictionary *frameGIFProperties = frameProperties[(id)kCGImagePropertyGIFDictionary]; + NSDictionary *frameProperties = (__bridge_transfer NSDictionary *)CGImageSourceCopyPropertiesAtIndex(imageSource, i, NULL); + NSDictionary *frameGIFProperties = frameProperties[(id)kCGImagePropertyGIFDictionary]; const NSTimeInterval kDelayTimeIntervalDefault = 0.1; NSNumber *delayTime = frameGIFProperties[(id)kCGImagePropertyGIFUnclampedDelayTime] ?: frameGIFProperties[(id)kCGImagePropertyGIFDelayTime]; diff --git a/Libraries/Image/RCTImageStoreManager.m b/Libraries/Image/RCTImageStoreManager.m index 65a2e63f2..46074cc37 100644 --- a/Libraries/Image/RCTImageStoreManager.m +++ b/Libraries/Image/RCTImageStoreManager.m @@ -14,7 +14,7 @@ @implementation RCTImageStoreManager { - NSMutableDictionary *_store; + NSMutableDictionary *_store; } @synthesize methodQueue = _methodQueue; diff --git a/Libraries/Image/RCTImageUtils.m b/Libraries/Image/RCTImageUtils.m index 9456bd273..2240a3219 100644 --- a/Libraries/Image/RCTImageUtils.m +++ b/Libraries/Image/RCTImageUtils.m @@ -237,7 +237,7 @@ RCT_EXTERN UIImage *RCTDecodeImageWithData(NSData *data, CGFloat maxPixelSize = fmax(fmin(sourceSize.width, targetPixelSize.width), fmin(sourceSize.height, targetPixelSize.height)); - NSDictionary *options = @{ + NSDictionary *options = @{ (id)kCGImageSourceShouldAllowFloat: @YES, (id)kCGImageSourceCreateThumbnailWithTransform: @YES, (id)kCGImageSourceCreateThumbnailFromImageAlways: @YES, diff --git a/Libraries/LinkingIOS/RCTLinkingManager.m b/Libraries/LinkingIOS/RCTLinkingManager.m index 37a2cc4d6..39fff4eb9 100644 --- a/Libraries/LinkingIOS/RCTLinkingManager.m +++ b/Libraries/LinkingIOS/RCTLinkingManager.m @@ -42,7 +42,7 @@ RCT_EXPORT_MODULE() sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { - NSDictionary *payload = @{@"url": URL.absoluteString}; + NSDictionary *payload = @{@"url": URL.absoluteString}; [[NSNotificationCenter defaultCenter] postNotificationName:RCTOpenURLNotification object:self userInfo:payload]; @@ -75,7 +75,7 @@ RCT_EXPORT_METHOD(canOpenURL:(NSURL *)URL callback(@[@(canOpen)]); } -- (NSDictionary *)constantsToExport +- (NSDictionary *)constantsToExport { NSURL *initialURL = _bridge.launchOptions[UIApplicationLaunchOptionsURLKey]; return @{@"initialURL": RCTNullIfNil(initialURL.absoluteString)}; diff --git a/Libraries/Network/RCTFileRequestHandler.m b/Libraries/Network/RCTFileRequestHandler.m index ad55ba0f4..162681ac4 100644 --- a/Libraries/Network/RCTFileRequestHandler.m +++ b/Libraries/Network/RCTFileRequestHandler.m @@ -48,7 +48,7 @@ RCT_EXPORT_MODULE() // Get content length NSError *error = nil; NSFileManager *fileManager = [NSFileManager new]; - NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:request.URL.path error:&error]; + NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:request.URL.path error:&error]; if (error) { [delegate URLRequest:weakOp didCompleteWithError:error]; return; diff --git a/Libraries/Network/RCTNetworking.m b/Libraries/Network/RCTNetworking.m index b1450a631..fe4f9a4dd 100644 --- a/Libraries/Network/RCTNetworking.m +++ b/Libraries/Network/RCTNetworking.m @@ -18,11 +18,11 @@ #import "RCTLog.h" #import "RCTUtils.h" -typedef RCTURLRequestCancellationBlock (^RCTHTTPQueryResult)(NSError *error, NSDictionary *result); +typedef RCTURLRequestCancellationBlock (^RCTHTTPQueryResult)(NSError *error, NSDictionary *result); @interface RCTNetworking () -- (RCTURLRequestCancellationBlock)processDataForHTTPQuery:(NSDictionary *)data +- (RCTURLRequestCancellationBlock)processDataForHTTPQuery:(NSDictionary *)data callback:(RCTHTTPQueryResult)callback; @end @@ -37,7 +37,7 @@ typedef RCTURLRequestCancellationBlock (^RCTHTTPQueryResult)(NSError *error, NSD @implementation RCTHTTPFormDataHelper { - NSMutableArray *_parts; + NSMutableArray *> *_parts; NSMutableData *_multipartBody; RCTHTTPQueryResult _callback; NSString *_boundary; @@ -68,12 +68,12 @@ static NSString *RCTGenerateFormBoundary() _multipartBody = [NSMutableData new]; _boundary = RCTGenerateFormBoundary(); - return [_networker processDataForHTTPQuery:_parts[0] callback:^(NSError *error, NSDictionary *result) { + return [_networker processDataForHTTPQuery:_parts[0] callback:^(NSError *error, NSDictionary *result) { return [self handleResult:result error:error]; }]; } -- (RCTURLRequestCancellationBlock)handleResult:(NSDictionary *)result +- (RCTURLRequestCancellationBlock)handleResult:(NSDictionary *)result error:(NSError *)error { if (error) { @@ -85,7 +85,7 @@ static NSString *RCTGenerateFormBoundary() dataUsingEncoding:NSUTF8StringEncoding]]; // Print headers. - NSMutableDictionary *headers = [_parts[0][@"headers"] mutableCopy]; + NSMutableDictionary *headers = [_parts[0][@"headers"] mutableCopy]; NSString *partContentType = result[@"contentType"]; if (partContentType != nil) { headers[@"content-type"] = partContentType; @@ -102,7 +102,7 @@ static NSString *RCTGenerateFormBoundary() [_parts removeObjectAtIndex:0]; if (_parts.count) { - return [_networker processDataForHTTPQuery:_parts[0] callback:^(NSError *err, NSDictionary *res) { + return [_networker processDataForHTTPQuery:_parts[0] callback:^(NSError *err, NSDictionary *res) { return [self handleResult:res error:err]; }]; } @@ -121,7 +121,7 @@ static NSString *RCTGenerateFormBoundary() */ @implementation RCTNetworking { - NSMutableDictionary *_tasksByRequestID; + NSMutableDictionary *_tasksByRequestID; NSArray> *_handlers; } @@ -191,7 +191,7 @@ RCT_EXPORT_MODULE() return nil; } -- (RCTURLRequestCancellationBlock)buildRequest:(NSDictionary *)query +- (RCTURLRequestCancellationBlock)buildRequest:(NSDictionary *)query completionBlock:(void (^)(NSURLRequest *request))block { NSURL *URL = [RCTConvert NSURL:query[@"url"]]; // this is marked as nullable in JS, but should not be null @@ -199,8 +199,8 @@ RCT_EXPORT_MODULE() request.HTTPMethod = [RCTConvert NSString:RCTNilIfNull(query[@"method"])].uppercaseString ?: @"GET"; request.allHTTPHeaderFields = [RCTConvert NSDictionary:query[@"headers"]]; - NSDictionary *data = [RCTConvert NSDictionary:RCTNilIfNull(query[@"data"])]; - return [self processDataForHTTPQuery:data callback:^(NSError *error, NSDictionary *result) { + NSDictionary *data = [RCTConvert NSDictionary:RCTNilIfNull(query[@"data"])]; + return [self processDataForHTTPQuery:data callback:^(NSError *error, NSDictionary *result) { if (error) { RCTLogError(@"Error processing request body: %@", error); // Ideally we'd circle back to JS here and notify an error/abort on the request. @@ -246,8 +246,8 @@ RCT_EXPORT_MODULE() * - @"contentType" (NSString): the content type header of the request * */ -- (RCTURLRequestCancellationBlock)processDataForHTTPQuery:(nullable NSDictionary *)query callback: -(RCTURLRequestCancellationBlock (^)(NSError *error, NSDictionary *result))callback +- (RCTURLRequestCancellationBlock)processDataForHTTPQuery:(nullable NSDictionary *)query callback: +(RCTURLRequestCancellationBlock (^)(NSError *error, NSDictionary *result))callback { if (!query) { return callback(nil, nil); @@ -322,7 +322,7 @@ RCT_EXPORT_MODULE() } } - NSArray *responseJSON = @[task.requestID, responseText ?: @""]; + NSArray *responseJSON = @[task.requestID, responseText ?: @""]; [_bridge.eventDispatcher sendDeviceEventWithName:@"didReceiveNetworkData" body:responseJSON]; } @@ -342,7 +342,7 @@ RCT_EXPORT_MODULE() void (^responseBlock)(NSURLResponse *) = ^(NSURLResponse *response) { dispatch_async(_methodQueue, ^{ - NSDictionary *headers; + NSDictionary *headers; NSInteger status; if ([response isKindOfClass:[NSHTTPURLResponse class]]) { // Might be a local file request NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; @@ -352,7 +352,7 @@ RCT_EXPORT_MODULE() headers = response.MIMEType ? @{@"Content-Type": response.MIMEType} : @{}; status = 200; } - NSArray *responseJSON = @[task.requestID, @(status), headers]; + NSArray *responseJSON = @[task.requestID, @(status), headers]; [_bridge.eventDispatcher sendDeviceEventWithName:@"didReceiveNetworkResponse" body:responseJSON]; }); diff --git a/Libraries/PushNotificationIOS/RCTPushNotificationManager.m b/Libraries/PushNotificationIOS/RCTPushNotificationManager.m index f38d00b7b..751e8ec34 100644 --- a/Libraries/PushNotificationIOS/RCTPushNotificationManager.m +++ b/Libraries/PushNotificationIOS/RCTPushNotificationManager.m @@ -31,7 +31,7 @@ NSString *const RCTRemoteNotificationsRegistered = @"RemoteNotificationsRegister + (UILocalNotification *)UILocalNotification:(id)json { - NSDictionary *details = [self NSDictionary:json]; + NSDictionary *details = [self NSDictionary:json]; UILocalNotification *notification = [UILocalNotification new]; notification.fireDate = [RCTConvert NSDate:details[@"fireDate"]] ?: [NSDate date]; notification.alertBody = [RCTConvert NSString:details[@"alertBody"]]; @@ -42,7 +42,7 @@ NSString *const RCTRemoteNotificationsRegistered = @"RemoteNotificationsRegister @implementation RCTPushNotificationManager { - NSDictionary *_initialNotification; + NSDictionary *_initialNotification; } RCT_EXPORT_MODULE() @@ -90,7 +90,7 @@ RCT_EXPORT_MODULE() for (NSUInteger i = 0; i < deviceTokenLength; i++) { [hexString appendFormat:@"%02x", bytes[i]]; } - NSDictionary *userInfo = @{ + NSDictionary *userInfo = @{ @"deviceToken" : [hexString copy] }; [[NSNotificationCenter defaultCenter] postNotificationName:RCTRemoteNotificationsRegistered @@ -174,7 +174,7 @@ RCT_EXPORT_METHOD(abandonPermissions) RCT_EXPORT_METHOD(checkPermissions:(RCTResponseSenderBlock)callback) { if (RCTRunningInAppExtension()) { - NSDictionary *permissions = @{@"alert": @(NO), @"badge": @(NO), @"sound": @(NO)}; + NSDictionary *permissions = @{@"alert": @NO, @"badge": @NO, @"sound": @NO}; callback(@[permissions]); return; } @@ -192,7 +192,7 @@ RCT_EXPORT_METHOD(checkPermissions:(RCTResponseSenderBlock)callback) } - NSMutableDictionary *permissions = [NSMutableDictionary new]; + NSMutableDictionary *permissions = [NSMutableDictionary new]; permissions[@"alert"] = @((types & UIUserNotificationTypeAlert) > 0); permissions[@"badge"] = @((types & UIUserNotificationTypeBadge) > 0); permissions[@"sound"] = @((types & UIUserNotificationTypeSound) > 0); @@ -200,7 +200,7 @@ RCT_EXPORT_METHOD(checkPermissions:(RCTResponseSenderBlock)callback) callback(@[permissions]); } -- (NSDictionary *)constantsToExport +- (NSDictionary *)constantsToExport { return @{ @"initialNotification": RCTNullIfNil(_initialNotification), diff --git a/Libraries/RCTTest/RCTTestModule.m b/Libraries/RCTTest/RCTTestModule.m index 3ad89b827..3976f146e 100644 --- a/Libraries/RCTTest/RCTTestModule.m +++ b/Libraries/RCTTest/RCTTestModule.m @@ -17,7 +17,7 @@ @implementation RCTTestModule { - NSMutableDictionary *_snapshotCounter; + NSMutableDictionary *_snapshotCounter; } @synthesize bridge = _bridge; @@ -41,7 +41,7 @@ RCT_EXPORT_METHOD(verifySnapshot:(RCTResponseSenderBlock)callback) { RCTAssert(_controller != nil, @"No snapshot controller configured."); - [_bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [_bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { NSString *testName = NSStringFromSelector(_testSelector); _snapshotCounter[testName] = (@([_snapshotCounter[testName] integerValue] + 1)).stringValue; @@ -77,7 +77,7 @@ RCT_EXPORT_METHOD(markTestCompleted) RCT_EXPORT_METHOD(markTestPassed:(BOOL)success) { - [_bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [_bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, __unused NSDictionary *viewRegistry) { _status = success ? RCTTestStatusPassed : RCTTestStatusFailed; }]; } diff --git a/Libraries/RCTTest/RCTTestRunner.h b/Libraries/RCTTest/RCTTestRunner.h index ce4a85f2f..aee9d412b 100644 --- a/Libraries/RCTTest/RCTTestRunner.h +++ b/Libraries/RCTTest/RCTTestRunner.h @@ -69,8 +69,9 @@ * @param initialProps props that are passed into the component when rendered. * @param configurationBlock A block that takes the hosting root view and performs arbitrary manipulation after its creation. */ - -- (void)runTest:(SEL)test module:(NSString *)moduleName initialProps:(NSDictionary *)initialProps configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock; +- (void)runTest:(SEL)test module:(NSString *)moduleName + initialProps:(NSDictionary *)initialProps +configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock; /** * Same as runTest:, but allows for passing initialProps for providing mock data @@ -83,7 +84,10 @@ * @param configurationBlock A block that takes the hosting root view and performs arbitrary manipulation after its creation. * @param expectErrorRegex A regex that must match the error thrown. If no error is thrown, the test fails. */ -- (void)runTest:(SEL)test module:(NSString *)moduleName initialProps:(NSDictionary *)initialProps configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock expectErrorRegex:(NSString *)expectErrorRegex; +- (void)runTest:(SEL)test module:(NSString *)moduleName + initialProps:(NSDictionary *)initialProps +configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock +expectErrorRegex:(NSString *)expectErrorRegex; /** * Same as runTest:, but allows for passing initialProps for providing mock data @@ -97,6 +101,9 @@ * @param configurationBlock A block that takes the hosting root view and performs arbitrary manipulation after its creation. * @param expectErrorBlock A block that takes the error message and returns NO to fail the test. */ -- (void)runTest:(SEL)test module:(NSString *)moduleName initialProps:(NSDictionary *)initialProps configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock; +- (void)runTest:(SEL)test module:(NSString *)moduleName + initialProps:(NSDictionary *)initialProps +configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock +expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock; @end diff --git a/Libraries/RCTTest/RCTTestRunner.m b/Libraries/RCTTest/RCTTestRunner.m index 16e911811..573c7e0a2 100644 --- a/Libraries/RCTTest/RCTTestRunner.m +++ b/Libraries/RCTTest/RCTTestRunner.m @@ -71,12 +71,17 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) [self runTest:test module:moduleName initialProps:nil configurationBlock:nil expectErrorBlock:nil]; } -- (void)runTest:(SEL)test module:(NSString *)moduleName initialProps:(NSDictionary *)initialProps configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock +- (void)runTest:(SEL)test module:(NSString *)moduleName + initialProps:(NSDictionary *)initialProps +configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock { [self runTest:test module:moduleName initialProps:initialProps configurationBlock:configurationBlock expectErrorBlock:nil]; } -- (void)runTest:(SEL)test module:(NSString *)moduleName initialProps:(NSDictionary *)initialProps configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock expectErrorRegex:(NSString *)errorRegex +- (void)runTest:(SEL)test module:(NSString *)moduleName + initialProps:(NSDictionary *)initialProps +configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock +expectErrorRegex:(NSString *)errorRegex { BOOL(^expectErrorBlock)(NSString *error) = ^BOOL(NSString *error){ return [error rangeOfString:errorRegex options:NSRegularExpressionSearch].location != NSNotFound; @@ -85,7 +90,10 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) [self runTest:test module:moduleName initialProps:initialProps configurationBlock:configurationBlock expectErrorBlock:expectErrorBlock]; } -- (void)runTest:(SEL)test module:(NSString *)moduleName initialProps:(NSDictionary *)initialProps configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock +- (void)runTest:(SEL)test module:(NSString *)moduleName + initialProps:(NSDictionary *)initialProps +configurationBlock:(void(^)(RCTRootView *rootView))configurationBlock +expectErrorBlock:(BOOL(^)(NSString *error))expectErrorBlock { __weak id weakJSContext; diff --git a/Libraries/Settings/RCTSettingsManager.m b/Libraries/Settings/RCTSettingsManager.m index 6f8b146c1..3e812e246 100644 --- a/Libraries/Settings/RCTSettingsManager.m +++ b/Libraries/Settings/RCTSettingsManager.m @@ -59,7 +59,7 @@ RCT_EXPORT_MODULE() body:RCTJSONClean([_defaults dictionaryRepresentation])]; } -- (NSDictionary *)constantsToExport +- (NSDictionary *)constantsToExport { return @{ @"settings": RCTJSONClean([_defaults dictionaryRepresentation]) diff --git a/Libraries/Text/RCTShadowText.m b/Libraries/Text/RCTShadowText.m index d6d6298ae..a8087b1da 100644 --- a/Libraries/Text/RCTShadowText.m +++ b/Libraries/Text/RCTShadowText.m @@ -16,7 +16,6 @@ #import "RCTImageComponent.h" #import "RCTLog.h" #import "RCTShadowRawText.h" -#import "RCTSparseArray.h" #import "RCTText.h" #import "RCTUtils.h" @@ -81,17 +80,17 @@ static css_dim_t RCTMeasure(void *context, float width) [self dirtyText]; } -- (NSDictionary *)processUpdatedProperties:(NSMutableSet *)applierBlocks - parentProperties:(NSDictionary *)parentProperties +- (NSDictionary *)processUpdatedProperties:(NSMutableSet *)applierBlocks + parentProperties:(NSDictionary *)parentProperties { parentProperties = [super processUpdatedProperties:applierBlocks parentProperties:parentProperties]; UIEdgeInsets padding = self.paddingAsInsets; CGFloat width = self.frame.size.width - (padding.left + padding.right); - + NSTextStorage *textStorage = [self buildTextStorageForWidth:width]; - [applierBlocks addObject:^(RCTSparseArray *viewRegistry) { + [applierBlocks addObject:^(NSDictionary *viewRegistry) { RCTText *view = viewRegistry[self.reactTag]; view.textStorage = textStorage; }]; diff --git a/Libraries/Text/RCTTextFieldManager.m b/Libraries/Text/RCTTextFieldManager.m index a278459fe..f2ccf07f4 100644 --- a/Libraries/Text/RCTTextFieldManager.m +++ b/Libraries/Text/RCTTextFieldManager.m @@ -11,7 +11,6 @@ #import "RCTBridge.h" #import "RCTShadowView.h" -#import "RCTSparseArray.h" #import "RCTTextField.h" @interface RCTTextFieldManager() @@ -117,8 +116,8 @@ RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger) { NSNumber *reactTag = shadowView.reactTag; UIEdgeInsets padding = shadowView.paddingAsInsets; - return ^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { - ((RCTTextField *)viewRegistry[reactTag]).contentInset = padding; + return ^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { + viewRegistry[reactTag].contentInset = padding; }; } diff --git a/Libraries/Text/RCTTextManager.m b/Libraries/Text/RCTTextManager.m index be63428fc..5496b3b80 100644 --- a/Libraries/Text/RCTTextManager.m +++ b/Libraries/Text/RCTTextManager.m @@ -15,7 +15,6 @@ #import "RCTLog.h" #import "RCTShadowRawText.h" #import "RCTShadowText.h" -#import "RCTSparseArray.h" #import "RCTText.h" #import "RCTTextView.h" #import "UIView+React.h" @@ -61,10 +60,10 @@ RCT_EXPORT_SHADOW_PROPERTY(writingDirection, NSWritingDirection) RCT_EXPORT_SHADOW_PROPERTY(allowFontScaling, BOOL) RCT_EXPORT_SHADOW_PROPERTY(opacity, CGFloat) -- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(RCTSparseArray *)shadowViewRegistry +- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary *)shadowViewRegistry { NSMutableSet *textViewTagsToUpdate = [NSMutableSet new]; - for (RCTShadowView *rootView in shadowViewRegistry.allObjects) { + for (RCTShadowView *rootView in shadowViewRegistry.allValues) { if (![rootView isReactRootView]) { // This isn't a root view continue; @@ -135,7 +134,7 @@ RCT_EXPORT_SHADOW_PROPERTY(opacity, CGFloat) CGFloat width = shadowText.frame.size.width - (padding.left + padding.right); NSTextStorage *textStorage = [shadowText buildTextStorageForWidth:width]; - [uiBlocks addObject:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [uiBlocks addObject:^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { RCTTextView *textView = viewRegistry[reactTag]; RCTText *text; for (RCTText *subview in textView.reactSubviews) { @@ -150,7 +149,7 @@ RCT_EXPORT_SHADOW_PROPERTY(opacity, CGFloat) }]; } - return ^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + return ^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { for (RCTViewManagerUIBlock uiBlock in uiBlocks) { uiBlock(uiManager, viewRegistry); } @@ -165,7 +164,7 @@ RCT_EXPORT_SHADOW_PROPERTY(opacity, CGFloat) NSNumber *reactTag = shadowView.reactTag; UIEdgeInsets padding = shadowView.paddingAsInsets; - return ^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + return ^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { RCTText *text = viewRegistry[reactTag]; text.contentInset = padding; }; diff --git a/Libraries/Text/RCTTextView.m b/Libraries/Text/RCTTextView.m index 8f8b3d724..2af31f39a 100644 --- a/Libraries/Text/RCTTextView.m +++ b/Libraries/Text/RCTTextView.m @@ -41,7 +41,7 @@ NSInteger _nativeEventCount; RCTText *_richTextView; NSAttributedString *_pendingAttributedText; - NSMutableArray *> *_subviews; + NSMutableArray *_subviews; BOOL _blockTextShouldChange; UITextRange *_previousSelectionRange; } @@ -71,12 +71,12 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithFrame:(CGRect)frame) RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) -- (NSArray *> *)reactSubviews +- (NSArray *)reactSubviews { return _subviews; } -- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)index +- (void)insertReactSubview:(UIView *)subview atIndex:(NSInteger)index { if ([subview isKindOfClass:[RCTText class]]) { if (_richTextView) { @@ -90,7 +90,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) } } -- (void)removeReactSubview:(UIView *)subview +- (void)removeReactSubview:(UIView *)subview { if (_richTextView == subview) { [_subviews removeObject:_richTextView]; diff --git a/Libraries/Text/RCTTextViewManager.m b/Libraries/Text/RCTTextViewManager.m index c9e33cd19..c5c04ee7f 100644 --- a/Libraries/Text/RCTTextViewManager.m +++ b/Libraries/Text/RCTTextViewManager.m @@ -12,7 +12,6 @@ #import "RCTBridge.h" #import "RCTConvert.h" #import "RCTShadowView.h" -#import "RCTSparseArray.h" #import "RCTTextView.h" @implementation RCTTextViewManager @@ -61,8 +60,8 @@ RCT_EXPORT_VIEW_PROPERTY(mostRecentEventCount, NSInteger) { NSNumber *reactTag = shadowView.reactTag; UIEdgeInsets padding = shadowView.paddingAsInsets; - return ^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { - ((RCTTextView *)viewRegistry[reactTag]).contentInset = padding; + return ^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { + viewRegistry[reactTag].contentInset = padding; }; } diff --git a/Libraries/WebSocket/RCTSRWebSocket.m b/Libraries/WebSocket/RCTSRWebSocket.m index a345f373a..5f46bfd75 100644 --- a/Libraries/WebSocket/RCTSRWebSocket.m +++ b/Libraries/WebSocket/RCTSRWebSocket.m @@ -506,7 +506,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) if (_secure) { - NSMutableDictionary *SSLOptions = [NSMutableDictionary new]; + NSMutableDictionary *SSLOptions = [NSMutableDictionary new]; [_outputStream setProperty:(__bridge id)kCFStreamSocketSecurityLevelNegotiatedSSL forKey:(__bridge id)kCFStreamPropertySocketSecurityLevel]; diff --git a/Libraries/WebSocket/RCTWebSocketExecutor.m b/Libraries/WebSocket/RCTWebSocketExecutor.m index 28333d2db..41ac0baf2 100644 --- a/Libraries/WebSocket/RCTWebSocketExecutor.m +++ b/Libraries/WebSocket/RCTWebSocketExecutor.m @@ -15,11 +15,10 @@ #import "RCTConvert.h" #import "RCTLog.h" -#import "RCTSparseArray.h" #import "RCTUtils.h" #import "RCTSRWebSocket.h" -typedef void (^RCTWSMessageCallback)(NSError *error, NSDictionary *reply); +typedef void (^RCTWSMessageCallback)(NSError *error, NSDictionary *reply); @interface RCTWebSocketExecutor () @@ -29,9 +28,9 @@ typedef void (^RCTWSMessageCallback)(NSError *error, NSDictionary *reply); { RCTSRWebSocket *_socket; dispatch_queue_t _jsQueue; - RCTSparseArray *_callbacks; + NSMutableDictionary *_callbacks; dispatch_semaphore_t _socketOpenSemaphore; - NSMutableDictionary *_injectedObjects; + NSMutableDictionary *_injectedObjects; NSURL *_url; } @@ -60,7 +59,7 @@ RCT_EXPORT_MODULE() _jsQueue = dispatch_queue_create("com.facebook.React.WebSocketExecutor", DISPATCH_QUEUE_SERIAL); _socket = [[RCTSRWebSocket alloc] initWithURL:_url]; _socket.delegate = self; - _callbacks = [RCTSparseArray new]; + _callbacks = [NSMutableDictionary new]; _injectedObjects = [NSMutableDictionary new]; [_socket setDelegateDispatchQueue:_jsQueue]; @@ -101,7 +100,7 @@ RCT_EXPORT_MODULE() { __block NSError *initError; dispatch_semaphore_t s = dispatch_semaphore_create(0); - [self sendMessage:@{@"method": @"prepareJSRuntime"} waitForReply:^(NSError *error, NSDictionary *reply) { + [self sendMessage:@{@"method": @"prepareJSRuntime"} waitForReply:^(NSError *error, NSDictionary *reply) { initError = error; dispatch_semaphore_signal(s); }]; @@ -112,7 +111,7 @@ RCT_EXPORT_MODULE() - (void)webSocket:(RCTSRWebSocket *)webSocket didReceiveMessage:(id)message { NSError *error = nil; - NSDictionary *reply = RCTJSONParse(message, &error); + NSDictionary *reply = RCTJSONParse(message, &error); NSNumber *messageID = reply[@"replyID"]; RCTWSMessageCallback callback = _callbacks[messageID]; if (callback) { @@ -130,7 +129,7 @@ RCT_EXPORT_MODULE() RCTLogError(@"WebSocket connection failed with error %@", error); } -- (void)sendMessage:(NSDictionary *)message waitForReply:(RCTWSMessageCallback)callback +- (void)sendMessage:(NSDictionary *)message waitForReply:(RCTWSMessageCallback)callback { static NSUInteger lastID = 10000; @@ -145,7 +144,7 @@ RCT_EXPORT_MODULE() NSNumber *expectedID = @(lastID++); _callbacks[expectedID] = [callback copy]; - NSMutableDictionary *messageWithID = [message mutableCopy]; + NSMutableDictionary *messageWithID = [message mutableCopy]; messageWithID[@"id"] = expectedID; [_socket send:RCTJSONStringify(messageWithID, NULL)]; }); @@ -153,12 +152,12 @@ RCT_EXPORT_MODULE() - (void)executeApplicationScript:(NSData *)script sourceURL:(NSURL *)URL onComplete:(RCTJavaScriptCompleteBlock)onComplete { - NSDictionary *message = @{ + NSDictionary *message = @{ @"method": @"executeApplicationScript", @"url": RCTNullIfNil(URL.absoluteString), @"inject": _injectedObjects, }; - [self sendMessage:message waitForReply:^(NSError *error, NSDictionary *reply) { + [self sendMessage:message waitForReply:^(NSError *error, NSDictionary *reply) { onComplete(error); }]; } @@ -166,13 +165,13 @@ RCT_EXPORT_MODULE() - (void)executeJSCall:(NSString *)name method:(NSString *)method arguments:(NSArray *)arguments callback:(RCTJavaScriptCallback)onComplete { RCTAssert(onComplete != nil, @"callback was missing for exec JS call"); - NSDictionary *message = @{ + NSDictionary *message = @{ @"method": @"executeJSCall", @"moduleName": name, @"moduleMethod": method, @"arguments": arguments }; - [self sendMessage:message waitForReply:^(NSError *socketError, NSDictionary *reply) { + [self sendMessage:message waitForReply:^(NSError *socketError, NSDictionary *reply) { if (socketError) { onComplete(nil, socketError); return; diff --git a/Libraries/WebSocket/RCTWebSocketModule.m b/Libraries/WebSocket/RCTWebSocketModule.m index 24066439f..df706f0d6 100644 --- a/Libraries/WebSocket/RCTWebSocketModule.m +++ b/Libraries/WebSocket/RCTWebSocketModule.m @@ -12,7 +12,6 @@ #import "RCTBridge.h" #import "RCTEventDispatcher.h" #import "RCTSRWebSocket.h" -#import "RCTSparseArray.h" #import "RCTUtils.h" @implementation RCTSRWebSocket (React) @@ -35,7 +34,7 @@ @implementation RCTWebSocketModule { - RCTSparseArray *_sockets; + NSMutableDictionary *_sockets; } RCT_EXPORT_MODULE() @@ -45,14 +44,14 @@ RCT_EXPORT_MODULE() - (instancetype)init { if ((self = [super init])) { - _sockets = [RCTSparseArray new]; + _sockets = [NSMutableDictionary new]; } return self; } - (void)dealloc { - for (RCTSRWebSocket *socket in _sockets.allObjects) { + for (RCTSRWebSocket *socket in _sockets.allValues) { socket.delegate = nil; [socket close]; } @@ -75,7 +74,7 @@ RCT_EXPORT_METHOD(send:(NSString *)message socketID:(nonnull NSNumber *)socketID RCT_EXPORT_METHOD(close:(nonnull NSNumber *)socketID) { [_sockets[socketID] close]; - _sockets[socketID] = nil; + [_sockets removeObjectForKey:socketID]; } #pragma mark - RCTSRWebSocketDelegate methods diff --git a/React/Base/RCTAssert.h b/React/Base/RCTAssert.h index ce47adc3e..94667502e 100644 --- a/React/Base/RCTAssert.h +++ b/React/Base/RCTAssert.h @@ -115,7 +115,7 @@ RCT_EXTERN NSString *RCTCurrentThreadName(void); /** * Helper to get generate exception message from NSError */ -RCT_EXTERN NSString *RCTFormatError(NSString *message, NSArray *stacktrace, NSUInteger maxMessageLength); +RCT_EXTERN NSString *RCTFormatError(NSString *message, NSArray *> *stacktrace, NSUInteger maxMessageLength); /** * Convenience macro to assert which thread is currently running (DEBUG mode only) diff --git a/React/Base/RCTAssert.m b/React/Base/RCTAssert.m index 8923f40a5..03e40c930 100644 --- a/React/Base/RCTAssert.m +++ b/React/Base/RCTAssert.m @@ -146,7 +146,7 @@ RCTFatalHandler RCTGetFatalHandler(void) return RCTCurrentFatalHandler; } -NSString *RCTFormatError(NSString *message, NSArray *stackTrace, NSUInteger maxMessageLength) +NSString *RCTFormatError(NSString *message, NSArray *> *stackTrace, NSUInteger maxMessageLength) { if (maxMessageLength > 0 && message.length > maxMessageLength) { message = [[message substringToIndex:maxMessageLength] stringByAppendingString:@"..."]; @@ -155,7 +155,7 @@ NSString *RCTFormatError(NSString *message, NSArray *stackTrace, NSUInteger maxM NSMutableString *prettyStack = [NSMutableString string]; if (stackTrace) { [prettyStack appendString:@", stack:\n"]; - for (NSDictionary *frame in stackTrace) { + for (NSDictionary *frame in stackTrace) { [prettyStack appendFormat:@"%@@%@:%@\n", frame[@"methodName"], frame[@"lineNumber"], frame[@"column"]]; } } diff --git a/React/Base/RCTBatchedBridge.m b/React/Base/RCTBatchedBridge.m index 2bd87c2bd..d4bf5b30e 100644 --- a/React/Base/RCTBatchedBridge.m +++ b/React/Base/RCTBatchedBridge.m @@ -22,7 +22,6 @@ #import "RCTPerformanceLogger.h" #import "RCTProfile.h" #import "RCTSourceCode.h" -#import "RCTSparseArray.h" #import "RCTUtils.h" #define RCTAssertJSThread() \ @@ -730,7 +729,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR dispatch_block_t block = ^{ RCTProfileEndFlowEvent(); - + #if RCT_DEV NSString *_threadName = RCTCurrentThreadName(); RCT_PROFILE_BEGIN_EVENT(0, _threadName, nil); diff --git a/React/Base/RCTBridgeModule.h b/React/Base/RCTBridgeModule.h index 07c6932b5..ee51f5d5b 100644 --- a/React/Base/RCTBridgeModule.h +++ b/React/Base/RCTBridgeModule.h @@ -228,7 +228,7 @@ RCT_EXTERN void RCTRegisterModule(Class); \ * for long-lived values such as session keys, that are regenerated only as * part of a reload of the entire React application. */ -- (NSDictionary *)constantsToExport; +- (NSDictionary *)constantsToExport; /** * Notifies the module that a batch of JS method invocations has just completed. diff --git a/React/Base/RCTLog.m b/React/Base/RCTLog.m index 02bc9b660..86392db1f 100644 --- a/React/Base/RCTLog.m +++ b/React/Base/RCTLog.m @@ -53,7 +53,7 @@ void RCTSetLogThreshold(RCTLogLevel threshold) { RCTLogFunction RCTDefaultLogFunction = ^( RCTLogLevel level, - RCTLogSource source, + __unused RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message diff --git a/React/Base/RCTSparseArray.h b/React/Base/RCTSparseArray.h deleted file mode 100644 index 78410d72d..000000000 --- a/React/Base/RCTSparseArray.h +++ /dev/null @@ -1,38 +0,0 @@ -/** - * 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. - */ - -#import - -@interface RCTSparseArray : NSObject - -- (instancetype)initWithCapacity:(NSUInteger)capacity NS_DESIGNATED_INITIALIZER; -- (instancetype)initWithSparseArray:(RCTSparseArray *)sparseArray NS_DESIGNATED_INITIALIZER; - -+ (instancetype)sparseArray; -+ (instancetype)sparseArrayWithCapacity:(NSUInteger)capacity; -+ (instancetype)sparseArrayWithSparseArray:(RCTSparseArray *)sparseArray; - -// Use nil object to remove at idx. -- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx; -- (id)objectAtIndexedSubscript:(NSUInteger)idx; - -// Use nil obj to remove at key. -- (void)setObject:(id)obj forKeyedSubscript:(NSNumber *)key; -- (id)objectForKeyedSubscript:(NSNumber *)key; - -@property (readonly, nonatomic) NSUInteger count; -@property (readonly, nonatomic, copy) NSArray *allIndexes; -@property (readonly, nonatomic, copy) NSArray *allObjects; - -- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSNumber *idx, BOOL *stop))block; -- (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(id obj, NSNumber *idx, BOOL *stop))block; - -- (void)removeAllObjects; - -@end diff --git a/React/Base/RCTSparseArray.m b/React/Base/RCTSparseArray.m deleted file mode 100644 index 76e01d677..000000000 --- a/React/Base/RCTSparseArray.m +++ /dev/null @@ -1,123 +0,0 @@ -/** - * 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. - */ - -#import "RCTSparseArray.h" - -@implementation RCTSparseArray -{ - NSMutableDictionary *_storage; -} - -- (instancetype)init -{ - return [self initWithCapacity:0]; -} - -- (instancetype)initWithCapacity:(NSUInteger)capacity -{ - if ((self = [super init])) { - _storage = [NSMutableDictionary dictionaryWithCapacity:capacity]; - } - return self; -} - -- (instancetype)initWithSparseArray:(RCTSparseArray *)sparseArray -{ - if ((self = [super init])) { - _storage = [sparseArray->_storage copy]; - } - return self; -} - -+ (instancetype)sparseArray -{ - return [self new]; -} - -+ (instancetype)sparseArrayWithCapacity:(NSUInteger)capacity -{ - return [[self alloc] initWithCapacity:capacity]; -} - -+ (instancetype)sparseArrayWithSparseArray:(RCTSparseArray *)sparseArray -{ - return [[self alloc] initWithSparseArray:sparseArray]; -} - -- (id)objectAtIndexedSubscript:(NSUInteger)idx -{ - return _storage[@(idx)]; -} - -- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx -{ - self[@(idx)] = obj; -} - -- (id)objectForKeyedSubscript:(NSNumber *)key -{ - return _storage[key]; -} - -- (void)setObject:(id)obj forKeyedSubscript:(NSNumber *)key -{ - if (obj) { - _storage[key] = obj; - } else { - [_storage removeObjectForKey:key]; - } -} - -- (NSUInteger)count -{ - return _storage.count; -} - -- (NSArray *)allIndexes -{ - return _storage.allKeys; -} - -- (NSArray *)allObjects -{ - return _storage.allValues; -} - -- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSNumber *idx, BOOL *stop))block -{ - NSParameterAssert(block != nil); - [_storage enumerateKeysAndObjectsUsingBlock:^(NSNumber *key, id obj, BOOL *stop) { - block(obj, key, stop); - }]; -} - -- (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(id obj, NSNumber *idx, BOOL *stop))block -{ - NSParameterAssert(block != nil); - [_storage enumerateKeysAndObjectsWithOptions:opts usingBlock:^(NSNumber *key, id obj, BOOL *stop) { - block(obj, key, stop); - }]; -} - -- (void)removeAllObjects -{ - [_storage removeAllObjects]; -} - -- (id)copyWithZone:(NSZone *)zone -{ - return [[[self class] allocWithZone:zone] initWithSparseArray:self]; -} - -- (NSString *)description -{ - return [super.description stringByAppendingString:_storage.description]; -} - -@end diff --git a/React/Base/RCTUtils.h b/React/Base/RCTUtils.h index 02e37c8b9..6d399594e 100644 --- a/React/Base/RCTUtils.h +++ b/React/Base/RCTUtils.h @@ -45,9 +45,9 @@ RCT_EXTERN BOOL RCTClassOverridesClassMethod(Class cls, SEL selector); RCT_EXTERN BOOL RCTClassOverridesInstanceMethod(Class cls, SEL selector); // Creates a standardized error object -RCT_EXTERN NSDictionary *RCTMakeError(NSString *message, id toStringify, NSDictionary *extraData); -RCT_EXTERN NSDictionary *RCTMakeAndLogError(NSString *message, id toStringify, NSDictionary *extraData); -RCT_EXTERN NSDictionary *RCTJSErrorFromNSError(NSError *error); +RCT_EXTERN NSDictionary *RCTMakeError(NSString *message, id toStringify, NSDictionary *extraData); +RCT_EXTERN NSDictionary *RCTMakeAndLogError(NSString *message, id toStringify, NSDictionary *extraData); +RCT_EXTERN NSDictionary *RCTJSErrorFromNSError(NSError *error); // Returns YES if React is running in a test environment RCT_EXTERN BOOL RCTRunningInTestEnvironment(void); diff --git a/React/Base/RCTUtils.m b/React/Base/RCTUtils.m index 732240aec..036ecc2bd 100644 --- a/React/Base/RCTUtils.m +++ b/React/Base/RCTUtils.m @@ -137,7 +137,7 @@ id RCTJSONClean(id object) if ([object isKindOfClass:[NSDictionary class]]) { __block BOOL copy = NO; - NSMutableDictionary *values = [[NSMutableDictionary alloc] initWithCapacity:[object count]]; + NSMutableDictionary *values = [[NSMutableDictionary alloc] initWithCapacity:[object count]]; [object enumerateKeysAndObjectsUsingBlock:^(NSString *key, id item, __unused BOOL *stop) { id value = RCTJSONClean(item); values[key] = value; @@ -288,30 +288,30 @@ BOOL RCTClassOverridesInstanceMethod(Class cls, SEL selector) return NO; } -NSDictionary *RCTMakeError(NSString *message, id toStringify, NSDictionary *extraData) +NSDictionary *RCTMakeError(NSString *message, id toStringify, NSDictionary *extraData) { if (toStringify) { message = [message stringByAppendingString:[toStringify description]]; } - NSMutableDictionary *error = [NSMutableDictionary dictionaryWithDictionary:extraData]; + NSMutableDictionary *error = [NSMutableDictionary dictionaryWithDictionary:extraData]; error[@"message"] = message; return error; } -NSDictionary *RCTMakeAndLogError(NSString *message, id toStringify, NSDictionary *extraData) +NSDictionary *RCTMakeAndLogError(NSString *message, id toStringify, NSDictionary *extraData) { - NSDictionary *error = RCTMakeError(message, toStringify, extraData); + NSDictionary *error = RCTMakeError(message, toStringify, extraData); RCTLogError(@"\nError: %@", error); return error; } // TODO: Can we just replace RCTMakeError with this function instead? -NSDictionary *RCTJSErrorFromNSError(NSError *error) +NSDictionary *RCTJSErrorFromNSError(NSError *error) { NSString *errorMessage; NSArray *stackTrace = [NSThread callStackSymbols]; - NSMutableDictionary *errorInfo = + NSMutableDictionary *errorInfo = [NSMutableDictionary dictionaryWithObject:stackTrace forKey:@"nativeStackIOS"]; if (error) { @@ -399,7 +399,7 @@ BOOL RCTImageHasAlpha(CGImageRef image) NSError *RCTErrorWithMessage(NSString *message) { - NSDictionary *errorInfo = @{NSLocalizedDescriptionKey: message}; + NSDictionary *errorInfo = @{NSLocalizedDescriptionKey: message}; return [[NSError alloc] initWithDomain:RCTErrorDomain code:0 userInfo:errorInfo]; } diff --git a/React/Modules/RCTAccessibilityManager.h b/React/Modules/RCTAccessibilityManager.h index ded98bcbd..8e14ccd88 100644 --- a/React/Modules/RCTAccessibilityManager.h +++ b/React/Modules/RCTAccessibilityManager.h @@ -19,7 +19,7 @@ extern NSString *const RCTAccessibilityManagerDidUpdateMultiplierNotification; / @property (nonatomic, readonly) CGFloat multiplier; /// map from UIKit categories to multipliers -@property (nonatomic, copy) NSDictionary *multipliers; +@property (nonatomic, copy) NSDictionary *multipliers; @property (nonatomic, assign) BOOL isVoiceOverEnabled; diff --git a/React/Modules/RCTAccessibilityManager.m b/React/Modules/RCTAccessibilityManager.m index f7bfe8feb..eb4d31954 100644 --- a/React/Modules/RCTAccessibilityManager.m +++ b/React/Modules/RCTAccessibilityManager.m @@ -10,6 +10,7 @@ #import "RCTAccessibilityManager.h" #import "RCTBridge.h" +#import "RCTConvert.h" #import "RCTEventDispatcher.h" #import "RCTLog.h" @@ -29,7 +30,7 @@ NSString *const RCTAccessibilityManagerDidUpdateMultiplierNotification = @"RCTAc RCT_EXPORT_MODULE() -+ (NSDictionary *)JSToUIKitMap ++ (NSDictionary *)JSToUIKitMap { static NSDictionary *map = nil; static dispatch_once_t onceToken; @@ -52,13 +53,12 @@ RCT_EXPORT_MODULE() + (NSString *)UIKitCategoryFromJSCategory:(NSString *)JSCategory { - return self.JSToUIKitMap[JSCategory]; + return [self JSToUIKitMap][JSCategory]; } - (instancetype)init { - self = [super init]; - if (self) { + if ((self = [super init])) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveNewContentSizeCategory:) name:UIContentSizeCategoryDidChangeNotification @@ -119,7 +119,7 @@ RCT_EXPORT_MODULE() return m.doubleValue; } -- (void)setMultipliers:(NSDictionary *)multipliers +- (void)setMultipliers:(NSDictionary *)multipliers { if (_multipliers != multipliers) { _multipliers = [multipliers copy]; @@ -127,7 +127,7 @@ RCT_EXPORT_MODULE() } } -- (NSDictionary *)multipliers +- (NSDictionary *)multipliers { if (_multipliers == nil) { _multipliers = @{UIContentSizeCategoryExtraSmall: @0.823, @@ -148,10 +148,10 @@ RCT_EXPORT_MODULE() RCT_EXPORT_METHOD(setAccessibilityContentSizeMultipliers:(NSDictionary *)JSMultipliers) { - NSMutableDictionary *multipliers = [NSMutableDictionary new]; + NSMutableDictionary *multipliers = [NSMutableDictionary new]; for (NSString *__nonnull JSCategory in JSMultipliers) { - NSNumber *m = JSMultipliers[JSCategory]; - NSString *UIKitCategory = [self.class UIKitCategoryFromJSCategory:JSCategory]; + NSNumber *m = [RCTConvert NSNumber:JSMultipliers[JSCategory]]; + NSString *UIKitCategory = [[self class] UIKitCategoryFromJSCategory:JSCategory]; multipliers[UIKitCategory] = m; } self.multipliers = multipliers; diff --git a/React/Modules/RCTSourceCode.m b/React/Modules/RCTSourceCode.m index ae3e22f72..281a304f9 100644 --- a/React/Modules/RCTSourceCode.m +++ b/React/Modules/RCTSourceCode.m @@ -36,7 +36,7 @@ RCT_EXPORT_METHOD(getScriptText:(RCTResponseSenderBlock)successCallback } } -- (NSDictionary *)constantsToExport +- (NSDictionary *)constantsToExport { NSString *URL = self.bridge.bundleURL.absoluteString ?: @""; return @{@"scriptURL": URL}; diff --git a/React/Modules/RCTTiming.m b/React/Modules/RCTTiming.m index 41d90d41a..fc2d9e716 100644 --- a/React/Modules/RCTTiming.m +++ b/React/Modules/RCTTiming.m @@ -12,7 +12,6 @@ #import "RCTAssert.h" #import "RCTBridge.h" #import "RCTLog.h" -#import "RCTSparseArray.h" #import "RCTUtils.h" @interface RCTBridge (Private) @@ -66,7 +65,7 @@ @implementation RCTTiming { - RCTSparseArray *_timers; + NSMutableDictionary *_timers; } @synthesize bridge = _bridge; @@ -79,7 +78,7 @@ RCT_EXPORT_MODULE() { if ((self = [super init])) { _paused = YES; - _timers = [RCTSparseArray new]; + _timers = [NSMutableDictionary new]; for (NSString *name in @[UIApplicationWillResignActiveNotification, UIApplicationDidEnterBackgroundNotification, @@ -146,12 +145,12 @@ RCT_EXPORT_MODULE() - (void)didUpdateFrame:(__unused RCTFrameUpdate *)update { NSMutableArray *timersToCall = [NSMutableArray new]; - for (RCTTimer *timer in _timers.allObjects) { + for (RCTTimer *timer in _timers.allValues) { if ([timer updateFoundNeedsJSUpdate]) { [timersToCall addObject:timer.callbackID]; } if (!timer.target) { - _timers[timer.callbackID] = nil; + [_timers removeObjectForKey:timer.callbackID]; } } @@ -208,7 +207,7 @@ RCT_EXPORT_METHOD(createTimer:(nonnull NSNumber *)callbackID RCT_EXPORT_METHOD(deleteTimer:(nonnull NSNumber *)timerID) { - _timers[timerID] = nil; + [_timers removeObjectForKey:timerID]; if (_timers.count == 0) { [self stopTimers]; } diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index b4f3da165..78767a95b 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -27,7 +27,6 @@ #import "RCTRootViewInternal.h" #import "RCTScrollableProtocol.h" #import "RCTShadowView.h" -#import "RCTSparseArray.h" #import "RCTUtils.h" #import "RCTView.h" #import "RCTViewManager.h" @@ -183,9 +182,8 @@ static UIViewAnimationOptions UIViewAnimationOptionsFromRCTAnimationType(RCTAnim @interface RCTUIManager () // NOTE: these are properties so that they can be accessed by unit tests -@property (nonatomic, strong) RCTSparseArray *viewManagerRegistry; // RCT thread only -@property (nonatomic, strong) RCTSparseArray *shadowViewRegistry; // RCT thread only -@property (nonatomic, strong) RCTSparseArray *viewRegistry; // Main thread only +@property (nonatomic, strong) NSMutableDictionary *shadowViewRegistry; // RCT thread only +@property (nonatomic, strong) NSMutableDictionary *viewRegistry; // Main thread only @end @@ -229,8 +227,8 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); dispatch_set_target_queue(_shadowQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)); } - _shadowViewRegistry = [RCTSparseArray new]; - _viewRegistry = [RCTSparseArray new]; + _shadowViewRegistry = [NSMutableDictionary new]; + _viewRegistry = [NSMutableDictionary new]; // Internal resources _pendingUIBlocks = [NSMutableArray new]; @@ -265,7 +263,7 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); dispatch_async(dispatch_get_main_queue(), ^{ for (NSNumber *rootViewTag in _rootViewTags) { - [_viewRegistry[rootViewTag] invalidate]; + [(id)_viewRegistry[rootViewTag] invalidate]; } _rootViewTags = nil; @@ -283,7 +281,7 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); RCTAssert(_bridge == nil, @"Should not re-use same UIIManager instance"); _bridge = bridge; - _shadowViewRegistry = [RCTSparseArray new]; + _shadowViewRegistry = [NSMutableDictionary new]; // Get view managers from bridge NSMutableDictionary *componentDataByName = [NSMutableDictionary new]; @@ -407,7 +405,7 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); * Unregisters views from registries */ - (void)_purgeChildren:(NSArray> *)children - fromRegistry:(RCTSparseArray *)registry + fromRegistry:(NSMutableDictionary> *)registry { for (id child in children) { RCTTraverseViewNodes(registry[child.reactTag], ^(id subview) { @@ -415,9 +413,9 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); if ([subview conformsToProtocol:@protocol(RCTInvalidating)]) { [(id)subview invalidate]; } - registry[subview.reactTag] = nil; + [registry removeObjectForKey:subview.reactTag]; - if (registry == _viewRegistry) { + if (registry == (NSMutableDictionary> *)_viewRegistry) { [_bridgeTransactionListeners removeObject:subview]; } }); @@ -528,7 +526,7 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); return nil; } // Perform layout (possibly animated) - return ^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + return ^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { RCTResponseSenderBlock callback = self->_layoutAnimation.callback; // It's unsafe to call this callback more than once, so we nil it out here @@ -602,7 +600,7 @@ extern NSString *RCTBridgeModuleNameForClass(Class cls); [topView collectUpdatedProperties:applierBlocks parentProperties:@{}]; if (applierBlocks.count) { - [self addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [self addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { for (RCTApplierBlock block in applierBlocks) { block(viewRegistry); } @@ -676,15 +674,17 @@ RCT_EXPORT_METHOD(removeRootView:(nonnull NSNumber *)rootReactTag) { RCTShadowView *rootShadowView = _shadowViewRegistry[rootReactTag]; RCTAssert(rootShadowView.superview == nil, @"root view cannot have superview (ID %@)", rootReactTag); - [self _purgeChildren:(NSArray> *)rootShadowView.reactSubviews fromRegistry:_shadowViewRegistry]; - _shadowViewRegistry[rootReactTag] = nil; + [self _purgeChildren:(NSArray> *)rootShadowView.reactSubviews + fromRegistry:(NSMutableDictionary> *)_shadowViewRegistry]; + [_shadowViewRegistry removeObjectForKey:rootReactTag]; [_rootViewTags removeObject:rootReactTag]; - [self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry){ + [self addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry){ RCTAssertMainThread(); UIView *rootView = viewRegistry[rootReactTag]; - [uiManager _purgeChildren:(NSArray> *)rootView.reactSubviews fromRegistry:viewRegistry]; - viewRegistry[rootReactTag] = nil; + [uiManager _purgeChildren:(NSArray> *)rootView.reactSubviews + fromRegistry:(NSMutableDictionary> *)viewRegistry]; + [(NSMutableDictionary *)viewRegistry removeObjectForKey:rootReactTag]; [[NSNotificationCenter defaultCenter] postNotificationName:RCTUIManagerDidRemoveRootViewNotification object:uiManager @@ -726,16 +726,16 @@ RCT_EXPORT_METHOD(manageChildren:(nonnull NSNumber *)containerReactTag addChildReactTags:addChildReactTags addAtIndices:addAtIndices removeAtIndices:removeAtIndices - registry:_shadowViewRegistry]; + registry:(NSMutableDictionary> *)_shadowViewRegistry]; - [self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry){ + [self addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry){ [uiManager _manageChildren:containerReactTag moveFromIndices:moveFromIndices moveToIndices:moveToIndices addChildReactTags:addChildReactTags addAtIndices:addAtIndices removeAtIndices:removeAtIndices - registry:viewRegistry]; + registry:(NSMutableDictionary> *)viewRegistry]; }]; } @@ -745,7 +745,7 @@ RCT_EXPORT_METHOD(manageChildren:(nonnull NSNumber *)containerReactTag addChildReactTags:(NSArray *)addChildReactTags addAtIndices:(NSArray *)addAtIndices removeAtIndices:(NSArray *)removeAtIndices - registry:(RCTSparseArray *)registry + registry:(NSMutableDictionary> *)registry { id container = registry[containerReactTag]; RCTAssert(moveFromIndices.count == moveToIndices.count, @"moveFromIndices had size %tu, moveToIndices had size %tu", moveFromIndices.count, moveToIndices.count); @@ -803,8 +803,8 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag // the view, but it's the only way that makes sense given our threading model UIColor *backgroundColor = shadowView.backgroundColor; - [self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry){ - id view = [componentData createViewWithTag:reactTag props:props]; + [self addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry){ + UIView *view = [componentData createViewWithTag:reactTag props:props]; if ([view respondsToSelector:@selector(setBackgroundColor:)]) { ((UIView *)view).backgroundColor = backgroundColor; } @@ -812,7 +812,7 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag if ([view respondsToSelector:@selector(reactBridgeDidFinishTransaction)]) { [uiManager->_bridgeTransactionListeners addObject:view]; } - viewRegistry[reactTag] = view; + ((NSMutableDictionary *)viewRegistry)[reactTag] = view; }]; } @@ -824,7 +824,7 @@ RCT_EXPORT_METHOD(updateView:(nonnull NSNumber *)reactTag RCTComponentData *componentData = _componentDataByName[shadowView.viewName ?: viewName]; [componentData setProps:props forShadowView:shadowView]; - [self addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [self addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { UIView *view = viewRegistry[reactTag]; [componentData setProps:props forView:view]; }]; @@ -832,7 +832,7 @@ RCT_EXPORT_METHOD(updateView:(nonnull NSNumber *)reactTag RCT_EXPORT_METHOD(focus:(nonnull NSNumber *)reactTag) { - [self addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [self addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { UIView *newResponder = viewRegistry[reactTag]; [newResponder reactWillMakeFirstResponder]; [newResponder becomeFirstResponder]; @@ -842,7 +842,7 @@ RCT_EXPORT_METHOD(focus:(nonnull NSNumber *)reactTag) RCT_EXPORT_METHOD(blur:(nonnull NSNumber *)reactTag) { - [self addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry){ + [self addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry){ UIView *currentResponder = viewRegistry[reactTag]; [currentResponder resignFirstResponder]; }]; @@ -850,7 +850,7 @@ RCT_EXPORT_METHOD(blur:(nonnull NSNumber *)reactTag) RCT_EXPORT_METHOD(findSubviewIn:(nonnull NSNumber *)reactTag atPoint:(CGPoint)point callback:(RCTResponseSenderBlock)callback) { - [self addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [self addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { UIView *view = viewRegistry[reactTag]; UIView *target = [view hitTest:point withEvent:nil]; CGRect frame = [target convertRect:target.bounds toView:view]; @@ -881,7 +881,7 @@ RCT_EXPORT_METHOD(findSubviewIn:(nonnull NSNumber *)reactTag atPoint:(CGPoint)po // Set up next layout animation if (_nextLayoutAnimation) { RCTLayoutAnimation *layoutAnimation = _nextLayoutAnimation; - [self addUIBlock:^(RCTUIManager *uiManager, __unused RCTSparseArray *viewRegistry) { + [self addUIBlock:^(RCTUIManager *uiManager, __unused NSDictionary *viewRegistry) { uiManager->_layoutAnimation = layoutAnimation; }]; } @@ -895,7 +895,7 @@ RCT_EXPORT_METHOD(findSubviewIn:(nonnull NSNumber *)reactTag atPoint:(CGPoint)po // Clear layout animations if (_nextLayoutAnimation) { - [self addUIBlock:^(RCTUIManager *uiManager, __unused RCTSparseArray *viewRegistry) { + [self addUIBlock:^(RCTUIManager *uiManager, __unused NSDictionary *viewRegistry) { uiManager->_layoutAnimation = nil; }]; _nextLayoutAnimation = nil; @@ -944,7 +944,7 @@ RCT_EXPORT_METHOD(findSubviewIn:(nonnull NSNumber *)reactTag atPoint:(CGPoint)po RCT_EXPORT_METHOD(measure:(nonnull NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback) { - [self addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [self addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { UIView *view = viewRegistry[reactTag]; if (!view) { // this view was probably collapsed out @@ -1091,7 +1091,7 @@ RCT_EXPORT_METHOD(measureViewsInRect:(CGRect)rect RCT_EXPORT_METHOD(setMainScrollViewTag:(nonnull NSNumber *)reactTag) { - [self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [self addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry) { // - There should be at most one designated "main scroll view" // - There should be at most one designated "`nativeMainScrollDelegate`" // - The one designated main scroll view should have the one designated @@ -1118,7 +1118,7 @@ RCT_EXPORT_METHOD(scrollTo:(nonnull NSNumber *)reactTag withOffsetX:(CGFloat)offsetX offsetY:(CGFloat)offsetY) { - [self addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry){ + [self addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry){ UIView *view = viewRegistry[reactTag]; if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) { [(id)view scrollToOffset:(CGPoint){offsetX, offsetY} animated:YES]; @@ -1133,7 +1133,7 @@ RCT_EXPORT_METHOD(scrollWithoutAnimationTo:(nonnull NSNumber *)reactTag offsetX:(CGFloat)offsetX offsetY:(CGFloat)offsetY) { - [self addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry){ + [self addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry){ UIView *view = viewRegistry[reactTag]; if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) { [(id)view scrollToOffset:(CGPoint){offsetX, offsetY} animated:NO]; @@ -1146,7 +1146,7 @@ RCT_EXPORT_METHOD(scrollWithoutAnimationTo:(nonnull NSNumber *)reactTag RCT_EXPORT_METHOD(zoomToRect:(nonnull NSNumber *)reactTag withRect:(CGRect)rect) { - [self addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry){ + [self addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry){ UIView *view = viewRegistry[reactTag]; if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) { [(id)view zoomToRect:rect animated:YES]; @@ -1163,7 +1163,7 @@ RCT_EXPORT_METHOD(zoomToRect:(nonnull NSNumber *)reactTag RCT_EXPORT_METHOD(setJSResponder:(nonnull NSNumber *)reactTag blockNativeResponder:(__unused BOOL)blockNativeResponder) { - [self addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [self addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { _jsResponder = viewRegistry[reactTag]; if (!_jsResponder) { RCTLogError(@"Invalid view set to be the JS responder - tag %zd", reactTag); @@ -1173,27 +1173,27 @@ RCT_EXPORT_METHOD(setJSResponder:(nonnull NSNumber *)reactTag RCT_EXPORT_METHOD(clearJSResponder) { - [self addUIBlock:^(__unused RCTUIManager *uiManager, __unused RCTSparseArray *viewRegistry) { + [self addUIBlock:^(__unused RCTUIManager *uiManager, __unused NSDictionary *viewRegistry) { _jsResponder = nil; }]; } -- (NSDictionary *)constantsToExport +- (NSDictionary *)constantsToExport { - NSMutableDictionary *allJSConstants = [NSMutableDictionary new]; - NSMutableDictionary *directEvents = [NSMutableDictionary new]; - NSMutableDictionary *bubblingEvents = [NSMutableDictionary new]; + NSMutableDictionary *allJSConstants = [NSMutableDictionary new]; + NSMutableDictionary *directEvents = [NSMutableDictionary new]; + NSMutableDictionary *bubblingEvents = [NSMutableDictionary new]; [_componentDataByName enumerateKeysAndObjectsUsingBlock: ^(NSString *name, RCTComponentData *componentData, __unused BOOL *stop) { RCTViewManager *manager = componentData.manager; - NSMutableDictionary *constantsNamespace = - [NSMutableDictionary dictionaryWithDictionary:allJSConstants[name]]; + NSMutableDictionary *constantsNamespace = + [NSMutableDictionary dictionaryWithDictionary:allJSConstants[name]]; // Add custom constants // TODO: should these be inherited? - NSDictionary *constants = RCTClassOverridesInstanceMethod([manager class], @selector(constantsToExport)) ? [manager constantsToExport] : nil; + NSDictionary *constants = RCTClassOverridesInstanceMethod([manager class], @selector(constantsToExport)) ? [manager constantsToExport] : nil; if (constants.count) { RCTAssert(constantsNamespace[@"Constants"] == nil , @"Cannot redefine Constants in namespace: %@", name); // add an additional 'Constants' namespace for each class @@ -1201,7 +1201,7 @@ RCT_EXPORT_METHOD(clearJSResponder) } // Add native props - NSDictionary *viewConfig = [componentData viewConfig]; + NSDictionary *viewConfig = [componentData viewConfig]; constantsNamespace[@"NativeProps"] = viewConfig[@"propTypes"]; // Add direct events @@ -1234,7 +1234,7 @@ RCT_EXPORT_METHOD(clearJSResponder) } } - allJSConstants[name] = [constantsNamespace copy]; + allJSConstants[name] = constantsNamespace; }]; [allJSConstants addEntriesFromDictionary:@{ diff --git a/React/Profiler/RCTPerfMonitor.m b/React/Profiler/RCTPerfMonitor.m index e1ce3ad4b..e91360198 100644 --- a/React/Profiler/RCTPerfMonitor.m +++ b/React/Profiler/RCTPerfMonitor.m @@ -22,7 +22,6 @@ #import "RCTJavaScriptExecutor.h" #import "RCTPerformanceLogger.h" #import "RCTRootView.h" -#import "RCTSparseArray.h" #import "RCTUIManager.h" static NSString *const RCTPerfMonitorKey = @"RCTPerfMonitorKey"; @@ -441,10 +440,10 @@ RCT_EXPORT_MODULE() - (void)updateStats { - RCTSparseArray *views = [_bridge.uiManager valueForKey:@"viewRegistry"]; + NSDictionary *views = [_bridge.uiManager valueForKey:@"viewRegistry"]; NSUInteger viewCount = views.count; NSUInteger visibleViewCount = 0; - for (UIView *view in views.allObjects) { + for (UIView *view in views.allValues) { if (view.window || view.superview.window) { visibleViewCount++; } diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index 6327931a8..91ec873d3 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ 133CAE8E1B8E5CFD00F6AD92 /* RCTDatePicker.m in Sources */ = {isa = PBXBuildFile; fileRef = 133CAE8D1B8E5CFD00F6AD92 /* RCTDatePicker.m */; }; 13456E931ADAD2DE009F94A7 /* RCTConvert+CoreLocation.m in Sources */ = {isa = PBXBuildFile; fileRef = 13456E921ADAD2DE009F94A7 /* RCTConvert+CoreLocation.m */; }; 13456E961ADAD482009F94A7 /* RCTConvert+MapKit.m in Sources */ = {isa = PBXBuildFile; fileRef = 13456E951ADAD482009F94A7 /* RCTConvert+MapKit.m */; }; - 134FCB361A6D42D900051CC8 /* RCTSparseArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 83BEE46D1A6D19BC00B5863B /* RCTSparseArray.m */; }; 134FCB3D1A6E7F0800051CC8 /* RCTContextExecutor.m in Sources */ = {isa = PBXBuildFile; fileRef = 134FCB3A1A6E7F0800051CC8 /* RCTContextExecutor.m */; }; 13513F3C1B1F43F400FCE529 /* RCTProgressViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13513F3B1B1F43F400FCE529 /* RCTProgressViewManager.m */; }; 13723B501A82FD3C00F88898 /* RCTStatusBarManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13723B4F1A82FD3C00F88898 /* RCTStatusBarManager.m */; }; @@ -246,8 +245,6 @@ 83A1FE8B1B62640A00BE0E65 /* RCTModalHostView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTModalHostView.m; sourceTree = ""; }; 83A1FE8D1B62643A00BE0E65 /* RCTModalHostViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTModalHostViewManager.h; sourceTree = ""; }; 83A1FE8E1B62643A00BE0E65 /* RCTModalHostViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTModalHostViewManager.m; sourceTree = ""; }; - 83BEE46C1A6D19BC00B5863B /* RCTSparseArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTSparseArray.h; sourceTree = ""; }; - 83BEE46D1A6D19BC00B5863B /* RCTSparseArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTSparseArray.m; sourceTree = ""; }; 83CBBA2E1A601D0E00E9B192 /* libReact.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libReact.a; sourceTree = BUILT_PRODUCTS_DIR; }; 83CBBA4A1A601E3B00E9B192 /* RCTAssert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTAssert.h; sourceTree = ""; }; 83CBBA4B1A601E3B00E9B192 /* RCTAssert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTAssert.m; sourceTree = ""; }; @@ -510,8 +507,6 @@ 142014171B32094000CC17BA /* RCTPerformanceLogger.m */, 830A229C1A66C68A008503DA /* RCTRootView.h */, 830A229D1A66C68A008503DA /* RCTRootView.m */, - 83BEE46C1A6D19BC00B5863B /* RCTSparseArray.h */, - 83BEE46D1A6D19BC00B5863B /* RCTSparseArray.m */, 83CBBA961A6020BB00E9B192 /* RCTTouchHandler.h */, 83CBBA971A6020BB00E9B192 /* RCTTouchHandler.m */, 1345A83A1B265A0E00583190 /* RCTURLRequestDelegate.h */, @@ -660,7 +655,6 @@ 13E067571A70F44B002CDEE1 /* RCTView.m in Sources */, 13456E931ADAD2DE009F94A7 /* RCTConvert+CoreLocation.m in Sources */, 137327E91AA5CF210034F82E /* RCTTabBarItemManager.m in Sources */, - 134FCB361A6D42D900051CC8 /* RCTSparseArray.m in Sources */, 13A1F71E1A75392D00D3D453 /* RCTKeyCommands.m in Sources */, 83CBBA531A601E3B00E9B192 /* RCTUtils.m in Sources */, 14435CE61AAC4AE100FC20F4 /* RCTMapManager.m in Sources */, diff --git a/React/Views/RCTComponentData.h b/React/Views/RCTComponentData.h index d510956cd..9a43e9865 100644 --- a/React/Views/RCTComponentData.h +++ b/React/Views/RCTComponentData.h @@ -14,6 +14,7 @@ @class RCTShadowView; @class RCTViewManager; +@class UIView; @interface RCTComponentData : NSObject @@ -22,11 +23,11 @@ - (instancetype)initWithManager:(RCTViewManager *)manager NS_DESIGNATED_INITIALIZER; -- (id)createViewWithTag:(NSNumber *)tag props:(NSDictionary *)props; +- (UIView *)createViewWithTag:(NSNumber *)tag props:(NSDictionary *)props; - (RCTShadowView *)createShadowViewWithTag:(NSNumber *)tag; -- (void)setProps:(NSDictionary *)props forView:(id)view; -- (void)setProps:(NSDictionary *)props forShadowView:(RCTShadowView *)shadowView; +- (void)setProps:(NSDictionary *)props forView:(id)view; +- (void)setProps:(NSDictionary *)props forShadowView:(RCTShadowView *)shadowView; -- (NSDictionary *)viewConfig; +- (NSDictionary *)viewConfig; @end diff --git a/React/Views/RCTComponentData.m b/React/Views/RCTComponentData.m index 1f208150d..20c64c3e1 100644 --- a/React/Views/RCTComponentData.m +++ b/React/Views/RCTComponentData.m @@ -15,6 +15,7 @@ #import "RCTShadowView.h" #import "RCTUtils.h" #import "RCTViewManager.h" +#import "UIView+React.h" typedef void (^RCTPropBlock)(id view, id json); @@ -41,8 +42,8 @@ typedef void (^RCTPropBlock)(id view, id json); { id _defaultView; RCTShadowView *_defaultShadowView; - NSMutableDictionary *_viewPropBlocks; - NSMutableDictionary *_shadowPropBlocks; + NSMutableDictionary *_viewPropBlocks; + NSMutableDictionary *_shadowPropBlocks; } - (instancetype)initWithManager:(RCTViewManager *)manager @@ -63,17 +64,15 @@ typedef void (^RCTPropBlock)(id view, id json); RCT_NOT_IMPLEMENTED(- (instancetype)init) -- (id)createViewWithTag:(NSNumber *)tag props:(NSDictionary *)props +- (UIView *)createViewWithTag:(NSNumber *)tag props:(NSDictionary *)props { RCTAssertMainThread(); - id view = (id)(props ? [_manager viewWithProps:props] : [_manager view]); + UIView *view = (UIView *)(props ? [_manager viewWithProps:props] : [_manager view]); view.reactTag = tag; - if ([view isKindOfClass:[UIView class]]) { - ((UIView *)view).multipleTouchEnabled = YES; - ((UIView *)view).userInteractionEnabled = YES; // required for touch handling - ((UIView *)view).layer.allowsGroupOpacity = YES; // required for touch handling - } + view.multipleTouchEnabled = YES; + view.userInteractionEnabled = YES; // required for touch handling + view.layer.allowsGroupOpacity = YES; // required for touch handling return view; } @@ -88,7 +87,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) - (RCTPropBlock)propBlockForKey:(NSString *)name defaultView:(id)defaultView { BOOL shadowView = [defaultView isKindOfClass:[RCTShadowView class]]; - NSMutableDictionary *propBlocks = shadowView ? _shadowPropBlocks : _viewPropBlocks; + NSMutableDictionary *propBlocks = shadowView ? _shadowPropBlocks : _viewPropBlocks; RCTPropBlock propBlock = propBlocks[name]; if (!propBlock) { @@ -277,7 +276,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) return propBlock; } -- (void)setProps:(NSDictionary *)props forView:(id)view +- (void)setProps:(NSDictionary *)props forView:(id)view { if (!view) { return; @@ -292,7 +291,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) }]; } -- (void)setProps:(NSDictionary *)props forShadowView:(RCTShadowView *)shadowView +- (void)setProps:(NSDictionary *)props forShadowView:(RCTShadowView *)shadowView { if (!shadowView) { return; @@ -309,7 +308,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) [shadowView updateLayout]; } -- (NSDictionary *)viewConfig +- (NSDictionary *)viewConfig { Class managerClass = [_manager class]; diff --git a/React/Views/RCTDatePickerManager.m b/React/Views/RCTDatePickerManager.m index 5bf0ebad4..165f69c2a 100644 --- a/React/Views/RCTDatePickerManager.m +++ b/React/Views/RCTDatePickerManager.m @@ -42,7 +42,7 @@ RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock) RCT_REMAP_VIEW_PROPERTY(mode, datePickerMode, UIDatePickerMode) RCT_REMAP_VIEW_PROPERTY(timeZoneOffsetInMinutes, timeZone, NSTimeZone) -- (NSDictionary *)constantsToExport +- (NSDictionary *)constantsToExport { UIDatePicker *view = [UIDatePicker new]; return @{ diff --git a/React/Views/RCTModalHostView.m b/React/Views/RCTModalHostView.m index c82ab5249..6bc9a7af1 100644 --- a/React/Views/RCTModalHostView.m +++ b/React/Views/RCTModalHostView.m @@ -51,18 +51,18 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:coder) } } -- (NSArray *> *)reactSubviews +- (NSArray *)reactSubviews { return _modalViewController.view ? @[_modalViewController.view] : @[]; } -- (void)insertReactSubview:(UIView *)subview atIndex:(__unused NSInteger)atIndex +- (void)insertReactSubview:(UIView *)subview atIndex:(__unused NSInteger)atIndex { [subview addGestureRecognizer:_touchHandler]; _modalViewController.view = subview; } -- (void)removeReactSubview:(UIView *)subview +- (void)removeReactSubview:(UIView *)subview { RCTAssert(subview == _modalViewController.view, @"Cannot remove view other than modal view"); _modalViewController.view = nil; diff --git a/React/Views/RCTNavigatorManager.m b/React/Views/RCTNavigatorManager.m index 0e900a14c..7356fee01 100644 --- a/React/Views/RCTNavigatorManager.m +++ b/React/Views/RCTNavigatorManager.m @@ -12,8 +12,8 @@ #import "RCTBridge.h" #import "RCTConvert.h" #import "RCTNavigator.h" -#import "RCTSparseArray.h" #import "RCTUIManager.h" +#import "UIView+React.h" @implementation RCTNavigatorManager @@ -34,7 +34,7 @@ RCT_EXPORT_METHOD(requestSchedulingJavaScriptNavigation:(nonnull NSNumber *)reac callback:(RCTResponseSenderBlock)callback) { [self.bridge.uiManager addUIBlock: - ^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry){ + ^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry){ RCTNavigator *navigator = viewRegistry[reactTag]; if ([navigator isKindOfClass:[RCTNavigator class]]) { BOOL wasAcquired = [navigator requestSchedulingJavaScriptNavigation]; diff --git a/React/Views/RCTPickerManager.m b/React/Views/RCTPickerManager.m index d43c58ad9..79d9c4758 100644 --- a/React/Views/RCTPickerManager.m +++ b/React/Views/RCTPickerManager.m @@ -26,7 +26,7 @@ RCT_EXPORT_VIEW_PROPERTY(items, NSDictionaryArray) RCT_EXPORT_VIEW_PROPERTY(selectedIndex, NSInteger) RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock) -- (NSDictionary *)constantsToExport +- (NSDictionary *)constantsToExport { UIPickerView *view = [UIPickerView new]; return @{ diff --git a/React/Views/RCTProgressViewManager.m b/React/Views/RCTProgressViewManager.m index 0cd9049d3..46a334724 100644 --- a/React/Views/RCTProgressViewManager.m +++ b/React/Views/RCTProgressViewManager.m @@ -36,7 +36,7 @@ RCT_EXPORT_VIEW_PROPERTY(trackTintColor, UIColor) RCT_EXPORT_VIEW_PROPERTY(progressImage, UIImage) RCT_EXPORT_VIEW_PROPERTY(trackImage, UIImage) -- (NSDictionary *)constantsToExport +- (NSDictionary *)constantsToExport { UIProgressView *view = [UIProgressView new]; return @{ diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index 1dfb9c1c9..e125061f4 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -412,7 +412,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) [subview removeFromSuperview]; } -- (NSArray *> *)reactSubviews +- (NSArray *)reactSubviews { return _contentView ? @[_contentView] : @[]; } diff --git a/React/Views/RCTScrollViewManager.m b/React/Views/RCTScrollViewManager.m index 6470f10f1..e90bda75e 100644 --- a/React/Views/RCTScrollViewManager.m +++ b/React/Views/RCTScrollViewManager.m @@ -11,7 +11,6 @@ #import "RCTBridge.h" #import "RCTScrollView.h" -#import "RCTSparseArray.h" #import "RCTUIManager.h" @interface RCTScrollView (Private) @@ -67,7 +66,7 @@ RCT_EXPORT_VIEW_PROPERTY(snapToInterval, int) RCT_EXPORT_VIEW_PROPERTY(snapToAlignment, NSString) RCT_REMAP_VIEW_PROPERTY(contentOffset, scrollView.contentOffset, CGPoint) -- (NSDictionary *)constantsToExport +- (NSDictionary *)constantsToExport { return @{ // TODO: unused - remove these? @@ -81,7 +80,7 @@ RCT_REMAP_VIEW_PROPERTY(contentOffset, scrollView.contentOffset, CGPoint) RCT_EXPORT_METHOD(getContentSize:(nonnull NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { RCTScrollView *view = viewRegistry[reactTag]; if (!view || ![view isKindOfClass:[RCTScrollView class]]) { @@ -100,7 +99,7 @@ RCT_EXPORT_METHOD(getContentSize:(nonnull NSNumber *)reactTag RCT_EXPORT_METHOD(calculateChildFrames:(nonnull NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { RCTScrollView *view = viewRegistry[reactTag]; if (!view || ![view isKindOfClass:[RCTScrollView class]]) { diff --git a/React/Views/RCTSegmentedControlManager.m b/React/Views/RCTSegmentedControlManager.m index cbe9f4a4b..e56be4cf0 100644 --- a/React/Views/RCTSegmentedControlManager.m +++ b/React/Views/RCTSegmentedControlManager.m @@ -29,7 +29,7 @@ RCT_EXPORT_VIEW_PROPERTY(momentary, BOOL) RCT_EXPORT_VIEW_PROPERTY(enabled, BOOL) RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock) -- (NSDictionary *)constantsToExport +- (NSDictionary *)constantsToExport { RCTSegmentedControl *view = [RCTSegmentedControl new]; return @{ diff --git a/React/Views/RCTShadowView.h b/React/Views/RCTShadowView.h index 1d697083a..138000578 100644 --- a/React/Views/RCTShadowView.h +++ b/React/Views/RCTShadowView.h @@ -21,7 +21,7 @@ typedef NS_ENUM(NSUInteger, RCTUpdateLifecycle) { RCTUpdateLifecycleDirtied, }; -typedef void (^RCTApplierBlock)(RCTSparseArray *viewRegistry); +typedef void (^RCTApplierBlock)(NSDictionary *viewRegistry); /** * ShadowView tree mirrors RCT view tree. Every node is highly stateful. @@ -124,14 +124,14 @@ typedef void (^RCTApplierBlock)(RCTSparseArray *viewRegistry); * on the main thread in order to update the view. */ - (void)collectUpdatedProperties:(NSMutableSet *)applierBlocks - parentProperties:(NSDictionary *)parentProperties; + parentProperties:(NSDictionary *)parentProperties; /** * Process the updated properties and apply them to view. Shadow view classes * that add additional propagating properties should override this method. */ -- (NSDictionary *)processUpdatedProperties:(NSMutableSet *)applierBlocks - parentProperties:(NSDictionary *)parentProperties NS_REQUIRES_SUPER; +- (NSDictionary *)processUpdatedProperties:(NSMutableSet *)applierBlocks + parentProperties:(NSDictionary *)parentProperties NS_REQUIRES_SUPER; /** * Calculate all views whose frame needs updating after layout has been calculated. diff --git a/React/Views/RCTShadowView.m b/React/Views/RCTShadowView.m index ed4fef1d9..293466d2b 100644 --- a/React/Views/RCTShadowView.m +++ b/React/Views/RCTShadowView.m @@ -11,14 +11,13 @@ #import "RCTConvert.h" #import "RCTLog.h" -#import "RCTSparseArray.h" #import "RCTUtils.h" #import "UIView+React.h" typedef void (^RCTActionBlock)(RCTShadowView *shadowViewSelf, id value); typedef void (^RCTResetActionBlock)(RCTShadowView *shadowViewSelf); -const NSString *const RCTBackgroundColorProp = @"backgroundColor"; +static NSString *const RCTBackgroundColorProp = @"backgroundColor"; typedef NS_ENUM(unsigned int, meta_prop_t) { META_PROP_LEFT, @@ -171,8 +170,8 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st } } -- (NSDictionary *)processUpdatedProperties:(NSMutableSet *)applierBlocks - parentProperties:(NSDictionary *)parentProperties +- (NSDictionary *)processUpdatedProperties:(NSMutableSet *)applierBlocks + parentProperties:(NSDictionary *)parentProperties { // TODO: we always refresh all propagated properties when propagation is // dirtied, but really we should track which properties have changed and @@ -181,14 +180,14 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st if (!_backgroundColor) { UIColor *parentBackgroundColor = parentProperties[RCTBackgroundColorProp]; if (parentBackgroundColor) { - [applierBlocks addObject:^(RCTSparseArray *viewRegistry) { + [applierBlocks addObject:^(NSDictionary *viewRegistry) { UIView *view = viewRegistry[_reactTag]; [view reactSetInheritedBackgroundColor:parentBackgroundColor]; }]; } } else { // Update parent properties for children - NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary:parentProperties]; + NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary:parentProperties]; CGFloat alpha = CGColorGetAlpha(_backgroundColor.CGColor); if (alpha < 1.0) { // If bg is non-opaque, don't propagate further @@ -202,14 +201,14 @@ static void RCTProcessMetaProps(const float metaProps[META_PROP_COUNT], float st } - (void)collectUpdatedProperties:(NSMutableSet *)applierBlocks - parentProperties:(NSDictionary *)parentProperties + parentProperties:(NSDictionary *)parentProperties { if (_propagationLifecycle == RCTUpdateLifecycleComputed && [parentProperties isEqualToDictionary:_lastParentProperties]) { return; } _propagationLifecycle = RCTUpdateLifecycleComputed; _lastParentProperties = parentProperties; - NSDictionary *nextProps = [self processUpdatedProperties:applierBlocks parentProperties:parentProperties]; + NSDictionary *nextProps = [self processUpdatedProperties:applierBlocks parentProperties:parentProperties]; for (RCTShadowView *child in _reactSubviews) { [child collectUpdatedProperties:applierBlocks parentProperties:nextProps]; } diff --git a/React/Views/RCTView.m b/React/Views/RCTView.m index 3ba4d88d6..8f143d8a9 100644 --- a/React/Views/RCTView.m +++ b/React/Views/RCTView.m @@ -92,7 +92,7 @@ static NSString *RCTRecursiveAccessibilityLabel(UIView *view) @implementation RCTView { - NSMutableArray *> *_reactSubviews; + NSMutableArray *_reactSubviews; UIColor *_backgroundColor; } @@ -413,7 +413,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:unused) [subview removeFromSuperview]; } -- (NSArray *> *)reactSubviews +- (NSArray *)reactSubviews { // The _reactSubviews array is only used when we have hidden // offscreen views. If _reactSubviews is nil, we can assume diff --git a/React/Views/RCTViewManager.h b/React/Views/RCTViewManager.h index 5825fa8cd..def09910d 100644 --- a/React/Views/RCTViewManager.h +++ b/React/Views/RCTViewManager.h @@ -21,7 +21,7 @@ @class RCTSparseArray; @class RCTUIManager; -typedef void (^RCTViewManagerUIBlock)(RCTUIManager *uiManager, RCTSparseArray *viewRegistry); +typedef void (^RCTViewManagerUIBlock)(RCTUIManager *uiManager, NSDictionary *viewRegistry); @interface RCTViewManager : NSObject @@ -39,7 +39,7 @@ typedef void (^RCTViewManagerUIBlock)(RCTUIManager *uiManager, RCTSparseArray *v * return a fresh instance each time. The view module MUST NOT cache the returned * view and return the same instance for subsequent calls. */ -- (UIView *)view; +- (UIView *)view; /** * This method instantiates a native view using the props passed into the component. @@ -48,7 +48,7 @@ typedef void (^RCTViewManagerUIBlock)(RCTUIManager *uiManager, RCTSparseArray *v * still be set individually, after the view is created. Like the -view method, * -viewWithProps: should return a fresh instance each time it is called. */ -- (UIView *)viewWithProps:(NSDictionary *)props; +- (UIView *)viewWithProps:(NSDictionary *)props; /** * This method instantiates a shadow view to be managed by the module. If omitted, @@ -97,7 +97,7 @@ typedef void (^RCTViewManagerUIBlock)(RCTUIManager *uiManager, RCTSparseArray *v * custo layout logic or tasks that involve walking the view hierarchy. * To be deprecated, hopefully. */ -- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(RCTSparseArray *)shadowViewRegistry; +- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary *)shadowViewRegistry; /** * This handles the simple case, where JS and native property names match. diff --git a/React/Views/RCTViewManager.m b/React/Views/RCTViewManager.m index 256f1a0a5..1004aad3f 100644 --- a/React/Views/RCTViewManager.m +++ b/React/Views/RCTViewManager.m @@ -54,7 +54,7 @@ RCT_EXPORT_MODULE() return _bridge.uiManager.methodQueue; } -- (UIView *)viewWithProps:(__unused NSDictionary *)props +- (UIView *)viewWithProps:(__unused NSDictionary *)props { return [self view]; } @@ -95,7 +95,7 @@ RCT_EXPORT_MODULE() return @[]; } -- (NSDictionary *)constantsToExport +- (NSDictionary *)constantsToExport { return nil; } @@ -105,7 +105,7 @@ RCT_EXPORT_MODULE() return nil; } -- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(__unused RCTSparseArray *)shadowViewRegistry +- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(__unused NSDictionary *)shadowViewRegistry { return nil; } diff --git a/React/Views/RCTWebView.h b/React/Views/RCTWebView.h index 3d514dd47..d806cd987 100644 --- a/React/Views/RCTWebView.h +++ b/React/Views/RCTWebView.h @@ -22,7 +22,7 @@ extern NSString *const RCTJSNavigationScheme; @protocol RCTWebViewDelegate - (BOOL)webView:(RCTWebView *)webView -shouldStartLoadForRequest:(NSMutableDictionary *)request +shouldStartLoadForRequest:(NSMutableDictionary *)request withCallback:(RCTDirectEventBlock)callback; @end diff --git a/React/Views/RCTWebView.m b/React/Views/RCTWebView.m index 2c35bc453..46a263d0e 100644 --- a/React/Views/RCTWebView.m +++ b/React/Views/RCTWebView.m @@ -118,9 +118,9 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) return _webView.backgroundColor; } -- (NSMutableDictionary *)baseEvent +- (NSMutableDictionary *)baseEvent { - NSMutableDictionary *event = [[NSMutableDictionary alloc] initWithDictionary:@{ + NSMutableDictionary *event = [[NSMutableDictionary alloc] initWithDictionary:@{ @"url": _webView.request.URL.absoluteString ?: @"", @"loading" : @(_webView.loading), @"title": [_webView stringByEvaluatingJavaScriptFromString:@"document.title"], @@ -147,7 +147,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) // skip this for the JS Navigation handler if (!isJSNavigation && _onShouldStartLoadWithRequest) { - NSMutableDictionary *event = [self baseEvent]; + NSMutableDictionary *event = [self baseEvent]; [event addEntriesFromDictionary: @{ @"url": (request.URL).absoluteString, @"navigationType": @(navigationType) @@ -163,7 +163,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) // We have this check to filter out iframe requests and whatnot BOOL isTopFrame = [request.URL isEqual:request.mainDocumentURL]; if (isTopFrame) { - NSMutableDictionary *event = [self baseEvent]; + NSMutableDictionary *event = [self baseEvent]; [event addEntriesFromDictionary: @{ @"url": (request.URL).absoluteString, @"navigationType": @(navigationType) @@ -187,7 +187,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) return; } - NSMutableDictionary *event = [self baseEvent]; + NSMutableDictionary *event = [self baseEvent]; [event addEntriesFromDictionary:@{ @"domain": error.domain, @"code": @(error.code), @@ -202,7 +202,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) if (_injectedJavaScript != nil) { NSString *jsEvaluationValue = [webView stringByEvaluatingJavaScriptFromString:_injectedJavaScript]; - NSMutableDictionary *event = [self baseEvent]; + NSMutableDictionary *event = [self baseEvent]; event[@"jsEvaluationValue"] = jsEvaluationValue; _onLoadingFinish(event); diff --git a/React/Views/RCTWebViewManager.m b/React/Views/RCTWebViewManager.m index 7512000b0..6c765e8d4 100644 --- a/React/Views/RCTWebViewManager.m +++ b/React/Views/RCTWebViewManager.m @@ -10,9 +10,9 @@ #import "RCTWebViewManager.h" #import "RCTBridge.h" -#import "RCTSparseArray.h" #import "RCTUIManager.h" #import "RCTWebView.h" +#import "UIView+React.h" @interface RCTWebViewManager () @@ -45,7 +45,7 @@ RCT_EXPORT_VIEW_PROPERTY(onLoadingFinish, RCTDirectEventBlock); RCT_EXPORT_VIEW_PROPERTY(onLoadingError, RCTDirectEventBlock); RCT_EXPORT_VIEW_PROPERTY(onShouldStartLoadWithRequest, RCTDirectEventBlock); -- (NSDictionary *)constantsToExport +- (NSDictionary *)constantsToExport { return @{ @"JSNavigationScheme": RCTJSNavigationScheme, @@ -62,7 +62,7 @@ RCT_EXPORT_VIEW_PROPERTY(onShouldStartLoadWithRequest, RCTDirectEventBlock); RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { RCTWebView *view = viewRegistry[reactTag]; if (![view isKindOfClass:[RCTWebView class]]) { RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view); @@ -74,7 +74,7 @@ RCT_EXPORT_METHOD(goBack:(nonnull NSNumber *)reactTag) RCT_EXPORT_METHOD(goForward:(nonnull NSNumber *)reactTag) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { id view = viewRegistry[reactTag]; if (![view isKindOfClass:[RCTWebView class]]) { RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view); @@ -86,7 +86,7 @@ RCT_EXPORT_METHOD(goForward:(nonnull NSNumber *)reactTag) RCT_EXPORT_METHOD(reload:(nonnull NSNumber *)reactTag) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { + [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { RCTWebView *view = viewRegistry[reactTag]; if (![view isKindOfClass:[RCTWebView class]]) { RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view); @@ -99,7 +99,7 @@ RCT_EXPORT_METHOD(reload:(nonnull NSNumber *)reactTag) #pragma mark - Exported synchronous methods - (BOOL)webView:(__unused RCTWebView *)webView -shouldStartLoadForRequest:(NSMutableDictionary *)request +shouldStartLoadForRequest:(NSMutableDictionary *)request withCallback:(RCTDirectEventBlock)callback { _shouldStartLoadLock = [[NSConditionLock alloc] initWithCondition:arc4random()]; diff --git a/React/Views/UIView+React.h b/React/Views/UIView+React.h index 6bfb6d80e..3cb442afb 100644 --- a/React/Views/UIView+React.h +++ b/React/Views/UIView+React.h @@ -15,8 +15,8 @@ @interface UIView (React) -- (NSArray *> *)reactSubviews; -- (UIView *)reactSuperview; +- (NSArray *)reactSubviews; +- (UIView *)reactSuperview; /** * Used by the UIIManager to set the view frame. diff --git a/React/Views/UIView+React.m b/React/Views/UIView+React.m index 14c7a26c7..892912364 100644 --- a/React/Views/UIView+React.m +++ b/React/Views/UIView+React.m @@ -51,12 +51,12 @@ [subview removeFromSuperview]; } -- (NSArray *> *)reactSubviews +- (NSArray *)reactSubviews { return self.subviews; } -- (UIView *)reactSuperview +- (UIView *)reactSuperview { return self.superview; }