-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPressableListItemBase.tsx
55 lines (53 loc) · 1.45 KB
/
PressableListItemBase.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import * as React from "react";
import { PropsWithChildren } from "react";
import { Pressable } from "react-native";
import Animated from "react-native-reanimated";
import { IOListItemStyles, IOListItemVisualParams } from "../../core";
import { WithTestID } from "../../utils/types";
import { useListItemAnimation } from "../../hooks";
export type PressableBaseProps = WithTestID<
Pick<
React.ComponentProps<typeof Pressable>,
| "onPress"
| "accessibilityLabel"
| "accessibilityHint"
| "accessibilityState"
| "accessibilityRole"
>
>;
export const PressableListItemBase = ({
onPress,
testID,
children,
accessibilityRole,
...props
}: PropsWithChildren<PressableBaseProps>) => {
const { onPressIn, onPressOut, scaleAnimatedStyle, backgroundAnimatedStyle } =
useListItemAnimation();
return (
<Pressable
onPress={onPress}
testID={testID}
accessible={true}
onPressIn={onPressIn}
onPressOut={onPressOut}
onTouchEnd={onPressOut}
accessibilityRole={accessibilityRole || "button"}
{...props}
>
<Animated.View
style={[IOListItemStyles.listItem, backgroundAnimatedStyle]}
>
<Animated.View
style={[
IOListItemStyles.listItemInner,
{ columnGap: IOListItemVisualParams.iconMargin },
scaleAnimatedStyle
]}
>
{children}
</Animated.View>
</Animated.View>
</Pressable>
);
};