Skip to content

Commit

Permalink
prepare_react_native_permissions -> setup_permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
zoontek committed Aug 11, 2023
1 parent 90c7e33 commit 51d97fa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 58 deletions.
22 changes: 21 additions & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@ require_relative '../node_modules/@react-native-community/cli-platform-ios/nativ

platform :ios, min_ios_version_supported
prepare_react_native_project!
prepare_react_native_permissions!

setup_permissions([
'AppTrackingTransparency',
'BluetoothPeripheral',
'Calendars',
'Camera',
'Contacts',
'FaceID',
'LocationAccuracy',
'LocationAlways',
'LocationWhenInUse',
'MediaLibrary',
'Microphone',
'Motion',
'Notifications',
'PhotoLibrary',
'PhotoLibraryAddOnly',
'Reminders',
'SpeechRecognition',
'StoreKit'
])

# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,6 @@ SPEC CHECKSUMS:
Yoga: 79dd7410de6f8ad73a77c868d3d368843f0c93e0
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

PODFILE CHECKSUM: 249b70e8c3b43b4e2575a0b5735341324ccda216
PODFILE CHECKSUM: 8497c4e99af6d07e91873f2f82e9bca5579e4347

COCOAPODS: 1.12.1
20 changes: 0 additions & 20 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,6 @@
"start": "react-native start",
"reinstall": "yarn clean && yarn install"
},
"reactNativePermissionsIOS": [
"AppTrackingTransparency",
"BluetoothPeripheral",
"Calendars",
"Camera",
"Contacts",
"FaceID",
"LocationAccuracy",
"LocationAlways",
"LocationWhenInUse",
"MediaLibrary",
"Microphone",
"Motion",
"Notifications",
"PhotoLibrary",
"PhotoLibraryAddOnly",
"Reminders",
"SpeechRecognition",
"StoreKit"
],
"dependencies": {
"react": "18.2.0",
"react-native": "0.71.4",
Expand Down
40 changes: 4 additions & 36 deletions scripts/permissions_setup.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,15 @@
require 'json'
require 'fileutils'

def pkg_dir(dir)
pkg_path = File.join(dir, 'package.json')

if File.exist?(pkg_path)
dir
else
parent_dir = File.expand_path('..', dir)

if parent_dir != dir
pkg_dir(parent_dir)
end
end
end

def log_warning(message)
puts "[Permissions] #{message}"
end

def prepare_react_native_permissions!
config_key = 'reactNativePermissionsIOS'

module_dir = File.expand_path('..', __dir__)
root_dir = pkg_dir(Dir.pwd) || Dir.pwd
pkg_path = File.join(root_dir, 'package.json')
json_path = File.join(root_dir, "#{config_key}.json")

config = JSON.parse(File.read(pkg_path))[config_key]

if !config && File.exist?(json_path)
text = File.read(json_path)
config = JSON.parse(text)
end

if !config
return log_warning("No #{config_key} config found")
end

unless config.is_a?(Array)
return log_warning("Invalid #{config_key} config")
def setup_permissions(config)
if config.nil? || !config.is_a?(Array)
return log_warning("Invalid config argument")
end

module_dir = File.expand_path('..', __dir__)
ios_dir = File.join(module_dir, 'ios')
ios_dirents = Dir.entries(ios_dir).map { |entry| File.join(ios_dir, entry) }

Expand Down

0 comments on commit 51d97fa

Please sign in to comment.