Command palette

@yasinsensoy/native

React Native · APIs and utilities

Permissions

Permission status, requesting and settings.

4 exports

Import

import { Permissions, usePermission } from "@yasinsensoy/native";

Permission status, requesting and settings.

NameTypeDescription
check(name: PermissionName) => Promise<PermissionStatus>Returns the status; shows no dialog.
checkMany<N extends PermissionName>(names: readonly N[]) => Promise<Record<N, PermissionStatus>>Status of several permissions.
request(name: PermissionName) => Promise<PermissionStatus>Requests the permission. If it is granted, limited, blocked or unavailable, the status is returned without showing a dialog.
requestMany<N extends PermissionName>(names: readonly N[]) => Promise<Record<N, PermissionStatus>>Requests several permissions in order.
openSettings() => Promise<void>Opens the app's system settings page (for blocked permissions).
isUsable(status: PermissionStatus | undefined) => booleangranted or limited: can work with the permission.

Watches a permission's status. The status is re-read when the app comes to the foreground (e.g. when the user returns from settings).

usePermission(name: PermissionName): UsePermissionResult

Permission status.

  • granted: granted.
  • limited: partially granted (selected photos, approximate location, provisional notifications).
  • undetermined: not asked yet; request shows a dialog.
  • denied: denied but can be asked again (Android).
  • blocked: cannot be asked again; can only be enabled in settings via openSettings.
  • unavailable: not on the device or not defined in the app (ui.config permissions).
type PermissionStatus = "granted" | "limited" | "undetermined" | "denied" | "blocked" | "unavailable"

Result of usePermission.

NameTypeDescription
statusPermissionStatus | undefinedThe last known status; undefined before the first check.
request() => Promise<PermissionStatus>Requests the permission; returns the new status.
check() => Promise<PermissionStatus>Reads the status again.
openSettings() => Promise<void>Opens the app settings.