{"id":24543857,"url":"https://github.com/douglasjunior/react-native-applifecycle","last_synced_at":"2025-04-15T12:56:58.308Z","repository":{"id":234799939,"uuid":"789526939","full_name":"douglasjunior/react-native-applifecycle","owner":"douglasjunior","description":"⚛ Enhances the reliability of managing app lifecycles across iOS and Android platforms, ensuring consistent behavior regarding foreground and background states.","archived":false,"fork":false,"pushed_at":"2025-04-12T01:55:10.000Z","size":416,"stargazers_count":92,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T12:56:40.518Z","etag":null,"topics":["android","appstate","ios","lifecycle","react-native"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-native-applifecycle","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/douglasjunior.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"douglasjunior","patreon":"douglasjunior","custom":"paypal.me/douglasnassif"}},"created_at":"2024-04-20T19:54:08.000Z","updated_at":"2025-04-09T11:41:40.000Z","dependencies_parsed_at":"2024-04-20T20:49:10.448Z","dependency_job_id":"539334c2-6d60-452b-8f9c-0ced4a8818bf","html_url":"https://github.com/douglasjunior/react-native-applifecycle","commit_stats":null,"previous_names":["douglasjunior/react-native-appstate"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douglasjunior%2Freact-native-applifecycle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douglasjunior%2Freact-native-applifecycle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douglasjunior%2Freact-native-applifecycle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/douglasjunior%2Freact-native-applifecycle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/douglasjunior","download_url":"https://codeload.github.com/douglasjunior/react-native-applifecycle/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249076545,"owners_count":21208811,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","appstate","ios","lifecycle","react-native"],"created_at":"2025-01-22T20:15:19.943Z","updated_at":"2025-04-15T12:56:58.286Z","avatar_url":"https://github.com/douglasjunior.png","language":"TypeScript","funding_links":["https://github.com/sponsors/douglasjunior","https://patreon.com/douglasjunior","paypal.me/douglasnassif","https://www.patreon.com/douglasjunior","https://paypal.me/douglasnassif"],"categories":[],"sub_categories":[],"readme":"# React-Native App Lifecycle\n\n[![License MIT](https://img.shields.io/badge/licence-MIT-blue.svg)](https://github.com/douglasjunior/react-native-applifecycle/blob/master/LICENSE)\n[![npm version](https://img.shields.io/npm/v/react-native-applifecycle.svg)](https://www.npmjs.com/package/react-native-applifecycle)\n[![npm downloads](https://img.shields.io/npm/dt/react-native-applifecycle.svg)](https://www.npmjs.com/package/react-native-applifecycle?activeTab=versions)\n\n⚛ Enhances the reliability of managing app lifecycles across iOS and Android platforms, ensuring consistent behavior regarding `foreground` and `background` states.\n\nIt implements the [Lifecycle](https://developer.android.com/jetpack/androidx/releases/lifecycle) for **Android** and falls back to the [AppState](https://reactnative.dev/docs/appstate) for **iOS**.\n\n## Why Use This?\n\nThe original [AppState](https://reactnative.dev/docs/appstate) API provided by React Native behaves differently between Android and iOS, particularly regarding the `background` state:\n\n- On iOS, the `background` state signifies that the entire app is in the background.\n- On Android, the `background` state indicates that the React Native Activity is in the background, which might not necessarily mean the entire app is in the background.\n\nBy using `react-native-applifecycle`, you can handle these differences seamlessly across both platforms, ensuring that the state `background` will be dispatched only when the entire app is in background.\n\n## Install\n\nInstall dependency package\n```bash\nyarn add react-native-applifecycle\n```\nOr\n```bash\nnpm i -S react-native-applifecycle\n```\n\n## Usage\n\nThe App Lifecycle API is compatible with the original [AppState](https://reactnative.dev/docs/appstate).\n\n### Subscribing to the `change` listener:\n\n```tsx\nimport {AppLifecycle} from 'react-native-applifecycle';\n\nconst App = () =\u003e {\n\n  useEffect(() =\u003e {\n    const listener = AppLifecycle.addEventListener('change', state =\u003e {\n      // do something\n    });\n\n    return () =\u003e listener.remove();\n  }, []);\n\n  return \u003cView /\u003e;\n}\n\nexport default App;\n```\n\n### Getting the current state with `hook`:\n\n```tsx\nimport {useAppLifecycle} from 'react-native-applifecycle';\n\nconst App = () =\u003e {\n  const currentLifecycle = useAppLifecycle();\n\n  // do something\n\n  return \u003cView /\u003e;\n}\n\nexport default App;\n```\n\nFor more details, see the [Sample Project](https://github.com/douglasjunior/react-native-applifecycle/blob/main/Sample/App.tsx).\n\n## Lifecycle States\n\n- `active` - The app is running in the foreground\n- `background` - The app is running in the background. The user is either:\n    - in another app\n    - on the home screen\n- [iOS] `inactive` - This is a state that occurs when transitioning between foreground \u0026 background, and during periods of inactivity such as entering the multitasking view, opening the Notification Center or in the event of an incoming call.\n\nFor more information, see [React Native documentation](https://reactnative.dev/docs/appstate#app-states).\n\n## Events\n\n### `change`\n    \nThis event is received when the app state has changed. The listener is called with one of the current app state values.\n\n### `memoryWarning`, `focus`, `blur`, etc\n\nFalls back to [AppState](https://reactnative.dev/docs/appstate#events)\n\n## Methods\n\n### `addEventListener()`\n\n```ts\nstatic addEventListener(\n  type: AppStateEvent,\n  listener: (state: AppStateStatus) =\u003e void,\n): NativeEventSubscription;\n```\n\nSets up a function that will be called whenever the specified event type on Lifecycle occurs. Valid values for `eventType` are listed above. Returns the `EventSubscription`.\n\n## Properties\n\n### `currentState`\n\n```ts\nstatic currentState: AppStateStatus;\n```\n\n## Jest mock\n\n```js\njest.mock('react-native-applifecycle/dist/AppLifecycle', () =\u003e require('react-native-applifecycle/jest/AppLifecycleMock'));\n```\n\n## Contribute\n\nNew features, bug fixes and improvements are welcome! For questions and suggestions use the [issues](https://github.com/douglasjunior/react-native-applifecycle/issues).\n\n\u003ca href=\"https://www.patreon.com/douglasjunior\"\u003e\u003cimg src=\"http://i.imgur.com/xEO164Z.png\" alt=\"Become a Patron!\" width=\"200\" /\u003e\u003c/a\u003e\n[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://paypal.me/douglasnassif)\n\n## Star History\n\n[![Star History Chart](https://api.star-history.com/svg?repos=douglasjunior/react-native-applifecycle\u0026type=Date)](https://star-history.com/#douglasjunior/react-native-applifecycle)\n\n## License\n\n```\nThe MIT License (MIT)\n\nCopyright (c) 2024 Douglas Nassif Roma Junior\n```\n\nSee the full [license file](https://github.com/douglasjunior/react-native-applifecycle/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdouglasjunior%2Freact-native-applifecycle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdouglasjunior%2Freact-native-applifecycle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdouglasjunior%2Freact-native-applifecycle/lists"}