Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.swmansion.gesturehandler.react

import android.content.Context
import android.view.accessibility.AccessibilityManager
import com.facebook.jni.HybridData
import com.facebook.proguard.annotations.DoNotStrip
import com.facebook.react.bridge.JSApplicationIllegalArgumentException
Expand Down Expand Up @@ -129,6 +131,15 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
isReanimatedAvailable = isAvailable
}

@ReactMethod
override fun isAccessibilityEnabled(): Boolean {
val accessibilityManager = reactApplicationContext.getSystemService(
Context.ACCESSIBILITY_SERVICE,
) as AccessibilityManager?

return accessibilityManager?.isEnabled ?: false
Comment thread
akwasniewski marked this conversation as resolved.
Outdated
}

@DoNotStrip
@Suppress("unused")
fun setGestureHandlerState(handlerTag: Int, newState: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
}

// @ts-ignore Types should be HTMLElement or React.Component
NodeManager.getHandler(handlerTag).init(newView, propsRef, actionType);

Check warning on line 57 in packages/react-native-gesture-handler/src/RNGestureHandlerModule.web.ts

View workflow job for this annotation

GitHub Actions / check

Unsafe call of an `any` typed value
},
detachGestureHandler(handlerTag: number) {
if (shouldPreventDrop) {
Expand Down Expand Up @@ -92,4 +92,7 @@
setReanimatedAvailable(_isAvailable: boolean) {
// No-op on web
},
isAccessibilityEnabled() {
// TODO
Comment thread
akwasniewski marked this conversation as resolved.
Outdated
},
};
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 RNGestureHandlerModule from '../../RNGestureHandlerModule';

export enum StateMachineEvent {
NATIVE_BEGIN = 'nativeBegin',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -112,6 +132,10 @@ export function getStatesConfig(
handlePressOut: (event: PressableEvent) => void
): StateDefinition[] {
if (Platform.OS === 'android') {
if (RNGestureHandlerModule.isAccessibilityEnabled()) {
console.log('accessible!!!');
Comment thread
akwasniewski marked this conversation as resolved.
Outdated
return getAndroidAccessibilityStatesConfig(handlePressIn, handlePressOut);
}
return getAndroidStatesConfig(handlePressIn, handlePressOut);
} else if (Platform.OS === 'ios') {
return getIosStatesConfig(handlePressIn, handlePressOut);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Spec extends TurboModule {
dropGestureHandler: (handlerTag: Double) => void;
flushOperations: () => void;
setReanimatedAvailable: (isAvailable: boolean) => void;
isAccessibilityEnabled: () => boolean;
Comment thread
akwasniewski marked this conversation as resolved.
Outdated
}

export default TurboModuleRegistry.getEnforcing<Spec>('RNGestureHandlerModule');
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { PureNativeButton } from './GestureButtons';

import { PressabilityDebugView } from '../../handlers/PressabilityDebugView';
import { INT32_MAX, isTestEnv } from '../../utils';
import RNGestureHandlerModule from '../../RNGestureHandlerModule';

const DEFAULT_LONG_PRESS_DURATION = 500;
const IS_TEST_ENV = isTestEnv();
Expand Down Expand Up @@ -257,7 +258,10 @@ const Pressable = (props: PressableProps) => {
);
},
onTouchesUp: () => {
if (Platform.OS === 'android') {
if (
Platform.OS === 'android' &&
!RNGestureHandlerModule.isAccessibilityEnabled()
) {
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This calls the native isAccessibilityEnabled() synchronously on every onTouchesUp. Since this value typically changes rarely, consider reading it once (e.g., on mount) and caching it in a ref/state to avoid repeated sync native calls on a hot interaction path.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Prevents potential soft-locks
stateMachine.reset();
handleFinalize();
Expand Down
Loading