Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions docs/appstate.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ AppState is frequently used to determine the intent and proper behavior when han

### App States

- `active` - The app is running in the foreground
- `active` - The app is running in the foreground.
- `background` - The app is running in the background. The user is either:
- in another app
- on the home screen
- [Android] on another `Activity`, including temporary system activities such
- <div className="label android">Android</div> on another `Activity`, including temporary system activities such
as autofill credential pickers (even if launched by your app or the system)
- [iOS] `inactive` - This is a state that occurs when transitioning between foreground & background, and during periods of inactivity such as entering the multitasking view, opening the Notification Center or in the event of an incoming call.
- <div className="label ios">iOS</div> `inactive` - This is a state that occurs when transitioning between foreground/background, and during periods of inactivity such as entering the multitasking view, opening the Notification Center or in the event of an incoming call.
- <div className="label ios">iOS</div> `extension` - The app is running in an extension context.
- <div className="label ios">iOS</div> `unknown` - The current app state is not yet available.

For more information, see [Apple's documentation](https://developer.apple.com/documentation/uikit/app_and_scenes/managing_your_app_s_life_cycle)
For more information, see [Apple documentation](https://developer.apple.com/documentation/uikit/managing-your-app-s-life-cycle) and [Android documentation](https://developer.android.com/guide/components/activities/activity-lifecycle).

## Basic Usage
## Usage

To see the current state, you can check `AppState.currentState`, which will be kept up-to-date.

Expand Down Expand Up @@ -77,6 +79,23 @@ export default AppStateExample;

This example will only ever appear to say "Current state is: active" because the app is only visible to the user when in the `active` state. If you want to experiment with the code we recommend to use your own device instead of embedded preview.

### Hook

The `useAppState` hook returns the current app state and subscribes to state changes. When the state changes, the component that calls this hook re-renders.

```tsx title="useAppState Hook Example"
import {useAppState, Text} from 'react-native';

const AppStateHookExample = () => {
const appState = useAppState();
return <Text>Current state is: {appState}</Text>;
};

export default AppStateHookExample;
```

The hook returns one of the [app state values](#app-states). It returns `unknown` until `AppState` reports a recognized state.

---

# Reference
Expand Down Expand Up @@ -120,3 +139,9 @@ Sets up a function that will be called whenever the specified event type on AppS
```tsx
static currentState: AppStateStatus;
```

### `isAvailable`

```tsx
static isAvailable: boolean;
```
8 changes: 8 additions & 0 deletions website/src/css/customTheme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,14 @@ td .label {
}
}

ul,
ol {
.label {
padding: 0 8px;
line-height: 20px;
}
}

/*
Mark pages as "new" using href attribute:
- to show badge in all versions use "PAGEID"
Expand Down
Loading