mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Added reduced motion
This commit is contained in:
52
src/utils/accessibility/AccessibilityManager.tsx
Normal file
52
src/utils/accessibility/AccessibilityManager.tsx
Normal file
@ -0,0 +1,52 @@
|
||||
import React, { createContext, useContext, useEffect, useState } from 'react'
|
||||
import { AccessibilityInfo } from 'react-native'
|
||||
|
||||
type ContextType = {
|
||||
reduceMotionEnabled: boolean
|
||||
}
|
||||
|
||||
const AccessibilityContext = createContext<ContextType>({
|
||||
reduceMotionEnabled: false
|
||||
})
|
||||
|
||||
export const useAccessibility = () => useContext(AccessibilityContext)
|
||||
|
||||
const AccessibilityManager: React.FC = ({ children }) => {
|
||||
const [reduceMotionEnabled, setReduceMotionEnabled] = useState(false)
|
||||
|
||||
const handleReduceMotionChanged = (reduceMotionEnabled: boolean) =>
|
||||
setReduceMotionEnabled(reduceMotionEnabled)
|
||||
|
||||
const loadReduceMotion = async () => {
|
||||
const reduceMotion = await AccessibilityInfo.isReduceMotionEnabled()
|
||||
setReduceMotionEnabled(reduceMotion)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
loadReduceMotion()
|
||||
|
||||
AccessibilityInfo.addEventListener(
|
||||
'reduceMotionChanged',
|
||||
handleReduceMotionChanged
|
||||
)
|
||||
|
||||
return () => {
|
||||
AccessibilityInfo.removeEventListener(
|
||||
'reduceMotionChanged',
|
||||
handleReduceMotionChanged
|
||||
)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<AccessibilityContext.Provider
|
||||
value={{
|
||||
reduceMotionEnabled
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</AccessibilityContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export default AccessibilityManager
|
Reference in New Issue
Block a user