Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d4e140f
Upgrade React packages to v18
jsnajdr Oct 24, 2022
3cc35fd
Upgrade framer-motion to get React 18 support and updated types
jsnajdr Oct 25, 2022
7af9bf2
React Native: upgrade to 0.69.4
jsnajdr Oct 31, 2022
b9d3d28
React Native: upgrade libraries
jsnajdr Nov 28, 2022
ea93ff0
LinkControl: fix unit tests
jsnajdr Nov 16, 2022
05da41f
Components: fix unit tests
jsnajdr Oct 26, 2022
9408a92
Block Editor: fix unit tests
jsnajdr Oct 27, 2022
382359b
NUX: fix unit tests
jsnajdr Oct 27, 2022
61e8e7a
useSelect: fix unit tests (partially)
jsnajdr Oct 28, 2022
23fb060
LinkSettings test: fix finding blocks by label text
jsnajdr Oct 31, 2022
b712d42
BlockDraggable test: fix finding blocks by label text
jsnajdr Oct 31, 2022
d253cdb
React Native test helpers: fix getting blocks
jsnajdr Oct 31, 2022
637ce64
Block Library tests: fix finding blocks by label text
jsnajdr Oct 31, 2022
6da1678
ToggleGroupControl: fix unit test by waiting for tooltip
jsnajdr Nov 18, 2022
cd42397
File Block: update snapshots to account for empty children
jsnajdr Nov 18, 2022
9f7c332
Embed native tests: improve mocked API response
jsnajdr Nov 21, 2022
4de9c4a
Embed native tests: wait for rich preview to appear
jsnajdr Nov 21, 2022
c9b9bd6
Format Library: fix finding blocks by label text
jsnajdr Nov 21, 2022
7fb330c
Edit Post: fix finding blocks by label text
jsnajdr Nov 21, 2022
4edb25f
Update native snapshots
tyxla Nov 23, 2022
7774a2f
useNestedSettingsUpdate: deoptimize/unbatch dispatching the updateBlo…
jsnajdr Nov 27, 2022
78faaeb
Color Palette: wait for dropdown to appear
jsnajdr Nov 27, 2022
807bcea
Add custom Jest matcher: toBePositionedPopover
jsnajdr Nov 28, 2022
595ce61
Use toBePositionedPopover matcher in tests
jsnajdr Nov 28, 2022
bb2595d
Mobile - Update tests
Oct 5, 2022
36de541
Mobile - Update gitignore
Oct 5, 2022
34c9c7f
Mobile - Update ruby config
Oct 5, 2022
3271c32
[Mobile] - React Native 0.69.4 Upgrade - Android (#43486)
Oct 11, 2022
c0adb62
[Mobile] - React Native 0.69.4 Upgrade - iOS
derekblank Oct 18, 2022
c9c71e7
Mobile - Check for a local bundle running with metro and use a jsbund…
Oct 21, 2022
d016b5d
Remove duplicated import of Gesture handler
Oct 30, 2022
e7bacd7
Remove deprecated initialization for Reanimated
Nov 2, 2022
d19e915
Update Podfile.lock after updating dependencies
Nov 28, 2022
69444f7
Remove React peer deps from packages that don't need them
jsnajdr Nov 30, 2022
259e3bb
Add changelog entries about React 18 upgrade
jsnajdr Nov 30, 2022
16d1ec2
Extract useIsScreenReaderEnabled hook, set state only if enabled=true
jsnajdr Nov 30, 2022
6e704aa
Mobile - Update Podfile.lock
Dec 1, 2022
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
Prev Previous commit
Next Next commit
Extract useIsScreenReaderEnabled hook, set state only if enabled=true
  • Loading branch information
jsnajdr committed Dec 1, 2022
commit 16d1ec295db8dbc90f6c66dede8da0dd0b060789
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,58 @@ const BlockDraggableWrapper = ( { children, isRTL } ) => {
);
};

function useIsScreenReaderEnabled() {
const [ isScreenReaderEnabled, setIsScreenReaderEnabled ] =
useState( false );

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

const changeListener = AccessibilityInfo.addEventListener(
'screenReaderChanged',
( enabled ) => setIsScreenReaderEnabled( enabled )
);

AccessibilityInfo.isScreenReaderEnabled().then(
( screenReaderEnabled ) => {
if ( mounted && screenReaderEnabled ) {
setIsScreenReaderEnabled( screenReaderEnabled );
}
}
);

return () => {
mounted = false;

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

return isScreenReaderEnabled;
}

function useIsEditingText() {
const [ isEditingText, setIsEditingText ] = useState( () =>
RCTAztecView.InputState.isFocused()
);

useEffect( () => {
const onFocusChangeAztec = ( { isFocused } ) => {
setIsEditingText( isFocused );
};

RCTAztecView.InputState.addFocusChangeListener( onFocusChangeAztec );

return () => {
RCTAztecView.InputState.removeFocusChangeListener(
onFocusChangeAztec
);
};
}, [] );

return isEditingText;
}

/**
* Block draggable component
*
Expand All @@ -308,9 +360,8 @@ const BlockDraggable = ( {
testID,
} ) => {
const wasBeingDragged = useRef( false );
const [ isEditingText, setIsEditingText ] = useState( false );
const [ isScreenReaderEnabled, setIsScreenReaderEnabled ] =
useState( false );
const isEditingText = useIsEditingText();
const isScreenReaderEnabled = useIsScreenReaderEnabled();

const draggingAnimation = {
opacity: useSharedValue( 1 ),
Expand Down Expand Up @@ -365,43 +416,6 @@ const BlockDraggable = ( {
wasBeingDragged.current = isBeingDragged;
}, [ isBeingDragged ] );

const onFocusChangeAztec = useCallback( ( { isFocused } ) => {
setIsEditingText( isFocused );
}, [] );

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();
};
}, [] );

const onLongPressDraggable = useCallback( () => {
// Ensure that no text input is focused when starting the dragging gesture in order to prevent conflicts with text editing.
RCTAztecView.InputState.blurCurrentFocusedElement();
Expand Down
50 changes: 31 additions & 19 deletions packages/block-library/src/cover/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,36 @@ const INNER_BLOCKS_TEMPLATE = [
],
];

function useIsScreenReaderEnabled() {
const [ isScreenReaderEnabled, setIsScreenReaderEnabled ] =
useState( false );

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

const changeListener = AccessibilityInfo.addEventListener(
'screenReaderChanged',
( enabled ) => setIsScreenReaderEnabled( enabled )
);

AccessibilityInfo.isScreenReaderEnabled().then(
( screenReaderEnabled ) => {
if ( mounted && screenReaderEnabled ) {
setIsScreenReaderEnabled( screenReaderEnabled );
}
}
);

return () => {
mounted = false;

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

return isScreenReaderEnabled;
}

const Cover = ( {
attributes,
getStylesFromColorScheme,
Expand Down Expand Up @@ -118,29 +148,11 @@ const Cover = ( {
overlayColor,
isDark,
} = attributes;
const [ isScreenReaderEnabled, setIsScreenReaderEnabled ] =
useState( false );
const isScreenReaderEnabled = useIsScreenReaderEnabled();

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

// Sync with local media store.
mediaUploadSync();
const a11yInfoChangeSubscription = AccessibilityInfo.addEventListener(
'screenReaderChanged',
setIsScreenReaderEnabled
);

AccessibilityInfo.isScreenReaderEnabled().then( () => {
if ( isCurrent ) {
setIsScreenReaderEnabled();
}
} );

return () => {
isCurrent = false;
a11yInfoChangeSubscription.remove();
};
}, [] );

const convertedMinHeight = useConvertUnitToMobile(
Expand Down
7 changes: 1 addition & 6 deletions packages/block-library/src/cover/test/edit.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { AccessibilityInfo, Image } from 'react-native';
import { Image } from 'react-native';
import {
getEditorHtml,
initializeEditor,
Expand Down Expand Up @@ -90,10 +90,6 @@ beforeAll( () => {
const getSizeSpy = jest.spyOn( Image, 'getSize' );
getSizeSpy.mockImplementation( ( _url, callback ) => callback( 300, 200 ) );

AccessibilityInfo.isScreenReaderEnabled.mockResolvedValue(
Promise.resolve( true )
);

// Register required blocks.
paragraph.init();
cover.init();
Expand All @@ -103,7 +99,6 @@ beforeAll( () => {
afterAll( () => {
// Restore mocks.
Image.getSize.mockRestore();
AccessibilityInfo.isScreenReaderEnabled.mockReset();

// Clean up registered blocks.
unregisterBlockType( paragraph.name );
Expand Down
58 changes: 31 additions & 27 deletions packages/block-library/src/search/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,36 @@ const BUTTON_OPTIONS = [
{ value: 'no-button', label: __( 'No button' ) },
];

function useIsScreenReaderEnabled() {
const [ isScreenReaderEnabled, setIsScreenReaderEnabled ] =
useState( false );

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

const changeListener = AccessibilityInfo.addEventListener(
'screenReaderChanged',
( enabled ) => setIsScreenReaderEnabled( enabled )
);

AccessibilityInfo.isScreenReaderEnabled().then(
( screenReaderEnabled ) => {
if ( mounted && screenReaderEnabled ) {
setIsScreenReaderEnabled( screenReaderEnabled );
}
}
);

return () => {
mounted = false;

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

return isScreenReaderEnabled;
}

export default function SearchEdit( {
onFocus,
isSelected,
Expand All @@ -57,8 +87,7 @@ export default function SearchEdit( {
useState( false );
const [ isLongButton, setIsLongButton ] = useState( false );
const [ buttonWidth, setButtonWidth ] = useState( MIN_BUTTON_WIDTH );
const [ isScreenReaderEnabled, setIsScreenReaderEnabled ] =
useState( false );
const isScreenReaderEnabled = useIsScreenReaderEnabled();

const textInputRef = useRef( null );

Expand All @@ -71,31 +100,6 @@ export default function SearchEdit( {
buttonText,
} = attributes;

/*
* Check if screenreader is enabled and save to state. This is important for
* properly creating accessibilityLabel text.
*/
useEffect( () => {
const a11yInfoChangeSubscription = AccessibilityInfo.addEventListener(
'screenReaderChanged',
handleScreenReaderToggled
);

AccessibilityInfo.isScreenReaderEnabled().then(
( screenReaderEnabled ) => {
setIsScreenReaderEnabled( screenReaderEnabled );
}
);

return () => {
a11yInfoChangeSubscription.remove();
};
}, [] );

const handleScreenReaderToggled = ( screenReaderEnabled ) => {
setIsScreenReaderEnabled( screenReaderEnabled );
};

/*
* Called when the value of isSelected changes. Blurs the PlainText component
* used by the placeholder when this block loses focus.
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/mobile/bottom-sheet/cell.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class BottomSheetCell extends Component {

AccessibilityInfo.isScreenReaderEnabled().then(
( isScreenReaderEnabled ) => {
if ( this.isCurrent ) {
if ( this.isCurrent && isScreenReaderEnabled ) {
this.setState( { isScreenReaderEnabled } );
}
}
Expand Down