npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

expo-app-lifecycle-plus

v0.1.0

Published

this module handle manage app states

Readme

Contributors Forks Stargazers Issues MIT License

About The Project

expo-app-lifecycle-plus exposes a single event channel and typed payloads so you can observe app state transitions consistently from JavaScript.

It is designed for real-world lifecycle analytics and debugging:

  • addListener((event) => ...) to stream lifecycle events
  • getCurrentState() to read current native state snapshot
  • iOS launch/scene signals and inferred termination support
  • Android process foreground/background and optional activity focus/blur

Built With

Getting Started

Prerequisites

  • Node.js LTS (20 or 22 recommended)
  • Expo / React Native app

Installation

Expo managed or prebuild:

npx expo install expo-app-lifecycle-plus

Bare React Native / Expo bare:

npm install expo-app-lifecycle-plus
# or
bun add expo-app-lifecycle-plus

Rebuild native apps after install:

npx expo run:android
npx expo run:ios

Usage

import * as Lifecycle from 'expo-app-lifecycle-plus';

const current = Lifecycle.getCurrentState();
console.log('current state', current);

const sub = Lifecycle.addListener((event) => {
  console.log('lifecycle event', event);
});

// later
sub.remove();

Example Event Payload

{
  "type": "foreground",
  "state": "foreground",
  "timestamp": 1700000000000,
  "platform": "ios"
}

Event Reference

Common Events

  • jsReload
  • coldStart
  • foreground
  • background

iOS Events

  • appLaunch
  • active
  • inactive
  • sceneActive
  • sceneInactive
  • willTerminate (best-effort; not guaranteed)
  • inferredTermination (emitted on next launch if app was previously backgrounded and appears to have been killed)

Android Events

  • focusActivity
  • blurActivity

Event Type

type LifecycleEvent = {
  type:
    | 'jsReload'
    | 'coldStart'
    | 'appLaunch'
    | 'inferredTermination'
    | 'foreground'
    | 'background'
    | 'active'
    | 'inactive'
    | 'willTerminate'
    | 'sceneActive'
    | 'sceneInactive'
    | 'focusActivity'
    | 'blurActivity';
  state: 'unknown' | 'foreground' | 'background' | 'active' | 'inactive';
  timestamp: number;
  platform: 'ios' | 'android';
  activity?: string;
  source?: 'didFinishLaunching' | 'observerStart';
  inferredFrom?: 'previousBackground';
  previousBackgroundTimestamp?: number;
  elapsedSinceBackgroundMs?: number;
};

API Reference

addListener(listener): EventSubscription

Subscribes to native lifecycle updates on onLifecycleEvent.

addListener(listener: (event: LifecycleEvent) => void): EventSubscription

getCurrentState(): LifecycleState

Returns current native lifecycle state snapshot.

getCurrentState(): 'unknown' | 'foreground' | 'background' | 'active' | 'inactive'

Platform Notes

  • willTerminate is not guaranteed on mobile OSes.
  • On iOS, app kills in background may not emit a terminate callback. Use inferredTermination for practical analytics.
  • On Android, process lifecycle (foreground/background) is generally the most reliable signal.
  • jsReload can happen during development due to fast refresh/reload and does not always mean a fresh process launch.

Troubleshooting

I only see inactive -> background -> foreground -> active

This is normal lifecycle flow on iOS when app moves between foreground/background.

willTerminate is not emitted

Expected on many real-device scenarios. Mobile OS may kill apps without firing terminate callbacks.

coldStart appears more than once in development

Development reload / fast refresh can recreate JS/runtime state. Use jsReload and appLaunch together to interpret startup behavior.

TypeScript import errors

Rebuild package and restart Metro:

npm run build

Contributing

PRs and issues are welcome.

  1. Fork the project
  2. Create branch
  3. Commit changes
  4. Push branch
  5. Open PR

License

MIT © Adem Hatay