From 4f2fac791654863357faaf4ce007a0046a8b8a5c Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 23 Aug 2017 16:30:24 -0700 Subject: [PATCH] Start of iOS project rewrite --- .gitignore | 1 + ios/RCTMGL.xcodeproj/project.pbxproj | 317 +++++++++++++++++++++++++++ ios/RCTMGL/MGLModule.h | 13 ++ ios/RCTMGL/MGLModule.m | 33 +++ ios/RCTMGL/RCTConvert+Mapbox.h | 16 ++ ios/RCTMGL/RCTConvert+Mapbox.m | 32 +++ ios/RCTMGL/RCTMGL.h | 13 ++ ios/RCTMGL/RCTMGL.m | 13 ++ ios/RCTMGL/RCTMGLMapView.h | 22 ++ ios/RCTMGL/RCTMGLMapView.m | 84 +++++++ ios/RCTMGL/RCTMGLMapViewManager.h | 13 ++ ios/RCTMGL/RCTMGLMapViewManager.m | 35 +++ react-native-mapbox-gl.podspec | 18 ++ 13 files changed, 610 insertions(+) create mode 100644 ios/RCTMGL.xcodeproj/project.pbxproj create mode 100644 ios/RCTMGL/MGLModule.h create mode 100644 ios/RCTMGL/MGLModule.m create mode 100644 ios/RCTMGL/RCTConvert+Mapbox.h create mode 100644 ios/RCTMGL/RCTConvert+Mapbox.m create mode 100644 ios/RCTMGL/RCTMGL.h create mode 100644 ios/RCTMGL/RCTMGL.m create mode 100644 ios/RCTMGL/RCTMGLMapView.h create mode 100644 ios/RCTMGL/RCTMGLMapView.m create mode 100644 ios/RCTMGL/RCTMGLMapViewManager.h create mode 100644 ios/RCTMGL/RCTMGLMapViewManager.m create mode 100644 react-native-mapbox-gl.podspec diff --git a/.gitignore b/.gitignore index e3dbb66..e16a0bf 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ Pods/ # node_modules/ npm-debug.log +package-lock.json *.tgz # project specific diff --git a/ios/RCTMGL.xcodeproj/project.pbxproj b/ios/RCTMGL.xcodeproj/project.pbxproj new file mode 100644 index 0000000..92b0dbc --- /dev/null +++ b/ios/RCTMGL.xcodeproj/project.pbxproj @@ -0,0 +1,317 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + C4D144421F4E16F600396F26 /* RCTMGL.m in Sources */ = {isa = PBXBuildFile; fileRef = C4D144411F4E16F600396F26 /* RCTMGL.m */; }; + C4D144431F4E16F600396F26 /* RCTMGL.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C4D144401F4E16F600396F26 /* RCTMGL.h */; }; + C4D1444C1F4E178100396F26 /* RCTMGLMapView.m in Sources */ = {isa = PBXBuildFile; fileRef = C4D1444B1F4E178100396F26 /* RCTMGLMapView.m */; }; + C4D1444F1F4E181100396F26 /* RCTMGLMapViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C4D1444E1F4E181100396F26 /* RCTMGLMapViewManager.m */; }; + C4D144531F4E190C00396F26 /* MGLModule.m in Sources */ = {isa = PBXBuildFile; fileRef = C4D144521F4E190C00396F26 /* MGLModule.m */; }; + C4D144971F4E2F1100396F26 /* RCTConvert+Mapbox.m in Sources */ = {isa = PBXBuildFile; fileRef = C4D144961F4E2F1100396F26 /* RCTConvert+Mapbox.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + C4D1443B1F4E16F600396F26 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + C4D144431F4E16F600396F26 /* RCTMGL.h in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + C4D1443D1F4E16F600396F26 /* libRCTMGL.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTMGL.a; sourceTree = BUILT_PRODUCTS_DIR; }; + C4D144401F4E16F600396F26 /* RCTMGL.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTMGL.h; sourceTree = ""; }; + C4D144411F4E16F600396F26 /* RCTMGL.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RCTMGL.m; sourceTree = ""; }; + C4D1444A1F4E178100396F26 /* RCTMGLMapView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTMGLMapView.h; sourceTree = ""; }; + C4D1444B1F4E178100396F26 /* RCTMGLMapView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTMGLMapView.m; sourceTree = ""; }; + C4D1444D1F4E181100396F26 /* RCTMGLMapViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTMGLMapViewManager.h; sourceTree = ""; }; + C4D1444E1F4E181100396F26 /* RCTMGLMapViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTMGLMapViewManager.m; sourceTree = ""; }; + C4D144511F4E190C00396F26 /* MGLModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLModule.h; sourceTree = ""; }; + C4D144521F4E190C00396F26 /* MGLModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLModule.m; sourceTree = ""; }; + C4D144951F4E2F1100396F26 /* RCTConvert+Mapbox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTConvert+Mapbox.h"; sourceTree = ""; }; + C4D144961F4E2F1100396F26 /* RCTConvert+Mapbox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTConvert+Mapbox.m"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + C4D1443A1F4E16F600396F26 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + C4D144341F4E16F600396F26 = { + isa = PBXGroup; + children = ( + C4D1443F1F4E16F600396F26 /* RCTMGL */, + C4D1443E1F4E16F600396F26 /* Products */, + ); + sourceTree = ""; + }; + C4D1443E1F4E16F600396F26 /* Products */ = { + isa = PBXGroup; + children = ( + C4D1443D1F4E16F600396F26 /* libRCTMGL.a */, + ); + name = Products; + sourceTree = ""; + }; + C4D1443F1F4E16F600396F26 /* RCTMGL */ = { + isa = PBXGroup; + children = ( + C4D144941F4E2EC800396F26 /* Utils */, + C4D144501F4E188F00396F26 /* MGLModule */, + C4D144491F4E176300396F26 /* MapView */, + C4D144401F4E16F600396F26 /* RCTMGL.h */, + C4D144411F4E16F600396F26 /* RCTMGL.m */, + ); + path = RCTMGL; + sourceTree = ""; + }; + C4D144491F4E176300396F26 /* MapView */ = { + isa = PBXGroup; + children = ( + C4D1444A1F4E178100396F26 /* RCTMGLMapView.h */, + C4D1444B1F4E178100396F26 /* RCTMGLMapView.m */, + C4D1444D1F4E181100396F26 /* RCTMGLMapViewManager.h */, + C4D1444E1F4E181100396F26 /* RCTMGLMapViewManager.m */, + ); + name = MapView; + sourceTree = ""; + }; + C4D144501F4E188F00396F26 /* MGLModule */ = { + isa = PBXGroup; + children = ( + C4D144511F4E190C00396F26 /* MGLModule.h */, + C4D144521F4E190C00396F26 /* MGLModule.m */, + ); + name = MGLModule; + sourceTree = ""; + }; + C4D144941F4E2EC800396F26 /* Utils */ = { + isa = PBXGroup; + children = ( + C4D144951F4E2F1100396F26 /* RCTConvert+Mapbox.h */, + C4D144961F4E2F1100396F26 /* RCTConvert+Mapbox.m */, + ); + name = Utils; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + C4D1443C1F4E16F600396F26 /* RCTMGL */ = { + isa = PBXNativeTarget; + buildConfigurationList = C4D144461F4E16F600396F26 /* Build configuration list for PBXNativeTarget "RCTMGL" */; + buildPhases = ( + C4D144391F4E16F600396F26 /* Sources */, + C4D1443A1F4E16F600396F26 /* Frameworks */, + C4D1443B1F4E16F600396F26 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = RCTMGL; + productName = RCTMGL; + productReference = C4D1443D1F4E16F600396F26 /* libRCTMGL.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + C4D144351F4E16F600396F26 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0830; + ORGANIZATIONNAME = "Mapbox Inc"; + TargetAttributes = { + C4D1443C1F4E16F600396F26 = { + CreatedOnToolsVersion = 8.3.3; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = C4D144381F4E16F600396F26 /* Build configuration list for PBXProject "RCTMGL" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = C4D144341F4E16F600396F26; + productRefGroup = C4D1443E1F4E16F600396F26 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + C4D1443C1F4E16F600396F26 /* RCTMGL */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + C4D144391F4E16F600396F26 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + C4D144531F4E190C00396F26 /* MGLModule.m in Sources */, + C4D1444C1F4E178100396F26 /* RCTMGLMapView.m in Sources */, + C4D1444F1F4E181100396F26 /* RCTMGLMapViewManager.m in Sources */, + C4D144971F4E2F1100396F26 /* RCTConvert+Mapbox.m in Sources */, + C4D144421F4E16F600396F26 /* RCTMGL.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + C4D144441F4E16F600396F26 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.3; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + C4D144451F4E16F600396F26 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.3; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + C4D144471F4E16F600396F26 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)"; + HEADER_SEARCH_PATHS = "$(SRCROOT)/../../react-native/React/**"; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + C4D144481F4E16F600396F26 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + FRAMEWORK_SEARCH_PATHS = "$(SRCROOT)"; + HEADER_SEARCH_PATHS = "$(SRCROOT)/../../react-native/React/**"; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + C4D144381F4E16F600396F26 /* Build configuration list for PBXProject "RCTMGL" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C4D144441F4E16F600396F26 /* Debug */, + C4D144451F4E16F600396F26 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + C4D144461F4E16F600396F26 /* Build configuration list for PBXNativeTarget "RCTMGL" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + C4D144471F4E16F600396F26 /* Debug */, + C4D144481F4E16F600396F26 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = C4D144351F4E16F600396F26 /* Project object */; +} diff --git a/ios/RCTMGL/MGLModule.h b/ios/RCTMGL/MGLModule.h new file mode 100644 index 0000000..902d488 --- /dev/null +++ b/ios/RCTMGL/MGLModule.h @@ -0,0 +1,13 @@ +// +// MGLModule.h +// RCTMGL +// +// Created by Nick Italiano on 8/23/17. +// Copyright © 2017 Mapbox Inc. All rights reserved. +// + +#import +#import + +@interface MGLModule : NSObject +@end diff --git a/ios/RCTMGL/MGLModule.m b/ios/RCTMGL/MGLModule.m new file mode 100644 index 0000000..9324e4c --- /dev/null +++ b/ios/RCTMGL/MGLModule.m @@ -0,0 +1,33 @@ +// +// MGLModule.m +// RCTMGL +// +// Created by Nick Italiano on 8/23/17. +// Copyright © 2017 Mapbox Inc. All rights reserved. +// + +#import "MGLModule.h" +@import Mapbox; + +@implementation MGLModule + +RCT_EXPORT_MODULE(); + +RCT_EXPORT_METHOD(setAccessToken:(NSString *)accessToken) +{ + [MGLAccountManager setAccessToken:accessToken]; +} + +RCT_EXPORT_METHOD(getAccessToken:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) +{ + NSString *accessToken = MGLAccountManager.accessToken; + + if (accessToken != nil) { + resolve(accessToken); + return; + } + + reject(@"missing_access_token", @"No access token has been set", nil); +} + +@end diff --git a/ios/RCTMGL/RCTConvert+Mapbox.h b/ios/RCTMGL/RCTConvert+Mapbox.h new file mode 100644 index 0000000..da34b5a --- /dev/null +++ b/ios/RCTMGL/RCTConvert+Mapbox.h @@ -0,0 +1,16 @@ +// +// RCTConvert+Mapbox.h +// RCTMGL +// +// Created by Nick Italiano on 8/23/17. +// Copyright © 2017 Mapbox Inc. All rights reserved. +// + +#import +#import + +@interface RCTConvert (Mapbox) + ++ (CLLocationCoordinate2D)GeoJSONPoint:(id)json; + +@end diff --git a/ios/RCTMGL/RCTConvert+Mapbox.m b/ios/RCTMGL/RCTConvert+Mapbox.m new file mode 100644 index 0000000..318b956 --- /dev/null +++ b/ios/RCTMGL/RCTConvert+Mapbox.m @@ -0,0 +1,32 @@ +// +// RCTConvert+Mapbox.m +// RCTMGL +// +// Created by Nick Italiano on 8/23/17. +// Copyright © 2017 Mapbox Inc. All rights reserved. +// + +#import "RCTConvert+Mapbox.h" + +@implementation RCTConvert (Mapbox) + ++ (CLLocationCoordinate2D)GeoJSONPoint:(id)json +{ + NSDictionary *point = [self NSDictionary:json]; + + if (![[point objectForKey:@"type"] isEqual: @"Point"]) { + return CLLocationCoordinate2DMake(0, 0); + } + + NSArray *coords = (NSArray*)[point objectForKey:@"coordinates"]; + if (coords == nil || coords.count < 2) { + return CLLocationCoordinate2DMake(0, 0); + } + + double lat = [[coords objectAtIndex:1] doubleValue]; + double lng = [[coords objectAtIndex:0] doubleValue]; + + return CLLocationCoordinate2DMake(lat, lng); +} + +@end diff --git a/ios/RCTMGL/RCTMGL.h b/ios/RCTMGL/RCTMGL.h new file mode 100644 index 0000000..3fd628f --- /dev/null +++ b/ios/RCTMGL/RCTMGL.h @@ -0,0 +1,13 @@ +// +// RCTMGL.h +// RCTMGL +// +// Created by Nick Italiano on 8/23/17. +// Copyright © 2017 Mapbox Inc. All rights reserved. +// + +#import + +@interface RCTMGL : NSObject + +@end diff --git a/ios/RCTMGL/RCTMGL.m b/ios/RCTMGL/RCTMGL.m new file mode 100644 index 0000000..a7972e2 --- /dev/null +++ b/ios/RCTMGL/RCTMGL.m @@ -0,0 +1,13 @@ +// +// RCTMGL.m +// RCTMGL +// +// Created by Nick Italiano on 8/23/17. +// Copyright © 2017 Mapbox Inc. All rights reserved. +// + +#import "RCTMGL.h" + +@implementation RCTMGL + +@end diff --git a/ios/RCTMGL/RCTMGLMapView.h b/ios/RCTMGL/RCTMGLMapView.h new file mode 100644 index 0000000..fe789ff --- /dev/null +++ b/ios/RCTMGL/RCTMGLMapView.h @@ -0,0 +1,22 @@ +// +// RCTMGLMapView.h +// RCTMGL +// +// Created by Nick Italiano on 8/23/17. +// Copyright © 2017 Mapbox Inc. All rights reserved. +// + +#import +@import Mapbox; + +@interface RCTMGLMapView : MGLMapView + +@property (nonatomic, assign) BOOL animated; +@property (nonatomic, assign) NSDictionary *reactCenterCoordinate; +@property (nonatomic, assign) NSString *reactStyleURL; + +@property (nonatomic, assign) double heading; +@property (nonatomic, assign) double pitch; +@property (nonatomic, assign) double reactZoomLevel; + +@end diff --git a/ios/RCTMGL/RCTMGLMapView.m b/ios/RCTMGL/RCTMGLMapView.m new file mode 100644 index 0000000..e5c3bec --- /dev/null +++ b/ios/RCTMGL/RCTMGLMapView.m @@ -0,0 +1,84 @@ +// +// RCTMGLMapView.m +// RCTMGL +// +// Created by Nick Italiano on 8/23/17. +// Copyright © 2017 Mapbox Inc. All rights reserved. +// + +#import "RCTMGLMapView.h" +#import "RCTConvert+Mapbox.h" + +@implementation RCTMGLMapView +{ + NSDictionary *_mapStyleURLS; +} + +- (instancetype)init +{ + if (self = [super init]) { + _mapStyleURLS = @{ + @"mapbox-streets": MGLStyle.streetsStyleURL, + @"mapbox-dark": MGLStyle.darkStyleURL, + @"mapbox-light": MGLStyle.lightStyleURL, + @"mapbox-outdoors": MGLStyle.outdoorsStyleURL, + @"mapbox-satellite": MGLStyle.satelliteStyleURL + }; + } + + return self; +} + +- (void)setAnimated:(BOOL)animated +{ + _animated = animated; +} + +- (void)setReactCenterCoordinate:(NSDictionary *)reactCenterCoordinate +{ + _reactCenterCoordinate = reactCenterCoordinate; + [self setCenterCoordinate:[RCTConvert GeoJSONPoint:_reactCenterCoordinate] animated:_animated]; +} + +- (void)setReactStyleURL:(NSString *)reactStyleURL +{ + _reactStyleURL = reactStyleURL; + self.styleURL = [self getStyleURLFromKey:_reactStyleURL]; +} + +- (void)setHeading:(double)heading +{ + _heading = heading; + MGLMapCamera *camera = [self.camera copy]; + camera.heading = _heading; + [self setCamera:camera animated: _animated]; +} + +- (void)setPitch:(double)pitch +{ + _pitch = pitch; + MGLMapCamera *camera = [self.camera copy]; + camera.pitch = _pitch; + [self setCamera:camera animated:_animated]; +} + +- (void)setReactZoomLevel:(double)reactZoomLevel +{ + _reactZoomLevel = reactZoomLevel; + self.zoomLevel = reactZoomLevel; +} + +- (NSURL*) getStyleURLFromKey:(NSString *)styleKey +{ + NSString *styleURL = [_mapStyleURLS objectForKey:styleKey]; + + // mapbox base style urls + if (styleURL != nil) { + return (NSURL*)styleURL; + } + + // custom style url + return [NSURL URLWithString:styleKey]; +} + +@end diff --git a/ios/RCTMGL/RCTMGLMapViewManager.h b/ios/RCTMGL/RCTMGLMapViewManager.h new file mode 100644 index 0000000..250ca64 --- /dev/null +++ b/ios/RCTMGL/RCTMGLMapViewManager.h @@ -0,0 +1,13 @@ +// +// RCTMGLMapViewManager.h +// RCTMGL +// +// Created by Nick Italiano on 8/23/17. +// Copyright © 2017 Mapbox Inc. All rights reserved. +// + +#import + +@interface RCTMGLMapViewManager : RCTViewManager + +@end diff --git a/ios/RCTMGL/RCTMGLMapViewManager.m b/ios/RCTMGL/RCTMGLMapViewManager.m new file mode 100644 index 0000000..e5e262c --- /dev/null +++ b/ios/RCTMGL/RCTMGLMapViewManager.m @@ -0,0 +1,35 @@ +// +// RCTMGLMapViewManager.m +// RCTMGL +// +// Created by Nick Italiano on 8/23/17. +// Copyright © 2017 Mapbox Inc. All rights reserved. +// + +#import "RCTMGLMapViewManager.h" +#import "RCTMGLMapView.h" +#import "RCTConvert+Mapbox.h" + +@interface RCTMGLMapViewManager() +@end + + +@implementation RCTMGLMapViewManager + +RCT_EXPORT_MODULE() + +- (UIView *)view +{ + RCTMGLMapView *mapView = [RCTMGLMapView new]; + mapView.delegate = self; + return mapView; +} + +RCT_EXPORT_VIEW_PROPERTY(animated, BOOL) +RCT_REMAP_VIEW_PROPERTY(centerCoordinate, reactCenterCoordinate, NSDictionary) +RCT_REMAP_VIEW_PROPERTY(styleURL, reactStyleURL, NSString) +RCT_EXPORT_VIEW_PROPERTY(heading, double) +RCT_EXPORT_VIEW_PROPERTY(pitch, double) +RCT_REMAP_VIEW_PROPERTY(zoomLevel, reactZoomLevel, double) + +@end diff --git a/react-native-mapbox-gl.podspec b/react-native-mapbox-gl.podspec new file mode 100644 index 0000000..77b954c --- /dev/null +++ b/react-native-mapbox-gl.podspec @@ -0,0 +1,18 @@ +require 'json' + +package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) + +Pod::Spec.new do |s| + s.name = "react-native-mapbox-gl" + s.summary = "React Native Component for Mapbox GL" + s.version = package['version'] + s.authors = { "Nick Italiano" => "ni6@njit.edu" } + s.homepage = "https://github.com/mapbox/react-native-mapbox-gl#readme" + s.license = "MIT" + s.platform = :ios, "8.0" + s.source = { :git => "https://github.com/mapbox/react-native-mapbox-gl.git" } + s.source_files = "lib/ios/RCTMGL/**/*.{h,m}" + + s.dependency 'React' + s.dependency 'Mapbox', '3.6' +end