Import apps/android/src/ui/use-reduce-motion.ts
This commit is contained in:
parent
4457a08625
commit
458480a0f3
|
|
@ -0,0 +1,25 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
import { AccessibilityInfo } from 'react-native'
|
||||
|
||||
/**
|
||||
* System "remove animations" preference, kept live for the lifetime of the
|
||||
* caller. Shared by connection hero, chat motion and the sheet primitive so a
|
||||
* single implementation decides how motion degrades.
|
||||
*/
|
||||
export function useReduceMotion(): boolean {
|
||||
const [reduceMotion, setReduceMotion] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true
|
||||
void AccessibilityInfo.isReduceMotionEnabled().then(enabled => {
|
||||
if (mounted) setReduceMotion(enabled)
|
||||
})
|
||||
const subscription = AccessibilityInfo.addEventListener('reduceMotionChanged', setReduceMotion)
|
||||
return () => {
|
||||
mounted = false
|
||||
subscription.remove()
|
||||
}
|
||||
}, [])
|
||||
|
||||
return reduceMotion
|
||||
}
|
||||
Loading…
Reference in New Issue