Skip to content

Commit

Permalink
Disable dragging when screen reader is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
fluiddot committed May 5, 2022
1 parent adcd420 commit 2a5a0ea
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* External dependencies
*/
import { AccessibilityInfo } from 'react-native';
import Animated, {
runOnJS,
runOnUI,
Expand Down Expand Up @@ -265,6 +266,9 @@ const BlockDraggable = ( { clientId, children, enabled = true } ) => {
const [ isEditingText, setIsEditingText ] = useState(
RCTAztecView.InputState.isFocused()
);
const [ isScreenReaderEnabled, setIsScreenReaderEnabled ] = useState(
false
);

const draggingAnimation = {
opacity: useSharedValue( 1 ),
Expand Down Expand Up @@ -327,11 +331,30 @@ const BlockDraggable = ( { clientId, children, enabled = true } ) => {
}, [] );

useEffect( () => {
let mounted = true;

RCTAztecView.InputState.addFocusChangeListener( onFocusChangeAztec );

const screenReaderChangedListener = AccessibilityInfo.addEventListener(
'screenReaderChanged',
setIsScreenReaderEnabled
);
AccessibilityInfo.isScreenReaderEnabled().then(
( screenReaderEnabled ) => {
if ( mounted ) {
setIsScreenReaderEnabled( screenReaderEnabled );
}
}
);

return () => {
mounted = false;

RCTAztecView.InputState.removeFocusChangeListener(
onFocusChangeAztec
);

screenReaderChangedListener.remove();
};
}, [] );

Expand All @@ -350,7 +373,10 @@ const BlockDraggable = ( { clientId, children, enabled = true } ) => {
styles[ 'draggable-wrapper__container' ],
];

const canDragBlock = enabled && ( ! isBlockSelected || ! isEditingText );
const canDragBlock =
enabled &&
! isScreenReaderEnabled &&
( ! isBlockSelected || ! isEditingText );

if ( ! isDraggable ) {
return children( { isDraggable: false } );
Expand Down

0 comments on commit 2a5a0ea

Please sign in to comment.