zoontek / react-native-permissions

An unified permissions API for React Native on iOS, Android and Windows.
MIT License
4.04k stars 828 forks source link

Add documentation on what the `npx react-native setup-ios-permissions` actually does #799

Closed david-gettins closed 1 year ago

david-gettins commented 1 year ago

Why it is needed?

For projects that do not follow the standard React Native project structure e.g. nx/react-native it is not clear how to successfully set up for, and run the command.

I managed to figure this as described here where someone else had faced the same issue as me.

The command doesn't allow you to use arguments to specify the node_modules folder location.

Possible implementation

Include documentation for deeply nested ios folders.

OR

Add command arguments to the npx react-native setup-ios-permissions to allow consumers to specify folder locations.

Code sample

Unfortunately, I'm not sure how to make the command changes myself. But the documentation could read something like - maybe a little better than - how I described to someone on Stack Overflow.

david-gettins commented 1 year ago

Might be worth noting that nx/react-native symlinks the node_modules folder from the repository root into an app folder that could be many levels deep e.g. apps/mobile or apps/consumer/mobile and so on.

The command seems to follow it okay when you run it from the app folder.

zoontek commented 1 year ago

@david-gettins I published a beta with an alternative already. Instead of relying on a react native CLI command, you can call a ruby function in your Podfile, it achieves the same (updating the podspec source_files to include additional handlers), but it's IMHO a better fit (as it makes sense to run pod install when you update your Podfile, less when you update a reactNativePermissionsIOS config). I think it should also fix your issue (as there's no need to locate a reactNativePermissionsIOS.json / package.json, it's a function call arg now):

require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
+ require_relative '../node_modules/react-native-permissions/scripts/permissions_setup'

platform :ios, min_ios_version_supported
prepare_react_native_project!

+ setup_permissions([
+  'Camera',
+  'LocationWhenInUse',
+  'Microphone'
+ ])

More infos here: https://github.com/zoontek/react-native-permissions/pull/750#issuecomment-1674724112

To try it:

yarn add react-native-permissions@next
zoontek commented 1 year ago

@david-gettins Published a new beta with an update to latest version of react native for the example app + documentation now mention hoisting support: https://github.com/zoontek/react-native-permissions/tree/add-ruby-setup-script#ios

If you confirm that it works correctly with nx, I will publish 3.9.0 🙂

david-gettins commented 1 year ago

@david-gettins Published a new beta with an update to latest version of react native for the example app + documentation now mention hoisting support: https://github.com/zoontek/react-native-permissions/tree/add-ruby-setup-script#ios

If you confirm that it works correctly with nx, I will publish 3.9.0 🙂

Thank you. I'll give it a try on Monday and get back to you.

zoontek commented 1 year ago

@david-gettins Did you tried?

david-gettins commented 1 year ago

@david-gettins Did you tried?

Hi, sorry I had a busy few days. I'm on it this evening, though.

david-gettins commented 1 year ago

Given this a try and all seems to work well. Thank you for looking into this. I agree that this feels like a better way to do this as you mentioned in an earlier comment. I have added a pod install step to my npm prepare script to ensure this is set up correctly on new repo clones and node_modules changes.

I have added a comment to an answer I provided on StackOverflow to someone with a similar issue pointing to this conversation.

@zoontek will you be putting this in the next stable release and updating the docs for it?

zoontek commented 1 year ago

@david-gettins Yes, it will be in the next release (with a solution for https://github.com/zoontek/react-native-permissions/issues/710 too)

david-gettins commented 1 year ago

Excellent, thank you for making this change! I'll close the issue.

zoontek commented 1 year ago

It's published: https://github.com/zoontek/react-native-permissions/releases/tag/3.9.0