CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-react-native-firebase--app

Core React Native Firebase implementation providing foundation for all Firebase services across iOS and Android platforms

Pending
Overview
Eval results
Files

utils.mddocs/

Utils

Platform utilities including file path constants, Google Play Services helpers, Firebase Test Lab detection, and cross-platform development utilities.

Capabilities

Utils Module Access

The Utils module provides platform-specific utilities and is available through both the traditional and modular APIs.

// Traditional API
import firebase from '@react-native-firebase/app';
const utils = firebase.utils();

// Direct import
import { utils } from '@react-native-firebase/app';
const utilsInstance = utils();

Test Lab Detection

Determines if the app is currently running inside a Firebase Test Lab environment.

/**
 * Returns true if this app is running inside a Firebase Test Lab environment
 * Android only - iOS always returns false
 */
interface Utils.Module {
  isRunningInTestLab: boolean;
}

Usage Examples:

import firebase from '@react-native-firebase/app';

const utils = firebase.utils();

if (utils.isRunningInTestLab) {
  console.log('Running in Firebase Test Lab');
  // Disable animations or enable test-specific behavior
} else {
  console.log('Running on real device or simulator');
}

Google Play Services Management

Comprehensive Google Play Services availability checking and resolution functionality for Android devices.

/**
 * Google Play Services availability status and management
 * Android only - iOS returns placeholder values
 */
interface Utils.Module {
  /** Current Play Services availability status */
  playServicesAvailability: PlayServicesAvailability;
  
  /** Gets current Play Services status */
  getPlayServicesStatus(): Promise<PlayServicesAvailability>;
  
  /** Prompts user to update Play Services */
  promptForPlayServices(): Promise<void>;
  
  /** Attempts to make Play Services available */
  makePlayServicesAvailable(): Promise<void>;
  
  /** Resolves Play Services errors via user interaction */
  resolutionForPlayServices(): Promise<void>;
  
  /** Logs information messages for debugging */
  logInfo(...args: any[]): void;
}

interface PlayServicesAvailability {
  status: PlayServicesAvailabilityStatusCodes;
  isAvailable: boolean;
  hasResolution: boolean | undefined;
  isUserResolvableError: boolean | undefined;
  error: string | undefined;
}

enum PlayServicesAvailabilityStatusCodes {
  SUCCESS = 0,
  SERVICE_MISSING = 1,
  SERVICE_VERSION_UPDATE_REQUIRED = 2,
  SERVICE_DISABLED = 3,
  SIGN_IN_REQUIRED = 4,
  INVALID_ACCOUNT = 5,
  RESOLUTION_REQUIRED = 6,
  NETWORK_ERROR = 7,
  INTERNAL_ERROR = 8,
  SERVICE_INVALID = 9,
  DEVELOPER_ERROR = 10,
  LICENSE_CHECK_FAILED = 11,
  CANCELED = 13,
  TIMEOUT = 14,
  INTERRUPTED = 15,
  API_UNAVAILABLE = 16,
  SIGN_IN_FAILED = 17,
  SERVICE_UPDATING = 18,
  SERVICE_MISSING_PERMISSION = 19,
  RESTRICTED_PROFILE = 20,
  DRIVE_EXTERNAL_STORAGE_REQUIRED = 1500,
}

Usage Examples:

import firebase from '@react-native-firebase/app';
import { Platform } from 'react-native';

const utils = firebase.utils();

if (Platform.OS === 'android') {
  // Check Play Services availability
  const availability = utils.playServicesAvailability;
  
  if (availability.isAvailable) {
    console.log('Google Play Services is available');
  } else {
    console.log('Google Play Services not available:', availability.error);
    
    if (availability.hasResolution) {
      try {
        // Try to resolve the issue
        await utils.resolutionForPlayServices();
        console.log('Play Services issue resolved');
      } catch (error) {
        console.log('Could not resolve Play Services issue');
      }
    }
  }
  
  // Get current status
  const status = await utils.getPlayServicesStatus();
  console.log('Play Services Status:', status.status);
  
  // Prompt user to update if needed
  if (status.status === 2) { // SERVICE_VERSION_UPDATE_REQUIRED
    await utils.promptForPlayServices();
  }
  
  // Log debugging information
  utils.logInfo('Play Services initialized successfully');
}

File Path Constants

Platform-specific file path constants for accessing device directories.

/**
 * File path constants for accessing device directories
 * Cross-platform with platform-specific availability
 */
interface Utils.FilePath {
  /** iOS only - Returns absolute path to applications main bundle */
  MAIN_BUNDLE: string;
  
  /** Returns absolute path to application specific cache directory */
  CACHES_DIRECTORY: string;
  
  /** Returns absolute path to users Documents directory */
  DOCUMENT_DIRECTORY: string;
  
  /** Android only - Returns path to external storage directory, null if unavailable */
  EXTERNAL_DIRECTORY: string | null;
  
  /** Android only - Returns path to external storage directory, null if unavailable */
  EXTERNAL_STORAGE_DIRECTORY: string | null;
  
  /** Returns absolute path to temporary directory */
  TEMP_DIRECTORY: string;
  
  /** Returns absolute path to apps library/resources directory */
  LIBRARY_DIRECTORY: string;
  
  /** Returns absolute path to pictures directory */
  PICTURES_DIRECTORY: string;
  
  /** Returns absolute path to movies directory */
  MOVIES_DIRECTORY: string;

  /** File type constant for regular files */
  FILE_TYPE_REGULAR: string;
  
  /** File type constant for directories */
  FILE_TYPE_DIRECTORY: string;
}

Usage Examples:

import firebase from '@react-native-firebase/app';
import { Platform } from 'react-native';

const utils = firebase.utils();
const filePaths = utils.FilePath;

// Cross-platform paths
console.log('Documents:', filePaths.DOCUMENT_DIRECTORY);
console.log('Cache:', filePaths.CACHES_DIRECTORY);
console.log('Temp:', filePaths.TEMP_DIRECTORY);

// Platform-specific paths
if (Platform.OS === 'ios') {
  console.log('Main Bundle:', filePaths.MAIN_BUNDLE);
} else if (Platform.OS === 'android') {
  if (filePaths.EXTERNAL_DIRECTORY) {
    console.log('External Storage:', filePaths.EXTERNAL_DIRECTORY);
  } else {
    console.log('External storage not available');
  }
}

// File operations using paths
const documentPath = `${filePaths.DOCUMENT_DIRECTORY}/myfile.txt`;
const cachePath = `${filePaths.CACHES_DIRECTORY}/cached_data.json`;

Utils Static Properties

Static utilities and constants available without instantiating the utils module.

/**
 * Static utilities available on the utils module
 */
interface Utils.Statics {
  FilePath: Utils.FilePath;
}

// Access via firebase.utils.FilePath (static)
import firebase from '@react-native-firebase/app';
const staticFilePaths = firebase.utils.FilePath;

Platform Considerations

iOS Behavior

  • isRunningInTestLab: Always returns false
  • playServicesAvailability: Returns { isAvailable: true, status: 0 }
  • Google Play Services methods: All return resolved promises with no action
  • MAIN_BUNDLE: Available with path to app bundle
  • External storage paths: Return null

Android Behavior

  • isRunningInTestLab: Returns actual Test Lab detection status
  • playServicesAvailability: Returns real Google Play Services status
  • Google Play Services methods: Perform actual system interactions
  • MAIN_BUNDLE: Not available (returns null)
  • External storage paths: Return actual paths if available

Web/Other Platforms

  • File paths: Return empty object {} (no native file system access)
  • Google Play Services: Return iOS-style placeholder values
  • Test Lab detection: Returns false

Complete Usage Example

import firebase from '@react-native-firebase/app';
import { Platform } from 'react-native';

class UtilsManager {
  private utils = firebase.utils();
  
  async initialize() {
    // Check Test Lab environment
    if (this.utils.isRunningInTestLab) {
      console.log('Configuring for Test Lab environment');
      // Disable animations, enable test mode, etc.
    }
    
    // Handle Play Services on Android
    if (Platform.OS === 'android') {
      await this.checkPlayServices();
    }
    
    // Set up file paths
    this.setupFilePaths();
  }
  
  private async checkPlayServices() {
    const availability = this.utils.playServicesAvailability;
    
    if (!availability.isAvailable) {
      console.warn('Google Play Services not available');
      
      if (availability.hasResolution) {
        try {
          await this.utils.makePlayServicesAvailable();
          console.log('Play Services made available');
        } catch (error) {
          console.error('Failed to make Play Services available:', error);
        }
      }
    }
  }
  
  private setupFilePaths() {
    const paths = this.utils.FilePath;
    
    // Configure app-specific paths
    this.documentPath = paths.DOCUMENT_DIRECTORY;
    this.cachePath = paths.CACHES_DIRECTORY;
    this.tempPath = paths.TEMP_DIRECTORY;
    
    console.log('File paths configured:', {
      documents: this.documentPath,
      cache: this.cachePath,
      temp: this.tempPath
    });
  }
}

// Usage
const utilsManager = new UtilsManager();
await utilsManager.initialize();

Install with Tessl CLI

npx tessl i tessl/npm-react-native-firebase--app

docs

app-management.md

configuration.md

index.md

native-integration.md

utils.md

tile.json