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 6, 2022
1 parent 0c34e55 commit 165950b
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 @@ -263,6 +264,9 @@ const BlockDraggableWrapper = ( { children } ) => {
const BlockDraggable = ( { clientId, children, enabled = true } ) => {
const wasBeingDragged = useRef( false );
const [ isEditingText, setIsEditingText ] = useState( false );
const [ isScreenReaderEnabled, setIsScreenReaderEnabled ] = useState(
false
);

const draggingAnimation = {
opacity: useSharedValue( 1 ),
Expand Down Expand Up @@ -325,16 +329,35 @@ const BlockDraggable = ( { clientId, children, enabled = true } ) => {
}, [] );

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

const isAnyAztecInputFocused = RCTAztecView.InputState.isFocused();
if ( isAnyAztecInputFocused ) {
setIsEditingText( isAnyAztecInputFocused );
}

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 @@ -353,7 +376,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 165950b

Please sign in to comment.