### Start Metro Server Source: https://github.com/douglasjunior/react-native-applifecycle/blob/main/Sample/README.md Starts Metro, the JavaScript bundler for React Native. This command should be run from the root of your React Native project. ```bash # using npm npm start # OR using Yarn yarn start ``` -------------------------------- ### Install react-native-applifecycle Source: https://github.com/douglasjunior/react-native-applifecycle/blob/main/README.md Installs the react-native-applifecycle package using either yarn or npm. ```bash yarn add react-native-applifecycle ``` ```bash npm i -S react-native-applifecycle ``` -------------------------------- ### Run React Native Application Source: https://github.com/douglasjunior/react-native-applifecycle/blob/main/Sample/README.md Launches your React Native application on an Android emulator or iOS simulator. Ensure the Metro server is running in a separate terminal. ```bash # For Android # using npm npm run android # OR using Yarn yarn android # For iOS # using npm npm run ios # OR using Yarn yarn ios ``` -------------------------------- ### Modify and Reload React Native App Source: https://github.com/douglasjunior/react-native-applifecycle/blob/main/Sample/README.md Instructions on how to modify your React Native application code and reload the changes on Android and iOS devices/simulators. ```bash # For Android: Press R twice or use Developer Menu (Ctrl+M or Cmd+M) # For iOS: Press Cmd+R in the iOS Simulator ``` -------------------------------- ### Get Current App Lifecycle State with Hook Source: https://github.com/douglasjunior/react-native-applifecycle/blob/main/README.md Utilizes the `useAppLifecycle` hook to get the current lifecycle state of the application. This hook simplifies state management for lifecycle events. ```tsx import {useAppLifecycle} from 'react-native-applifecycle'; const App = () => { const currentLifecycle = useAppLifecycle(); // do something return ; } ``` -------------------------------- ### Jest Mock for react-native-applifecycle Source: https://github.com/douglasjunior/react-native-applifecycle/blob/main/README.md Provides a Jest mock implementation for the react-native-applifecycle module, allowing for easier testing of components that depend on it. ```js jest.mock('react-native-applifecycle/dist/AppLifecycle', () => require('react-native-applifecycle/jest/AppLifecycleMock')); ``` -------------------------------- ### App Lifecycle API - addEventListener Method Source: https://github.com/douglasjunior/react-native-applifecycle/blob/main/README.md The `addEventListener` method allows setting up a listener for specified event types on the AppLifecycle. It takes an event type and a callback function that receives the current app state. ```ts static addEventListener( type: AppStateEvent, listener: (state: AppStateStatus) => void, ): NativeEventSubscription; ``` -------------------------------- ### App Lifecycle API - currentState Property Source: https://github.com/douglasjunior/react-native-applifecycle/blob/main/README.md The `currentState` property provides the current state of the application lifecycle. ```ts static currentState: AppStateStatus; ``` -------------------------------- ### Subscribe to App Lifecycle Change Listener Source: https://github.com/douglasjunior/react-native-applifecycle/blob/main/README.md Subscribes to the 'change' event from AppLifecycle to receive updates on the application's state. It's important to remove the listener when the component unmounts to prevent memory leaks. ```tsx import {AppLifecycle} from 'react-native-applifecycle'; const App = () => { useEffect(() => { const listener = AppLifecycle.addEventListener('change', state => { // do something }); return () => listener.remove(); }, []); return ; } export default App; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.