parent
4d8537bcd4
commit
4bba59790a
|
@ -24,6 +24,7 @@ import {
|
||||||
import {s} from '#/lib/styles'
|
import {s} from '#/lib/styles'
|
||||||
import {ThemeProvider} from '#/lib/ThemeContext'
|
import {ThemeProvider} from '#/lib/ThemeContext'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
|
import {Provider as A11yProvider} from '#/state/a11y'
|
||||||
import {Provider as MutedThreadsProvider} from '#/state/cache/thread-mutes'
|
import {Provider as MutedThreadsProvider} from '#/state/cache/thread-mutes'
|
||||||
import {Provider as DialogStateProvider} from '#/state/dialogs'
|
import {Provider as DialogStateProvider} from '#/state/dialogs'
|
||||||
import {Provider as InvitesStateProvider} from '#/state/invites'
|
import {Provider as InvitesStateProvider} from '#/state/invites'
|
||||||
|
@ -152,27 +153,29 @@ function App() {
|
||||||
* that is set up in the InnerApp component above.
|
* that is set up in the InnerApp component above.
|
||||||
*/
|
*/
|
||||||
return (
|
return (
|
||||||
<KeyboardProvider enabled={false} statusBarTranslucent={true}>
|
<A11yProvider>
|
||||||
<SessionProvider>
|
<KeyboardProvider enabled={false} statusBarTranslucent={true}>
|
||||||
<ShellStateProvider>
|
<SessionProvider>
|
||||||
<PrefsStateProvider>
|
<ShellStateProvider>
|
||||||
<InvitesStateProvider>
|
<PrefsStateProvider>
|
||||||
<ModalStateProvider>
|
<InvitesStateProvider>
|
||||||
<DialogStateProvider>
|
<ModalStateProvider>
|
||||||
<LightboxStateProvider>
|
<DialogStateProvider>
|
||||||
<I18nProvider>
|
<LightboxStateProvider>
|
||||||
<PortalProvider>
|
<I18nProvider>
|
||||||
<InnerApp />
|
<PortalProvider>
|
||||||
</PortalProvider>
|
<InnerApp />
|
||||||
</I18nProvider>
|
</PortalProvider>
|
||||||
</LightboxStateProvider>
|
</I18nProvider>
|
||||||
</DialogStateProvider>
|
</LightboxStateProvider>
|
||||||
</ModalStateProvider>
|
</DialogStateProvider>
|
||||||
</InvitesStateProvider>
|
</ModalStateProvider>
|
||||||
</PrefsStateProvider>
|
</InvitesStateProvider>
|
||||||
</ShellStateProvider>
|
</PrefsStateProvider>
|
||||||
</SessionProvider>
|
</ShellStateProvider>
|
||||||
</KeyboardProvider>
|
</SessionProvider>
|
||||||
|
</KeyboardProvider>
|
||||||
|
</A11yProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import {QueryProvider} from '#/lib/react-query'
|
||||||
import {Provider as StatsigProvider} from '#/lib/statsig/statsig'
|
import {Provider as StatsigProvider} from '#/lib/statsig/statsig'
|
||||||
import {ThemeProvider} from '#/lib/ThemeContext'
|
import {ThemeProvider} from '#/lib/ThemeContext'
|
||||||
import {logger} from '#/logger'
|
import {logger} from '#/logger'
|
||||||
|
import {Provider as A11yProvider} from '#/state/a11y'
|
||||||
import {Provider as MutedThreadsProvider} from '#/state/cache/thread-mutes'
|
import {Provider as MutedThreadsProvider} from '#/state/cache/thread-mutes'
|
||||||
import {Provider as DialogStateProvider} from '#/state/dialogs'
|
import {Provider as DialogStateProvider} from '#/state/dialogs'
|
||||||
import {Provider as InvitesStateProvider} from '#/state/invites'
|
import {Provider as InvitesStateProvider} from '#/state/invites'
|
||||||
|
@ -135,25 +136,27 @@ function App() {
|
||||||
* that is set up in the InnerApp component above.
|
* that is set up in the InnerApp component above.
|
||||||
*/
|
*/
|
||||||
return (
|
return (
|
||||||
<SessionProvider>
|
<A11yProvider>
|
||||||
<ShellStateProvider>
|
<SessionProvider>
|
||||||
<PrefsStateProvider>
|
<ShellStateProvider>
|
||||||
<InvitesStateProvider>
|
<PrefsStateProvider>
|
||||||
<ModalStateProvider>
|
<InvitesStateProvider>
|
||||||
<DialogStateProvider>
|
<ModalStateProvider>
|
||||||
<LightboxStateProvider>
|
<DialogStateProvider>
|
||||||
<I18nProvider>
|
<LightboxStateProvider>
|
||||||
<PortalProvider>
|
<I18nProvider>
|
||||||
<InnerApp />
|
<PortalProvider>
|
||||||
</PortalProvider>
|
<InnerApp />
|
||||||
</I18nProvider>
|
</PortalProvider>
|
||||||
</LightboxStateProvider>
|
</I18nProvider>
|
||||||
</DialogStateProvider>
|
</LightboxStateProvider>
|
||||||
</ModalStateProvider>
|
</DialogStateProvider>
|
||||||
</InvitesStateProvider>
|
</ModalStateProvider>
|
||||||
</PrefsStateProvider>
|
</InvitesStateProvider>
|
||||||
</ShellStateProvider>
|
</PrefsStateProvider>
|
||||||
</SessionProvider>
|
</ShellStateProvider>
|
||||||
|
</SessionProvider>
|
||||||
|
</A11yProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
import React from 'react'
|
||||||
|
import {AccessibilityInfo} from 'react-native'
|
||||||
|
import {isReducedMotion} from 'react-native-reanimated'
|
||||||
|
|
||||||
|
import {isWeb} from '#/platform/detection'
|
||||||
|
|
||||||
|
const Context = React.createContext({
|
||||||
|
reduceMotionEnabled: false,
|
||||||
|
screenReaderEnabled: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
export function useA11y() {
|
||||||
|
return React.useContext(Context)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||||
|
const [reduceMotionEnabled, setReduceMotionEnabled] = React.useState(() =>
|
||||||
|
isReducedMotion(),
|
||||||
|
)
|
||||||
|
const [screenReaderEnabled, setScreenReaderEnabled] = React.useState(false)
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const reduceMotionChangedSubscription = AccessibilityInfo.addEventListener(
|
||||||
|
'reduceMotionChanged',
|
||||||
|
enabled => {
|
||||||
|
setReduceMotionEnabled(enabled)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
const screenReaderChangedSubscription = AccessibilityInfo.addEventListener(
|
||||||
|
'screenReaderChanged',
|
||||||
|
enabled => {
|
||||||
|
setScreenReaderEnabled(enabled)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
;(async () => {
|
||||||
|
const [_reduceMotionEnabled, _screenReaderEnabled] = await Promise.all([
|
||||||
|
AccessibilityInfo.isReduceMotionEnabled(),
|
||||||
|
AccessibilityInfo.isScreenReaderEnabled(),
|
||||||
|
])
|
||||||
|
setReduceMotionEnabled(_reduceMotionEnabled)
|
||||||
|
setScreenReaderEnabled(_screenReaderEnabled)
|
||||||
|
})()
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
reduceMotionChangedSubscription.remove()
|
||||||
|
screenReaderChangedSubscription.remove()
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const ctx = React.useMemo(() => {
|
||||||
|
return {
|
||||||
|
reduceMotionEnabled,
|
||||||
|
/**
|
||||||
|
* Always returns true on web. For now, we're using this for mobile a11y,
|
||||||
|
* so we reset to false on web.
|
||||||
|
*
|
||||||
|
* @see https://github.com/necolas/react-native-web/discussions/2072
|
||||||
|
*/
|
||||||
|
screenReaderEnabled: isWeb ? false : screenReaderEnabled,
|
||||||
|
}
|
||||||
|
}, [reduceMotionEnabled, screenReaderEnabled])
|
||||||
|
|
||||||
|
return <Context.Provider value={ctx}>{children}</Context.Provider>
|
||||||
|
}
|
Loading…
Reference in New Issue