Skip to content

Commit 6203c18

Browse files
committed
feat: added accessibility overrides support (#1288)(by @Mahmoud-SK)
* Added accessibility to the bottomSheet component * Accessibility changes - BottomSheetBackdrop * Accessibility changes - BottomSheetHandle * Minor adjustments after review * removed unused spread operator * fix: removed change announcement removed the change announcement part of the code, and the ..rest from the two mentioned files.
1 parent 17269f1 commit 6203c18

File tree

11 files changed

+120
-30
lines changed

11 files changed

+120
-30
lines changed

src/components/bottomSheet/BottomSheet.tsx

+16-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import BottomSheetHandleContainer from '../bottomSheetHandleContainer';
4141
import BottomSheetBackgroundContainer from '../bottomSheetBackgroundContainer';
4242
import BottomSheetFooterContainer from '../bottomSheetFooterContainer/BottomSheetFooterContainer';
4343
import BottomSheetDraggableView from '../bottomSheetDraggableView';
44-
import BottomSheetDebugView from '../bottomSheetDebugView';
44+
// import BottomSheetDebugView from '../bottomSheetDebugView';
4545
import {
4646
ANIMATION_STATE,
4747
KEYBOARD_STATE,
@@ -76,6 +76,9 @@ import {
7676
INITIAL_CONTAINER_OFFSET,
7777
INITIAL_VALUE,
7878
DEFAULT_DYNAMIC_SIZING,
79+
DEFAULT_ACCESSIBLE,
80+
DEFAULT_ACCESSIBILITY_LABEL,
81+
DEFAULT_ACCESSIBILITY_ROLE,
7982
} from './constants';
8083
import type { BottomSheetMethods, Insets } from '../../types';
8184
import type { BottomSheetProps, AnimateToPositionType } from './types';
@@ -154,6 +157,13 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
154157
backgroundComponent,
155158
footerComponent,
156159
children,
160+
161+
// accessibility
162+
accessible: _providedAccessible = DEFAULT_ACCESSIBLE,
163+
accessibilityLabel:
164+
_providedAccessibilityLabel = DEFAULT_ACCESSIBILITY_LABEL,
165+
accessibilityRole:
166+
_providedAccessibilityRole = DEFAULT_ACCESSIBILITY_ROLE,
157167
} = props;
158168
//#endregion
159169

@@ -1713,6 +1723,9 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
17131723
<Animated.View
17141724
pointerEvents="box-none"
17151725
style={contentMaskContainerStyle}
1726+
accessible={_providedAccessible ?? undefined}
1727+
accessibilityRole={_providedAccessibilityRole ?? undefined}
1728+
accessibilityLabel={_providedAccessibilityLabel ?? undefined}
17161729
>
17171730
<BottomSheetDraggableView
17181731
key="BottomSheetRootDraggableView"
@@ -1742,7 +1755,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
17421755
handleIndicatorStyle={_providedHandleIndicatorStyle}
17431756
/>
17441757
</Animated.View>
1745-
<BottomSheetDebugView
1758+
{/* <BottomSheetDebugView
17461759
values={{
17471760
// topInset,
17481761
// bottomInset,
@@ -1766,7 +1779,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
17661779
// isContentHeightFixed,
17671780
// isInTemporaryPosition,
17681781
}}
1769-
/>
1782+
/> */}
17701783
</BottomSheetContainer>
17711784
</BottomSheetGestureHandlersProvider>
17721785
</BottomSheetInternalProvider>

src/components/bottomSheet/constants.ts

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ const INITIAL_CONTAINER_OFFSET = {
3333
const INITIAL_HANDLE_HEIGHT = -999;
3434
const INITIAL_POSITION = SCREEN_HEIGHT;
3535

36+
// accessibility
37+
const DEFAULT_ACCESSIBLE = true;
38+
const DEFAULT_ACCESSIBILITY_LABEL = 'Bottom Sheet';
39+
const DEFAULT_ACCESSIBILITY_ROLE = 'adjustable';
40+
3641
export {
3742
DEFAULT_HANDLE_HEIGHT,
3843
DEFAULT_OVER_DRAG_RESISTANCE_FACTOR,
@@ -53,4 +58,8 @@ export {
5358
INITIAL_HANDLE_HEIGHT,
5459
INITIAL_SNAP_POINT,
5560
INITIAL_VALUE,
61+
// accessibility
62+
DEFAULT_ACCESSIBLE,
63+
DEFAULT_ACCESSIBILITY_LABEL,
64+
DEFAULT_ACCESSIBILITY_ROLE,
5665
};

src/components/bottomSheet/types.d.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ import type {
1818
KEYBOARD_BLUR_BEHAVIOR,
1919
KEYBOARD_INPUT_MODE,
2020
} from '../../constants';
21-
import type { GestureEventsHandlersHookType } from '../../types';
21+
import type {
22+
GestureEventsHandlersHookType,
23+
NullableAccessibilityProps,
24+
} from '../../types';
2225

2326
export interface BottomSheetProps
2427
extends BottomSheetAnimationConfigs,
25-
Partial<BottomSheetGestureProps> {
28+
Partial<BottomSheetGestureProps>,
29+
Omit<NullableAccessibilityProps, 'accessibilityHint'> {
2630
//#region configuration
2731
/**
2832
* Initial snap point index, provide `-1` to initiate bottom sheet in closed state.

src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx

+29-15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import {
1919
DEFAULT_DISAPPEARS_ON_INDEX,
2020
DEFAULT_ENABLE_TOUCH_THROUGH,
2121
DEFAULT_PRESS_BEHAVIOR,
22+
DEFAULT_ACCESSIBLE,
23+
DEFAULT_ACCESSIBILITY_ROLE,
24+
DEFAULT_ACCESSIBILITY_LABEL,
25+
DEFAULT_ACCESSIBILITY_HINT,
2226
} from './constants';
2327
import { styles } from './styles';
2428
import type { BottomSheetDefaultBackdropProps } from './types';
@@ -33,6 +37,10 @@ const BottomSheetBackdropComponent = ({
3337
onPress,
3438
style,
3539
children,
40+
accessible: _providedAccessible = DEFAULT_ACCESSIBLE,
41+
accessibilityRole: _providedAccessibilityRole = DEFAULT_ACCESSIBILITY_ROLE,
42+
accessibilityLabel: _providedAccessibilityLabel = DEFAULT_ACCESSIBILITY_LABEL,
43+
accessibilityHint: _providedAccessibilityHint = DEFAULT_ACCESSIBILITY_HINT,
3644
}: BottomSheetDefaultBackdropProps) => {
3745
//#region hooks
3846
const { snapToIndex, close } = useBottomSheet();
@@ -112,27 +120,33 @@ const BottomSheetBackdropComponent = ({
112120
},
113121
[disappearsOnIndex]
114122
);
123+
124+
const AnimatedView = (
125+
<Animated.View
126+
style={containerStyle}
127+
pointerEvents={pointerEvents}
128+
accessible={_providedAccessible ?? undefined}
129+
accessibilityRole={_providedAccessibilityRole ?? undefined}
130+
accessibilityLabel={_providedAccessibilityLabel ?? undefined}
131+
accessibilityHint={
132+
_providedAccessibilityHint
133+
? _providedAccessibilityHint
134+
: `Tap to ${
135+
typeof pressBehavior === 'string' ? pressBehavior : 'move'
136+
} the Bottom Sheet`
137+
}
138+
>
139+
{children}
140+
</Animated.View>
141+
);
115142
//#endregion
116143

117144
return pressBehavior !== 'none' ? (
118145
<TapGestureHandler onGestureEvent={gestureHandler}>
119-
<Animated.View
120-
style={containerStyle}
121-
pointerEvents={pointerEvents}
122-
accessible={true}
123-
accessibilityRole="button"
124-
accessibilityLabel="Bottom Sheet backdrop"
125-
accessibilityHint={`Tap to ${
126-
typeof pressBehavior === 'string' ? pressBehavior : 'move'
127-
} the Bottom Sheet`}
128-
>
129-
{children}
130-
</Animated.View>
146+
{AnimatedView}
131147
</TapGestureHandler>
132148
) : (
133-
<Animated.View pointerEvents={pointerEvents} style={containerStyle}>
134-
{children}
135-
</Animated.View>
149+
AnimatedView
136150
);
137151
};
138152

src/components/bottomSheetBackdrop/constants.ts

+9
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,19 @@ const DEFAULT_DISAPPEARS_ON_INDEX = 0;
44
const DEFAULT_ENABLE_TOUCH_THROUGH = false;
55
const DEFAULT_PRESS_BEHAVIOR = 'close' as const;
66

7+
const DEFAULT_ACCESSIBLE = true;
8+
const DEFAULT_ACCESSIBILITY_ROLE = 'button';
9+
const DEFAULT_ACCESSIBILITY_LABEL = 'Bottom sheet backdrop';
10+
const DEFAULT_ACCESSIBILITY_HINT = 'Tap to close the bottom sheet';
11+
712
export {
813
DEFAULT_OPACITY,
914
DEFAULT_APPEARS_ON_INDEX,
1015
DEFAULT_DISAPPEARS_ON_INDEX,
1116
DEFAULT_ENABLE_TOUCH_THROUGH,
1217
DEFAULT_PRESS_BEHAVIOR,
18+
DEFAULT_ACCESSIBLE,
19+
DEFAULT_ACCESSIBILITY_ROLE,
20+
DEFAULT_ACCESSIBILITY_LABEL,
21+
DEFAULT_ACCESSIBILITY_HINT,
1322
};

src/components/bottomSheetBackdrop/types.d.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { ReactNode } from 'react';
22
import type { ViewProps } from 'react-native';
3-
import type { BottomSheetVariables } from '../../types';
3+
import type {
4+
BottomSheetVariables,
5+
NullableAccessibilityProps,
6+
} from '../../types';
47

58
export interface BottomSheetBackdropProps
69
extends Pick<ViewProps, 'style'>,
@@ -9,7 +12,8 @@ export interface BottomSheetBackdropProps
912
export type BackdropPressBehavior = 'none' | 'close' | 'collapse' | number;
1013

1114
export interface BottomSheetDefaultBackdropProps
12-
extends BottomSheetBackdropProps {
15+
extends BottomSheetBackdropProps,
16+
NullableAccessibilityProps {
1317
/**
1418
* Backdrop opacity.
1519
* @type number

src/components/bottomSheetHandle/BottomSheetHandle.tsx

+17-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@ import React, { memo, useMemo } from 'react';
22
import Animated from 'react-native-reanimated';
33
import { styles } from './styles';
44
import type { BottomSheetDefaultHandleProps } from './types';
5+
import {
6+
DEFAULT_ACCESSIBLE,
7+
DEFAULT_ACCESSIBILITY_ROLE,
8+
DEFAULT_ACCESSIBILITY_LABEL,
9+
DEFAULT_ACCESSIBILITY_HINT,
10+
} from './constants';
511

612
const BottomSheetHandleComponent = ({
713
style,
814
indicatorStyle: _indicatorStyle,
915
children,
16+
accessible = DEFAULT_ACCESSIBLE,
17+
accessibilityRole = DEFAULT_ACCESSIBILITY_ROLE,
18+
accessibilityLabel = DEFAULT_ACCESSIBILITY_LABEL,
19+
accessibilityHint = DEFAULT_ACCESSIBILITY_HINT,
1020
}: BottomSheetDefaultHandleProps) => {
1121
// styles
1222
const containerStyle = useMemo(
@@ -23,7 +33,13 @@ const BottomSheetHandleComponent = ({
2333

2434
// render
2535
return (
26-
<Animated.View style={containerStyle}>
36+
<Animated.View
37+
style={containerStyle}
38+
accessible={accessible ?? undefined}
39+
accessibilityRole={accessibilityRole ?? undefined}
40+
accessibilityLabel={accessibilityLabel ?? undefined}
41+
accessibilityHint={accessibilityHint ?? undefined}
42+
>
2743
<Animated.View style={indicatorStyle} />
2844
{children}
2945
</Animated.View>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const DEFAULT_ACCESSIBLE = true;
2+
const DEFAULT_ACCESSIBILITY_ROLE = 'adjustable';
3+
const DEFAULT_ACCESSIBILITY_LABEL = 'Bottom sheet handle';
4+
const DEFAULT_ACCESSIBILITY_HINT =
5+
'Drag up or down to extend or minimize the bottom sheet';
6+
7+
export {
8+
DEFAULT_ACCESSIBLE,
9+
DEFAULT_ACCESSIBILITY_ROLE,
10+
DEFAULT_ACCESSIBILITY_LABEL,
11+
DEFAULT_ACCESSIBILITY_HINT,
12+
};

src/components/bottomSheetHandle/types.d.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
import type React from 'react';
22
import type { ViewProps } from 'react-native';
33
import type { AnimateProps } from 'react-native-reanimated';
4-
import type { BottomSheetVariables } from '../../types';
4+
import type {
5+
BottomSheetVariables,
6+
NullableAccessibilityProps,
7+
} from '../../types';
58

69
export interface BottomSheetHandleProps extends BottomSheetVariables {}
710

8-
export interface BottomSheetDefaultHandleProps extends BottomSheetHandleProps {
11+
export interface BottomSheetDefaultHandleProps
12+
extends BottomSheetHandleProps,
13+
NullableAccessibilityProps {
914
/**
1015
* View style to be applied to the handle container.
1116
* @type Animated.AnimateStyle<ViewStyle> | ViewStyle

src/components/bottomSheetHandleContainer/BottomSheetHandleContainer.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,8 @@ function BottomSheetHandleContainerComponent({
134134
<GestureDetector gesture={panGesture}>
135135
<Animated.View
136136
key="BottomSheetHandleContainer"
137-
accessible={true}
138-
accessibilityRole="adjustable"
139-
accessibilityLabel="Bottom Sheet handle"
140-
accessibilityHint="Drag up or down to extend or minimize the Bottom Sheet"
141-
style={styles.container}
142137
onLayout={handleContainerLayout}
138+
style={styles.container}
143139
>
144140
<HandleComponent
145141
animatedIndex={animatedIndex}

src/types.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
SectionList,
66
NativeScrollEvent,
77
NativeSyntheticEvent,
8+
AccessibilityProps,
89
} from 'react-native';
910
import type {
1011
GestureEventPayload,
@@ -186,3 +187,10 @@ export type ScrollEventsHandlersHookType = (
186187
handleOnMomentumEnd?: ScrollEventHandlerCallbackType;
187188
};
188189
//#endregion
190+
191+
export interface NullableAccessibilityProps extends AccessibilityProps {
192+
accessible?: AccessibilityProps['accessible'] | null;
193+
accessibilityLabel?: AccessibilityProps['accessibilityLabel'] | null;
194+
accessibilityHint?: AccessibilityProps['accessibilityHint'] | null;
195+
accessibilityRole?: AccessibilityProps['accessibilityRole'] | null;
196+
}

0 commit comments

Comments
 (0)