From fc6e209223fb80316e5e2cd1dd654af6ae0eb273 Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Wed, 22 Apr 2015 13:23:48 -0700 Subject: [PATCH] Fixed broken struct arguments --- Libraries/Geolocation/RCTLocationObserver.m | 7 ++++--- React/Base/RCTBridge.m | 9 ++++++--- React/Modules/RCTUIManager.m | 6 ++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Libraries/Geolocation/RCTLocationObserver.m b/Libraries/Geolocation/RCTLocationObserver.m index 3e864657b..5d56caccb 100644 --- a/Libraries/Geolocation/RCTLocationObserver.m +++ b/Libraries/Geolocation/RCTLocationObserver.m @@ -163,12 +163,12 @@ RCT_EXPORT_MODULE() #pragma mark - Public API -RCT_EXPORT_METHOD(startObserving:(RCTLocationOptions)options) +RCT_EXPORT_METHOD(startObserving:(NSDictionary *)optionsJSON) { [self checkLocationConfig]; // Select best options - _observerOptions = options; + _observerOptions = [RCTConvert RCTLocationOptions:optionsJSON]; for (RCTLocationRequest *request in _pendingRequests) { _observerOptions.accuracy = MIN(_observerOptions.accuracy, request.options.accuracy); } @@ -189,7 +189,7 @@ RCT_EXPORT_METHOD(stopObserving) } } -RCT_EXPORT_METHOD(getCurrentPosition:(RCTLocationOptions)options +RCT_EXPORT_METHOD(getCurrentPosition:(NSDictionary *)optionsJSON withSuccessCallback:(RCTResponseSenderBlock)successBlock errorCallback:(RCTResponseSenderBlock)errorBlock) { @@ -219,6 +219,7 @@ RCT_EXPORT_METHOD(getCurrentPosition:(RCTLocationOptions)options } // Check if previous recorded location exists and is good enough + RCTLocationOptions options = [RCTConvert RCTLocationOptions:optionsJSON]; if (_lastLocationEvent && CFAbsoluteTimeGetCurrent() - [RCTConvert NSTimeInterval:_lastLocationEvent[@"timestamp"]] < options.maximumAge && [_lastLocationEvent[@"coords"][@"accuracy"] doubleValue] >= options.accuracy) { diff --git a/React/Base/RCTBridge.m b/React/Base/RCTBridge.m index a4a4362b0..48fd672a3 100644 --- a/React/Base/RCTBridge.m +++ b/React/Base/RCTBridge.m @@ -375,10 +375,14 @@ static NSString *RCTStringUpToFirstArgument(NSString *methodName) RCT_CONVERT_CASE('B', BOOL) RCT_CONVERT_CASE('@', id) RCT_CONVERT_CASE('^', void *) - + case '{': + RCTAssert(NO, @"Argument %zd of %C[%@ %@] is defined as %@, however RCT_EXPORT_METHOD() " + "does not currently support struct-type arguments.", i - 2, + [reactMethodName characterAtIndex:0], _moduleClassName, + objCMethodName, argumentName); + break; default: defaultCase(argumentType); - break; } } else if ([argumentName isEqualToString:@"RCTResponseSenderBlock"]) { addBlockArgument(); @@ -434,7 +438,6 @@ static NSString *RCTStringUpToFirstArgument(NSString *methodName) default: defaultCase(argumentType); - break; } } } diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index b7ae182ba..451a343d0 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -1001,11 +1001,12 @@ RCT_EXPORT_METHOD(measureLayoutRelativeToParent:(NSNumber *)reactTag * Only layouts for views that are within the rect passed in are returned. Invokes the error callback if the * passed in parent view does not exist. Invokes the supplied callback with the array of computed layouts. */ -RCT_EXPORT_METHOD(measureViewsInRect:(CGRect)rect +RCT_EXPORT_METHOD(measureViewsInRect:(id)rectJSON parentView:(NSNumber *)reactTag errorCallback:(RCTResponseSenderBlock)errorCallback callback:(RCTResponseSenderBlock)callback) { + CGRect rect = [RCTConvert CGRect:rectJSON]; RCTShadowView *shadowView = _shadowViewRegistry[reactTag]; if (!shadowView) { RCTLogError(@"Attempting to measure view that does not exist (tag #%@)", reactTag); @@ -1101,8 +1102,9 @@ RCT_EXPORT_METHOD(scrollWithoutAnimationTo:(NSNumber *)reactTag } RCT_EXPORT_METHOD(zoomToRect:(NSNumber *)reactTag - withRect:(CGRect)rect) + withRect:(id)rectJSON) { + CGRect rect = [RCTConvert CGRect:rectJSON]; [self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry){ UIView *view = viewRegistry[reactTag]; if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {