diff --git a/example/ios/Podfile b/example/ios/Podfile index 55ec7d62a..2dcd8a70e 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -35,6 +35,9 @@ target 'RNMapboxGLExample' do use_native_modules! + pre_install do |installer| + $RNMBGL.pre_install(installer) + end # Enables Flipper. # # Note that if you have use_frameworks! enabled, Flipper will not work and @@ -42,6 +45,7 @@ target 'RNMapboxGLExample' do use_flipper! post_install do |installer| flipper_post_install(installer) + $RNMBGL.post_install(installer) end end diff --git a/example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj b/example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj index 3485bce02..102b12644 100644 --- a/example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj +++ b/example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj @@ -478,7 +478,6 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-RNMapboxGLExample/Pods-RNMapboxGLExample-resources.sh", - "${PODS_ROOT}/MapboxMobileEvents/MapboxMobileEvents/Resources/logger.html", "${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/AntDesign.ttf", "${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/Entypo.ttf", "${PODS_ROOT}/../../node_modules/react-native-vector-icons/Fonts/EvilIcons.ttf", @@ -499,7 +498,6 @@ ); name = "[CP] Copy Pods Resources"; outputPaths = ( - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/logger.html", "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/AntDesign.ttf", "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Entypo.ttf", "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/EvilIcons.ttf", @@ -552,13 +550,13 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-RNMapboxGLExample/Pods-RNMapboxGLExample-frameworks.sh", - "${PODS_ROOT}/@react-native-mapbox-gl-mapbox-static/dynamic/MapboxMobileEvents.framework", "${PODS_ROOT}/Mapbox-iOS-SDK/dynamic/Mapbox.framework", + "${BUILT_PRODUCTS_DIR}/MapboxMobileEvents/MapboxMobileEvents.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mapbox.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MapboxMobileEvents.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; diff --git a/ios/install.md b/ios/install.md index 9d9dac58b..31551e08c 100644 --- a/ios/install.md +++ b/ios/install.md @@ -2,34 +2,39 @@ ## React-Native > `0.60.0` -If you are using autolinking feature introduced in React-Native `0.60.0`, you just need `npm install @react-native-mapbox-gl/maps`, followed by `pod install` from the `ios` directory. +If you are using autolinking feature introduced in React-Native `0.60.0`, you just need `npm install @react-native-mapbox-gl/maps`, -## Using CocoaPods - -To install with CocoaPods, add the following to your `Podfile`: +Add the following to your `ios/Podfile`: ```ruby - # Mapbox - pod 'react-native-mapbox-gl', :path => '../node_modules/@react-native-mapbox-gl/maps' + pre_install do |installer| + $RNMBGL.pre_install(installer) + ... other pre install hooks + end +``` +```ruby + post_install do |installer| + $RNMBGL.post_install(installer) + ... other post install hooks + end ``` -Then run `pod install` and rebuild your project. -## use_frameworks! +followed by `pod install` from the `ios` directory. Please also add the pre/post install cocoapods hooks. -Mapbox normally [requires](https://github.com/mapbox/mapbox-gl-native-ios/issues/154) `use_frameworks!` in cocoapods. By default we implement a [workaround](https://github.com/react-native-mapbox-gl/maps/pull/714). In case you need `use_frameworks!` for some reason, you can use the mapbox pod without the workaround with the `DynamicLibrary` subspec: +## Using CocoaPods without autolink +To install with CocoaPods, add the following to your `Podfile`: ```ruby # Mapbox - pod 'react-native-mapbox-gl/DynamicLibrary', :path => '../node_modules/@react-native-mapbox-gl/maps' + pod 'react-native-mapbox-gl', :path => '../node_modules/@react-native-mapbox-gl/maps' - ... +``` - use_frameworks! +Then run `pod install` and rebuild your project. -``` ## Mapbox Maps SDK diff --git a/react-native-mapbox-gl.podspec b/react-native-mapbox-gl.podspec index 2d7ea256f..cceaa53b2 100644 --- a/react-native-mapbox-gl.podspec +++ b/react-native-mapbox-gl.podspec @@ -8,6 +8,32 @@ if ENV.has_key?("REACT_NATIVE_MAPBOX_MAPBOX_IOS_VERSION") puts "REACT_NATIVE_MAPBOX_MAPBOX_IOS_VERSION env is deprecated please use `$ReactNativeMapboxGLIOSVersion = \"#{rnmbgl_ios_version}\"`" end +TargetsToChangeToDynamic = ['MapboxMobileEvents'] + +$RNMBGL = Object.new + +def $RNMBGL.post_install(installer) + installer.pod_targets.each do |pod| + if TargetsToChangeToDynamic.include?(pod.name) + if pod.send(:build_type) != Pod::BuildType.dynamic_framework + pod.instance_variable_set(:@build_type,Pod::BuildType.dynamic_framework) + puts "* Changed #{pod.name} to `#{pod.send(:build_type)}`" + fail "Unable to change build_type" unless mobile_events_target.send(:build_type) == Pod::BuildType.dynamic_framework + end + end + end +end + +def $RNMBGL.pre_install(installer) + installer.aggregate_targets.each do |target| + target.pod_targets.select { |p| TargetsToChangeToDynamic.include?(p.name) }.each do |mobile_events_target| + mobile_events_target.instance_variable_set(:@build_type,Pod::BuildType.dynamic_framework) + puts "* Changed #{mobile_events_target.name} to #{mobile_events_target.send(:build_type)}" + fail "Unable to change build_type" unless mobile_events_target.send(:build_type) == Pod::BuildType.dynamic_framework + end + end +end + Pod::Spec.new do |s| s.name = "react-native-mapbox-gl" s.summary = "React Native Component for Mapbox GL" @@ -30,7 +56,7 @@ Pod::Spec.new do |s| s.default_subspecs= ['DynamicLibrary'] else s.subspec 'StaticLibraryFixer' do |sp| - s.dependency '@react-native-mapbox-gl-mapbox-static', rnmbgl_ios_version + # s.dependency '@react-native-mapbox-gl-mapbox-static', rnmbgl_ios_version end s.default_subspecs= ['DynamicLibrary', 'StaticLibraryFixer']