Skip to content

Commit 0a23ac0

Browse files
LeleDallasdmnplb
andauthored
feat: improve HeaderSecondLevel a11y visibility based on scroll (#408)
## Short description This pull request introduces enhancements to the `HeaderSecondLevel`, focusing on improving accessibility and adding new animated reactions ## List of changes proposed in this pull request - Modified the `importantForAccessibility` property of the `View` component to use the new state, ensuring that it updates correctly when the scroll position changes. - Implemented `useAnimatedReaction` to update the `importantForAccessibility` state based on the scroll offset, enhancing the component's responsiveness to user interactions. ## How to test Using a real device 📱, check each `HeaderSecondLevel` screen with TalkBack accessibility tool ## Preview | Before | Now | |--------|--------| | <video src="https://github.com/user-attachments/assets/3b75637c-7eb2-4dab-bcd1-b0c74226dc64"/> | <video src="https://github.com/user-attachments/assets/d15403fd-99d5-4ae2-80fe-5724a0924e38"/> | > [!TIP] > The navigation between actions shown in the video is performed using swipe gestures with TalkBack enabled, but you can also verify its functionality by tapping Co-authored-by: Damiano Plebani <[email protected]>
1 parent 1b81ff7 commit 0a23ac0

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/components/layout/HeaderSecondLevel.tsx

+28-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import Animated, {
1313
SharedValue,
1414
interpolate,
1515
interpolateColor,
16+
runOnJS,
17+
useAnimatedReaction,
1618
useAnimatedStyle,
1719
useDerivedValue,
1820
useScrollViewOffset,
@@ -269,6 +271,31 @@ export const HeaderSecondLevel = ({
269271
: 1
270272
}));
271273

274+
const [importantForAccessibility, setImportantForAccessibility] =
275+
React.useState<"yes" | "no-hide-descendants">("yes");
276+
277+
// Updates accessibility state based on scroll position.
278+
useAnimatedReaction(
279+
() =>
280+
enableDiscreteTransition
281+
? scrollOffset.value
282+
: scrollValues?.contentOffsetY.value,
283+
(currentOffset, previousOffset) => {
284+
if (currentOffset !== previousOffset) {
285+
const offsetToCompare = enableDiscreteTransition
286+
? 0
287+
: scrollValues?.triggerOffset ?? 0;
288+
// Sets accessibility to "yes" when scrolled past the threshold, else hides it from screen readers.
289+
const newValue =
290+
(currentOffset ?? 0) > offsetToCompare && !ignoreAccessibilityCheck
291+
? "yes"
292+
: "no-hide-descendants";
293+
runOnJS(setImportantForAccessibility)(newValue);
294+
}
295+
},
296+
[scrollValues, enableDiscreteTransition]
297+
);
298+
272299
return (
273300
<Animated.View
274301
accessibilityRole="header"
@@ -303,11 +330,7 @@ export const HeaderSecondLevel = ({
303330
<View
304331
ref={titleRef}
305332
accessibilityElementsHidden={!isTitleAccessible}
306-
importantForAccessibility={
307-
isTitleAccessible && !ignoreAccessibilityCheck
308-
? "yes"
309-
: "no-hide-descendants"
310-
}
333+
importantForAccessibility={importantForAccessibility}
311334
accessible={isTitleAccessible}
312335
accessibilityLabel={title}
313336
accessibilityRole="header"

0 commit comments

Comments
 (0)