hardened camera mounting handling

This commit is contained in:
Christopher Sanden
2026-03-19 16:15:37 +01:00
parent 63e65001e2
commit 57daa96be6
5 changed files with 434 additions and 12 deletions

View File

@@ -0,0 +1,38 @@
import { useIsFocused } from "@react-navigation/native"
import { useCallback, useEffect, useRef } from "react"
export function usePickerLifecycleGuard() {
const isFocused = useIsFocused()
const isMountedRef = useRef(true)
const isPickerActiveRef = useRef(false)
useEffect(() => {
return () => {
isMountedRef.current = false
isPickerActiveRef.current = false
}
}, [])
const isScreenActive = useCallback(() => {
return isMountedRef.current && isFocused
}, [isFocused])
const tryBeginPicker = useCallback(() => {
if (isPickerActiveRef.current) {
return false
}
isPickerActiveRef.current = true
return true
}, [])
const endPicker = useCallback(() => {
isPickerActiveRef.current = false
}, [])
return {
endPicker,
isScreenActive,
tryBeginPicker,
}
}