-
-
Notifications
You must be signed in to change notification settings - Fork 1k
[android] fix talkback on pressable #4017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9536fcf
35814ae
bca566a
ddc7874
61bee1f
feb7499
03d6451
ef091ac
674cd20
f5fb841
11f7445
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,4 +56,7 @@ export default { | |
| flushOperations() { | ||
| // NO-OP | ||
| }, | ||
| isScreenReaderEnabled() { | ||
| // NO-OP | ||
| }, | ||
|
Comment on lines
+59
to
+61
|
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { Platform } from 'react-native'; | ||
| import { PressableEvent } from './PressableProps'; | ||
| import { StateDefinition } from './StateMachine'; | ||
| import { isScreenReaderEnabled } from '../../utils'; | ||
|
|
||
| export enum StateMachineEvent { | ||
| NATIVE_BEGIN = 'nativeBegin', | ||
|
|
@@ -29,6 +30,25 @@ function getAndroidStatesConfig( | |
| ]; | ||
| } | ||
|
|
||
| function getAndroidAccessibilityStatesConfig( | ||
| handlePressIn: (event: PressableEvent) => void, | ||
| handlePressOut: (event: PressableEvent) => void | ||
| ) { | ||
| return [ | ||
| { | ||
| eventName: StateMachineEvent.LONG_PRESS_TOUCHES_DOWN, | ||
| callback: handlePressIn, | ||
| }, | ||
| { | ||
| eventName: StateMachineEvent.NATIVE_BEGIN, | ||
| }, | ||
| { | ||
| eventName: StateMachineEvent.FINALIZE, | ||
| callback: handlePressOut, | ||
| }, | ||
| ]; | ||
| } | ||
|
|
||
| function getIosStatesConfig( | ||
| handlePressIn: (event: PressableEvent) => void, | ||
| handlePressOut: (event: PressableEvent) => void | ||
|
|
@@ -112,6 +132,9 @@ export function getStatesConfig( | |
| handlePressOut: (event: PressableEvent) => void | ||
| ): StateDefinition[] { | ||
| if (Platform.OS === 'android') { | ||
| if (isScreenReaderEnabled()) { | ||
| return getAndroidAccessibilityStatesConfig(handlePressIn, handlePressOut); | ||
| } | ||
| return getAndroidStatesConfig(handlePressIn, handlePressOut); | ||
|
Comment on lines
134
to
138
|
||
| } else if (Platform.OS === 'ios') { | ||
| return getIosStatesConfig(handlePressIn, handlePressOut); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| import { AccessibilityInfo } from 'react-native'; | ||
| import RNGestureHandlerModule from './RNGestureHandlerModule'; | ||
|
|
||
| export function toArray<T>(object: T | T[]): T[] { | ||
| if (!Array.isArray(object)) { | ||
| return [object]; | ||
|
|
@@ -93,3 +96,16 @@ export function deepEqual(obj1: any, obj2: any) { | |
| } | ||
|
|
||
| export const INT32_MAX = 2 ** 31 - 1; | ||
|
|
||
| let isScreenReaderEnabledCache: boolean | null = null; | ||
|
|
||
| AccessibilityInfo.addEventListener('screenReaderChanged', () => { | ||
| isScreenReaderEnabledCache = RNGestureHandlerModule.isScreenReaderEnabled(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need a new method in the module when there's one in React Native, and you can also just get the value from the event here? |
||
| }); | ||
|
|
||
| export function isScreenReaderEnabled(): boolean { | ||
| if (isScreenReaderEnabledCache === null) { | ||
| isScreenReaderEnabledCache = RNGestureHandlerModule.isScreenReaderEnabled(); | ||
| } | ||
| return isScreenReaderEnabledCache; | ||
|
Comment on lines
+106
to
+110
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we already have this defined in some utils or extensions file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here