Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
def DEFAULT_COMPILE_SDK_VERSION = 28
def DEFAULT_TARGET_SDK_VERSION = 28
def DEFAULT_SUPPORT_LIB_VERSION = "28.0.0"
def DEFAULT_MIN_SDK_VERSION = 16
def DEFAULT_MIN_SDK_VERSION = 21

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
Expand All @@ -14,6 +14,7 @@ android {
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)

defaultConfig {
minSdkVersion 21
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
resValue "string", "places_api_key", (System.env.RNGP_ANDROID_API_KEY ? "$System.env.RNGP_ANDROID_API_KEY" : (rootProject.findProperty("RNGP_ANDROID_API_KEY") ?: "INSERT_KEY_HERE"))
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,11 @@
"react": ">=15.4.0 || ^16.0.0-alpha",
"react-native": ">=0.40.0"
},
"devDependencies": {}
"devDependencies": {},
"rnpm": {
"commands": {
"prelink": "node_modules/react-native-google-places/scripts/pre-link.sh",
"postlink": "node_modules/react-native-google-places/scripts/post-link.sh"
}
}
}
70 changes: 70 additions & 0 deletions scripts/post-link-ios.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env ruby

require 'xcodeproj'
require 'tempfile'
require 'fileutils'

Dir.chdir('ios')

@podfile_path = Pathname.pwd + 'Podfile'
@pod_dep_arr = ['GooglePlaces', 'GoogleMaps', 'GooglePlacePicker']
@pod_dep = @pod_dep_arr.map{|dep| " pod '#{dep}'\n"}.join("")

@project_paths= Pathname.pwd.children.select { |pn| pn.extname == '.xcodeproj' }
raise 'No Xcode project found' unless @project_paths.length > 0
raise 'Multiple Xcode projects found' unless @project_paths.length == 1
project_path = @project_paths.first

project = Xcodeproj::Project.open(project_path)
main_target = project.targets.first

puts "Checking Podfile in iOS project #{@podfile_path}"


if File.exist? @podfile_path
puts 'Found an existing Podfile'
puts "Adding the following pod to Podfile\n#{@pod_dep}"
temp_file = Tempfile.new('Podfile_temp')

File.readlines(@podfile_path).each do |line|
if line =~ /pod\s'GooglePlaces'/
@pod_dep_arr.delete('GooglePlaces')
puts 'GooglePlaces pod is already added'
elsif line =~ /pod\s'GoogleMaps'/
@pod_dep_arr.delete('GoogleMaps')
puts 'GoogleMaps pod is already added'
elsif line =~ /pod\s'GooglePlacePicker'/
@pod_dep_arr.delete('GooglePlacePicker')
puts 'GooglePlacePicker pod is already added'
end
end

begin
escaped_target_name = main_target.name.gsub(/'/, "\\\\\'")
File.readlines(@podfile_path).each do |line|
temp_file.puts(line)
@pod_dep_arr.each do |dep|
temp_file.puts(" pod '#{dep}'") if line =~ /target\s+'#{escaped_target_name}'\s+do/
end
end
temp_file.close
FileUtils.mv(temp_file.path, @podfile_path)
ensure
temp_file.delete
end
else
puts 'Adding Podfile to iOS project'
podfile = ''

podfile << "# Uncomment the next line to define a global platform for your project\n# platform :ios, '9.0'\n"
podfile << "\ntarget '#{main_target.name.gsub(/'/, "\\\\\'")}' do\n"
podfile << @pod_dep
podfile << " inherit! :search_paths\n"
podfile << "end\n"
puts podfile
File.write(@podfile_path, podfile)
end

puts 'Installing Pods'

system 'pod install'
6 changes: 6 additions & 0 deletions scripts/post-link.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

if [[ "$(uname)" == "Darwin" ]]; then
ruby $(dirname "$0")/post-link-ios.rb
fi

15 changes: 15 additions & 0 deletions scripts/pre-link.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

if [[ "$(uname)" == "Darwin" ]]; then
echo "Preparing to link react-native-google-places for iOS"

echo "Checking CocoaPods..."
has_cocoapods=`which pod >/dev/null 2>&1`
if [ -z "$has_cocoapods" ]
then
echo "CocoaPods already installed"
else
echo "Installing CocoaPods..."
gem install cocoapods
fi
fi