WhoBuilt

Adding modularity to your React Native library

Sep 22, 2023· 19 min· 1.1K views·Watch on YouTube

Speaker

Mathieu Acthernoene, main maintainer of React Native Permissions and an engineer at Swan, explains how he made the library’s permission code modular at React Native EU 2023.

Why permissions caused App Store problems

React Native Permissions checks and requests device permissions on iOS, Android, and Windows. On iOS, apps must describe why they use each permission, and reviewers may reject an app if its code can request permissions that the app does not need. Some users responded by maintaining forks with unwanted permission code removed.

Making permissions optional with CocoaPods

With React Native 0.60 and CocoaPods integration, Acthernoene first explored using subspecs to link only the needed permission files. Autolinking made that approach impractical, so the team tried separate pods for each permission, with a shared core exposing `check` and `request` methods. Xcode caching sometimes kept newly added permissions from being detected, while framework builds hid the files the core needed to inspect.

Replacing source detection with configuration

The separate pod approach created a difficult developer experience. The team built a React Native CLI plugin that changed the podspec to include selected permission files, but users had to rerun it after deleting `node_modules`, and package hoisting caused problems in monorepos.

Running setup through CocoaPods

To address those issues, Acthernoene rewrote the setup script in Ruby so CocoaPods could run it before installation. Developers load the script in the Podfile and call `setup_permissions`, which updates the library specs based on the chosen permissions. This removed the need to rerun the setup after deleting `node_modules` and fixed the hoisting issue.

Maintaining open source takes patience

Acthernoene says software that combines technologies and platforms may take several attempts to get right. He encourages users to be empathetic toward open source maintainers and contribute where they can, including documentation and issue follow-up.

Takeaways

  • Make optional platform features explicit so apps only include the code they need.
  • Check how build caching and framework packaging affect any file-based detection approach.
  • Put setup logic in the toolchain that can run it reliably, including after dependency changes.
  • Treat open source maintenance as human work, and contribute small fixes or documentation when possible.

Mentioned in this talk

Search inside this talk

What was claimed 10

Related talks