Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

[config] permissions plugins #2871

Merged
merged 3 commits into from
Nov 19, 2020
Merged

Conversation

EvanBacon
Copy link
Contributor

Most packages will need a generic method for adding permissions, this provides that.

Example:

const withImagePicker: ConfigPlugin<{
  photoLibraryPermission: string;
  cameraPermission: string;
  microphonePermission: string;
}> = (
  config,
  { photoLibraryPermission, cameraPermission, microphonePermission }
) => {
  return withPlugins(config, [
    (c) =>
      IOSConfig.Permissions.withPermissions(c, {
        NSPhotoLibraryUsageDescription: photoLibraryPermission,
        NSCameraUsageDescription: cameraPermission,
        NSMicrophoneUsageDescription: microphonePermission,
      }),
    (c) =>
      AndroidConfig.Permissions.withPermissions(
        c,
        [
          "android.permission.CAMERA",
          "android.permission.READ_EXTERNAL_STORAGE",
          "android.permission.WRITE_EXTERNAL_STORAGE",
          !!microphonePermission && "android.permission.RECORD_AUDIO",
        ].filter(Boolean) as string[]
      ),
  ]);
};

const withAV: ConfigPlugin<{
  microphonePermission?: string;
}> = (config, { microphonePermission }) => {
  return withPlugins(config, [
    (c) =>
      IOSConfig.Permissions.withPermissions(c, {
        NSMicrophoneUsageDescription: microphonePermission ?? null,
      }),
    (c) =>
      AndroidConfig.Permissions.withPermissions(
        c,
        [!!microphonePermission && "android.permission.RECORD_AUDIO"].filter(
          Boolean
        ) as string[]
      ),
  ]);
};

@EvanBacon EvanBacon added the enhancement New feature or request label Nov 10, 2020
@EvanBacon EvanBacon self-assigned this Nov 10, 2020
@EvanBacon EvanBacon merged commit b09732b into master Nov 19, 2020
@EvanBacon EvanBacon deleted the @evanbacon/plugins/permissions-plugins branch November 19, 2020 16:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant