CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-expo-permissions

Deprecated centralized permissions API for React Native and Expo applications

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Expo Permissions

Expo Permissions is a deprecated centralized permissions API for React Native and Expo applications. It provides a unified interface to request and check various device permissions including camera, media library, location, notifications, contacts, calendar, audio recording, and motion sensors across iOS, Android, and web platforms.

⚠️ Deprecation Notice: This package has been deprecated in favor of requesting permissions directly from individual Expo modules (like expo-camera, expo-location) that use these permissions.

Package Information

  • Package Name: expo-permissions
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install expo-permissions
  • Peer Dependency: Requires expo as peer dependency

Core Imports

import { getAsync, askAsync, usePermissions, CAMERA, MEDIA_LIBRARY, LOCATION_FOREGROUND } from "expo-permissions";

For CommonJS:

const { getAsync, askAsync, usePermissions, CAMERA, MEDIA_LIBRARY, LOCATION_FOREGROUND } = require("expo-permissions");

Basic Usage

import { getAsync, askAsync, CAMERA, MEDIA_LIBRARY } from "expo-permissions";

// Check permission status
const cameraPermission = await getAsync(CAMERA);
console.log(cameraPermission.granted); // boolean

// Request permissions from user
const permissions = await askAsync(CAMERA, MEDIA_LIBRARY);
if (permissions.granted) {
  // All requested permissions granted
  console.log("All permissions granted");
} else {
  // Some permissions denied or undetermined
  console.log("Permissions status:", permissions.status);
}

Architecture

Expo Permissions is built around several key components:

  • Permission Request Functions: Core async functions (getAsync, askAsync) for checking and requesting permissions
  • React Integration: usePermissions hook for declarative permission management in React components
  • Permission Constants: Predefined constants for all supported permission types
  • Type System: Complete TypeScript definitions with permission status, response types, and platform-specific details
  • Permission Coalescing: Logic to combine multiple permission requests into unified responses
  • Platform Abstraction: Unified API that handles iOS, Android, and web platform differences internally

Capabilities

Permission Management

Core functions for checking and requesting device permissions with unified cross-platform API and deprecation warnings.

function getAsync(...types: PermissionType[]): Promise<PermissionResponse>;
function askAsync(...types: PermissionType[]): Promise<PermissionResponse>;

Permission Management

React Hooks Integration

React hook for declarative permission management with automatic status fetching and lifecycle handling.

function usePermissions(
  type: PermissionType | PermissionType[],
  options?: PermissionsOptions
): [PermissionResponse | undefined, () => Promise<void>, () => Promise<void>];

interface PermissionsOptions {
  ask?: boolean;
  get?: boolean;
}

React Hooks

Permission Types

type PermissionType =
  | 'camera'
  | 'mediaLibrary'
  | 'mediaLibraryWriteOnly'
  | 'audioRecording'
  | 'locationForeground'
  | 'locationBackground'
  | 'userFacingNotifications'
  | 'notifications'
  | 'contacts'
  | 'calendar'
  | 'reminders'
  | 'motion'
  | 'systemBrightness'
  | 'location'  // deprecated
  | 'cameraRoll'; // deprecated

Permission Constants

// Active constants
const CAMERA = "camera";
const MEDIA_LIBRARY = "mediaLibrary";
const MEDIA_LIBRARY_WRITE_ONLY = "mediaLibraryWriteOnly";
const AUDIO_RECORDING = "audioRecording";
const LOCATION_FOREGROUND = "locationForeground";
const LOCATION_BACKGROUND = "locationBackground";
const USER_FACING_NOTIFICATIONS = "userFacingNotifications";
const NOTIFICATIONS = "notifications";
const CONTACTS = "contacts";
const CALENDAR = "calendar";
const REMINDERS = "reminders";
const SYSTEM_BRIGHTNESS = "systemBrightness";
const MOTION = "motion";

// Deprecated constants
const CAMERA_ROLL = MEDIA_LIBRARY; // @deprecated Use MEDIA_LIBRARY or MEDIA_LIBRARY_WRITE_ONLY
const LOCATION = "location"; // @deprecated Use LOCATION_FOREGROUND or LOCATION_BACKGROUND

Core Types

interface PermissionResponse {
  status: PermissionStatus;
  expires: PermissionExpiration;
  granted: boolean;
  canAskAgain: boolean;
  permissions: PermissionMap;
}

interface PermissionMap {
  [permissionType: string]: PermissionInfo;
}

interface PermissionInfo {
  status: PermissionStatus;
  expires: PermissionExpiration;
  granted: boolean;
  canAskAgain: boolean;
  accessPrivileges?: 'all' | 'limited' | 'none'; // iOS only - Media Library
  scope?: 'whenInUse' | 'always' | 'none';
  android?: PermissionDetailsLocationAndroid;
}

interface PermissionDetailsLocationAndroid {
  accuracy: 'fine' | 'coarse' | 'none';
}

// The following types are imported from 'expo-modules-core':

enum PermissionStatus {
  /** User has granted the permission. */
  GRANTED = 'granted',
  /** User hasn't granted or denied the permission yet. */
  UNDETERMINED = 'undetermined',
  /** User has denied the permission. */
  DENIED = 'denied',
}

/** Permission expiration time. Currently, all permissions are granted permanently. */
type PermissionExpiration = 'never' | number;
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/expo-permissions@14.4.x
Publish Source
CLI
Badge
tessl/npm-expo-permissions badge