688963954a
* docs: Use Light codeblocks theme * docs: Fix image align * fix pixels * fix: Adjust all images
38 lines
1.8 KiB
Plaintext
38 lines
1.8 KiB
Plaintext
---
|
|
id: lifecycle
|
|
title: Lifecycle
|
|
sidebar_label: Lifecycle
|
|
---
|
|
|
|
import useBaseUrl from '@docusaurus/useBaseUrl'
|
|
|
|
<div class="image-container">
|
|
<img width="283" src={useBaseUrl("img/example.png")} />
|
|
</div>
|
|
|
|
## The `isActive` prop
|
|
|
|
The Camera's `isActive` property can be used to _pause_ the session (`isActive={false}`) while still keeping the session "warm". This is more desirable than completely unmounting the camera, since _resuming_ the session (`isActive={true}`) will be **much faster** than re-mounting the camera view.
|
|
|
|
For example, you want to **pause the camera** when the user **navigates to another page** or **minimizes the app** since otherwise the camera continues to run in the background without the user seeing it, causing **significant battery drain**. Also, on iOS a green dot indicates the user that the camera is still active, possibly causing the user to raise privacy concerns. (See ["About the orange and green indicators in your iPhone status bar"](https://support.apple.com/en-us/HT211876))
|
|
|
|
For example, you might want to pause the Camera when the user minimizes the app ([`useAppState()`](https://github.com/react-native-community/hooks?tab=readme-ov-file#useappstate)) or navigates to a new screen ([`useIsFocused()`](https://reactnavigation.org/docs/use-is-focused/)):
|
|
|
|
```tsx
|
|
function App() {
|
|
const isFocused = useIsFocused()
|
|
const appState = useAppState()
|
|
const isActive = isFocused && appState === "active"
|
|
|
|
return <Camera {...props} isActive={isActive} />
|
|
}
|
|
```
|
|
|
|
## Interruptions
|
|
|
|
VisionCamera gracefully handles Camera interruptions such as incoming calls, phone overheating, a different app opening the Camera, etc., and will automatically resume the Camera once it becomes available again.
|
|
|
|
<br />
|
|
|
|
#### 🚀 Next section: [Camera Formats](formats)
|