Repository: expo/expo
File: packages/expo-media-library/src/MediaLibrary.ts (TypeScript)

Code before:
  return await MediaLibrary.getPermissionsAsync(writeOnly);
}

// @needsAudit
/**
 * Check or request permissions to access the media library.
 * This uses both `requestPermissionsAsync` and `getPermissionsAsync` to interact with the permissions.
 *
 * @example
 * ```ts
 * const [permissionResponse, requestPermission] = MediaLibrary.usePermissions();
 * ```
 */
export const usePermissions = createPermissionHook<
  PermissionResponse,
  { writeOnly?: boolean; granularPermissions?: GranularPermission[] }
>({
  // TODO(cedric): permission requesters should have an options param or a different requester
  getMethod: (options) => getPermissionsAsync(options?.writeOnly, options?.granularPermissions),
  requestMethod: (options) =>
    requestPermissionsAsync(options?.writeOnly, options?.granularPermissions),
});

// @needsAudit
/**
 * __Available only on iOS >= 14 and Android >= 14.__ Allows the user to update the assets that your app has access to.
 * The system modal is only displayed if the user originally allowed only `limited` access to their
 * media library, otherwise this method is a no-op.
 * @return A promise that either rejects if the method is unavailable, or resolves to `void`.
 * > __Note:__ This method doesn't inform you if the user changes which assets your app has access to.
 * That information is only exposed by iOS, and to obtain it, you need to subscribe for updates to the user's media library using [addListener(listener)](#medialibraryaddlistenerlistener).
 * If `hasIncrementalChanges` is `false`, the user changed their permissions.
 */
export async function presentPermissionsPickerAsync(
  mediaTypes: MediaTypeFilter[] = ['photo', 'video']
): Promise<void> {
  if (Platform.OS === 'android' && Platform.Version >= 34) {
    await MediaLibrary.requestPermissionsAsync(false, mediaTypes);
    return;
  }
  if (!MediaLibrary.presentPermissionsPickerAsync) {
    throw new UnavailabilityError('MediaLibrary', 'presentPermissionsPickerAsync');
  }
  return await MediaLibrary.presentPermissionsPickerAsync();
}

// @needsAudit
/**
 * Creates an asset from existing file. The most common use case is to save a picture taken by [Camera](./camera).
 * This method requires `CAMERA_ROLL` permission.
 *

Review comment (suggestion):
```suggestion
 * Allows the user to update the assets that your app has access to.
```

We can use the platform tags to indicate the required platform versions:
```
@platform android 14+
@platform ios 14+
```


In long term, we would like to show all supported platforms for every API entry. The process will be automated, based on platforms set for the page, but in cases like that we would need to add those params to overwrite the default value for the package anyway.

A bit more information about params we use in source comments:
* https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md#general-approach

Code after:

// @needsAudit
/**
 * Check or request permissions to access the media library.
 * This uses both `requestPermissionsAsync` and `getPermissionsAsync` to interact with the permissions.
 *
 * @example
 * ```ts
 * const [permissionResponse, requestPermission] = MediaLibrary.usePermissions();
 * ```
 */
export const usePermissions = createPermissionHook<
  PermissionResponse,
  { writeOnly?: boolean; granularPermissions?: GranularPermission[] }
>({
  // TODO(cedric): permission requesters should have an options param or a different requester
  getMethod: (options) => getPermissionsAsync(options?.writeOnly, options?.granularPermissions),
  requestMethod: (options) =>
    requestPermissionsAsync(options?.writeOnly, options?.granularPermissions),
});

// @needsAudit
/**
 * Allows the user to update the assets that your app has access to.
 * The system modal is only displayed if the user originally allowed only `limited` access to their
 * media library, otherwise this method is a no-op.
 * @param mediaTypes Limits the type(s) of media that the user will be granting access to. By default, a list that shows both photos and videos is presented.
 *
 * @return A promise that either rejects if the method is unavailable, or resolves to `void`.
 * > __Note:__ This method doesn't inform you if the user changes which assets your app has access to.
 * That information is only exposed by iOS, and to obtain it, you need to subscribe for updates to the user's media library using [addListener(listener)](#medialibraryaddlistenerlistener).
 * If `hasIncrementalChanges` is `false`, the user changed their permissions.
 *
 * @platform android 14+
 * @platform ios 14+
 */
export async function presentPermissionsPickerAsync(
  mediaTypes: MediaTypeFilter[] = ['photo', 'video']
): Promise<void> {
  if (Platform.OS === 'android' && Platform.Version >= 34) {
    await MediaLibrary.requestPermissionsAsync(false, mediaTypes);
    return;
  }
  if (!MediaLibrary.presentPermissionsPickerAsync) {
    throw new UnavailabilityError('MediaLibrary', 'presentPermissionsPickerAsync');
  }
  return await MediaLibrary.presentPermissionsPickerAsync();
}

// @needsAudit
/**