Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions package/react-native-better-maps.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@ require 'json'

package = JSON.parse(File.read(File.join(__dir__, 'package.json')))

def better_maps_podfile_properties
# Helpers are lambdas in local variables rather than top-level `def`s: CocoaPods
# evaluates a podspec with `eval`, and a method defined that way is not visible
# from inside the `Pod::Spec.new` block on every Ruby / CocoaPods combination
# (Ruby 4.0 + CocoaPods 1.17 raises `undefined method ... for module Pod`).
better_maps_podfile_properties = lambda do
installation_root = Pod::Config.instance.installation_root
return {} if installation_root.nil?
next {} if installation_root.nil?

podfile_properties_path = File.join(installation_root, 'Podfile.properties.json')
return {} unless File.exist?(podfile_properties_path)
next {} unless File.exist?(podfile_properties_path)

JSON.parse(File.read(podfile_properties_path))
rescue StandardError => e
properties = JSON.parse(File.read(podfile_properties_path))
next properties if properties.is_a?(Hash)

Pod::UI.warn "[react-native-better-maps] Podfile.properties.json is not a JSON object. iOS Google Maps provider will be disabled."
{}
# `::` is required: this file is evaluated inside module `Pod`, where a bare
# `StandardError` resolves to `Pod::StandardError` and would not catch JSON errors.
rescue ::StandardError => e
Pod::UI.warn "[react-native-better-maps] Failed to read Podfile.properties.json: #{e.message}. iOS Google Maps provider will be disabled."
{}
end

def better_maps_ios_google_provider_enabled?
# Must match IOS_GOOGLE_PROVIDER_PODFILE_PROPERTY in plugin/src/ios.ts
better_maps_podfile_properties['betterMaps.iosGoogleProvider'] == 'true'
end
# Must match IOS_GOOGLE_PROVIDER_PODFILE_PROPERTY in plugin/src/ios.ts
better_maps_ios_google_provider_enabled =
better_maps_podfile_properties.call['betterMaps.iosGoogleProvider'] == 'true'

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Pod::Spec.new do |s|
s.name = 'react-native-better-maps'
Expand Down Expand Up @@ -48,7 +57,7 @@ Pod::Spec.new do |s|

s.dependency 'React-jsi'
s.dependency 'React-callinvoker'
if better_maps_ios_google_provider_enabled?
if better_maps_ios_google_provider_enabled
s.dependency 'GoogleMaps'
end

Expand Down