Skip to content

Commit

Permalink
User build_type to handle non use_frameworks
Browse files Browse the repository at this point in the history
  • Loading branch information
mfazekas committed Mar 5, 2021
1 parent c048645 commit ac9ab84
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 18 deletions.
4 changes: 4 additions & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ 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
# you should disable these next few lines.
use_flipper!
post_install do |installer|
flipper_post_install(installer)
$RNMBGL.post_install(installer)
end
end

Expand Down
6 changes: 2 additions & 4 deletions example/ios/RNMapboxGLExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 18 additions & 13 deletions ios/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 27 additions & 1 deletion react-native-mapbox-gl.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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']
Expand Down

0 comments on commit ac9ab84

Please sign in to comment.