or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

error-handling.mdevent-management.mdindex.mdnative-modules.mdnative-views.mdpermissions.mdplatform-utilities.mdutilities.md
tile.json

tessl/npm-unimodules--core

Deprecated compatibility wrapper that provides backward compatibility for applications migrating from legacy Unimodules infrastructure to Expo Modules API

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@unimodules/core@7.2.x

To install, run

npx @tessl/cli install tessl/npm-unimodules--core@7.2.0

index.mddocs/

@unimodules/core

@unimodules/core is a deprecated compatibility wrapper that provides backward compatibility for applications migrating from the legacy Unimodules infrastructure to the newer Expo Modules API. It serves as a bridge between old @unimodules/core architecture and modern expo-modules-core system, allowing existing React Native applications to continue functioning during migration.

⚠️ Deprecation Notice: This package is deprecated in favor of the expo package. Applications should migrate using the guide at https://expo.fyi/expo-modules-migration

Package Information

  • Package Name: @unimodules/core
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @unimodules/core
  • Main Dependency: expo-modules-core ~0.4.0

Core Imports

import { 
  EventEmitter, 
  NativeModulesProxy, 
  Platform,
  requireNativeViewManager,
  CodedError,
  UnavailabilityError,
  DeviceEventEmitter,
  Subscription,
  SyntheticPlatformEmitter,
  ProxyNativeModule,
  deprecate,
  // Permission system
  PermissionStatus,
  PermissionResponse,
  createPermissionHook
} from "@unimodules/core";

For CommonJS:

const { 
  EventEmitter, 
  NativeModulesProxy, 
  Platform,
  requireNativeViewManager,
  CodedError,
  UnavailabilityError,
  DeviceEventEmitter,
  Subscription,
  SyntheticPlatformEmitter,
  ProxyNativeModule,
  deprecate,
  PermissionStatus,
  PermissionResponse,
  createPermissionHook
} = require("@unimodules/core");

Basic Usage

import { 
  EventEmitter, 
  NativeModulesProxy, 
  Platform,
  CodedError 
} from "@unimodules/core";

// Platform detection
if (Platform.OS === 'ios') {
  console.log('Running on iOS');
}

// Access native modules
const MyNativeModule = NativeModulesProxy.MyModule;
if (MyNativeModule) {
  await MyNativeModule.someMethod();
}

// Event handling
const eventEmitter = new EventEmitter(MyNativeModule);
const subscription = eventEmitter.addListener('eventName', (data) => {
  console.log('Received event:', data);
});

// Clean up
subscription.remove();

Architecture

@unimodules/core provides essential infrastructure for React Native/Expo module development:

  • Module Proxy System: NativeModulesProxy provides dynamic access to native modules
  • Event System: EventEmitter handles native-to-JavaScript event communication
  • Platform Utilities: Extended platform detection and capability checking
  • View Integration: requireNativeViewManager for native UI components
  • Error Handling: Standardized error classes with error codes
  • Permission System: Complete permission management with React hooks

Capabilities

Event Management

Core event handling system for native module events with automatic listener lifecycle management.

class EventEmitter {
  constructor(nativeModule: NativeModule);
  addListener<T>(eventName: string, listener: (event: T) => void): Subscription;
  removeAllListeners(eventName: string): void;
  removeSubscription(subscription: Subscription): void;
  emit(eventName: string, ...params: any[]): void;
}

interface Subscription {
  remove: () => void;
}

Event Management

Native Module Access

Proxy system providing dynamic access to native modules with automatic method binding and error handling.

const NativeModulesProxy: { [moduleName: string]: ProxyNativeModule };

interface ProxyNativeModule {
  [propertyName: string]: any;
  addListener: (eventName: string) => void;
  removeListeners: (count: number) => void;
}

Native Module Access

Platform Utilities

Extended platform detection and capability checking beyond React Native's built-in Platform.

interface PlatformInterface {
  OS: PlatformOSType;
  select: <T>(specifics: { [platform in PlatformSelectOSType]?: T }) => T;
  isDOMAvailable: boolean;
  canUseEventListeners: boolean;
  canUseViewport: boolean;
  isAsyncDebugging: boolean;
}

const Platform: PlatformInterface;

Platform Utilities

Error Handling

Standardized error classes for consistent error handling across Expo modules.

class CodedError extends Error {
  code: string;
  info?: any;
  constructor(code: string, message: string);
}

class UnavailabilityError extends CodedError {
  constructor(moduleName: string, propertyName: string);
}

Error Handling

Permission Management

Complete permission system with React hooks for managing app permissions.

enum PermissionStatus {
  GRANTED = 'granted',
  UNDETERMINED = 'undetermined',
  DENIED = 'denied'
}

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

function createPermissionHook<Permission extends PermissionResponse, Options extends object>(
  methods: PermissionHookMethods<Permission, Options>
): (options?: PermissionHookOptions<Options>) => [Permission | null, () => Promise<Permission>, () => Promise<Permission>];

Permission Management

Native View Integration

Component creation utilities for integrating native UI components into React Native applications.

function requireNativeViewManager<P = any>(viewName: string): React.ComponentType<P>;

Native View Integration

Utilities

API deprecation utilities and additional event emitters for platform-specific functionality.

function deprecate(
  library: string, 
  deprecatedAPI: string, 
  options?: {
    replacement?: string;
    currentVersion?: string;
    versionToRemove?: string;
  }
): void;

const SyntheticPlatformEmitter: EventEmitter;
const DeviceEventEmitter: DeviceEventEmitterStatic;
const RCTDeviceEventEmitter: DeviceEventEmitterStatic; // @deprecated Use DeviceEventEmitter

Utilities

Types

type PlatformOSType = 'ios' | 'android' | 'windows' | 'macos' | 'web';
type PlatformSelectOSType = PlatformOSType | 'native' | 'electron' | 'default';
type PlatformSelect = <T>(specifics: { [platform in PlatformSelectOSType]?: T }) => T;
type PermissionExpiration = 'never' | number;

interface NativeModule {
  startObserving?: () => void;
  stopObserving?: () => void;
  addListener: (eventName: string) => void;
  removeListeners: (count: number) => void;
}

interface Subscription {
  remove: () => void;
}

interface ProxyNativeModule {
  [propertyName: string]: any;
  addListener: (eventName: string) => void;
  removeListeners: (count: number) => void;
}

interface DeviceEventEmitterStatic {
  addListener: (eventType: string, listener: (data: any) => void) => { remove: () => void };
  emit: (eventType: string, ...args: any[]) => void;
  removeAllListeners: (eventType: string) => void;
}