-
Notifications
You must be signed in to change notification settings - Fork 2
/
PressableModuleBase.tsx
59 lines (56 loc) · 1.53 KB
/
PressableModuleBase.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
56
57
58
59
import * as React from "react";
import { PropsWithChildren } from "react";
import { Pressable } from "react-native";
import Animated from "react-native-reanimated";
import {
IOColors,
IOModuleIDPSavedVSpacing,
IOModuleStyles,
useIOTheme
} from "../../core";
import { WithTestID } from "../../utils/types";
import { useModuleSpringAnimation } from "./hooks/useModuleSpringAnimation";
export type PressableModuleBaseProps = WithTestID<
{
withLooseSpacing?: boolean;
} & Pick<
React.ComponentProps<typeof Pressable>,
"onPress" | "accessibilityLabel" | "accessibilityHint"
>
>;
export const PressableModuleBase = ({
onPress,
withLooseSpacing = false,
accessibilityLabel,
accessibilityHint,
testID,
children
}: PropsWithChildren<PressableModuleBaseProps>) => {
const theme = useIOTheme();
const { handlePressIn, handlePressOut, animatedStyle } =
useModuleSpringAnimation();
return (
<Pressable
onPress={onPress}
testID={testID}
accessible={true}
onPressIn={handlePressIn}
onPressOut={handlePressOut}
onTouchEnd={handlePressOut}
accessibilityLabel={accessibilityLabel}
accessibilityHint={accessibilityHint}
accessibilityRole="button"
>
<Animated.View
style={[
IOModuleStyles.button,
{ borderColor: IOColors[theme["cardBorder-default"]] },
withLooseSpacing && { paddingVertical: IOModuleIDPSavedVSpacing },
animatedStyle
]}
>
{children}
</Animated.View>
</Pressable>
);
};