1 | import * as React from 'react';
|
2 | import { Platform, Pressable, PressableProps } from 'react-native';
|
3 |
|
4 | export type Props = PressableProps & {
|
5 | pressColor?: string;
|
6 | pressOpacity?: number;
|
7 | children: React.ReactNode;
|
8 | };
|
9 |
|
10 | const ANDROID_VERSION_LOLLIPOP = 21;
|
11 | const ANDROID_SUPPORTS_RIPPLE =
|
12 | Platform.OS === 'android' && Platform.Version >= ANDROID_VERSION_LOLLIPOP;
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export default function PlatformPressable({
|
22 | android_ripple,
|
23 | pressColor = 'rgba(0, 0, 0, .32)',
|
24 | pressOpacity,
|
25 | style,
|
26 | ...rest
|
27 | }: Props) {
|
28 | return (
|
29 | <Pressable
|
30 | android_ripple={
|
31 | ANDROID_SUPPORTS_RIPPLE
|
32 | ? { color: pressColor, ...android_ripple }
|
33 | : undefined
|
34 | }
|
35 | style={({ pressed }) => [
|
36 | { opacity: pressed && !ANDROID_SUPPORTS_RIPPLE ? pressOpacity : 1 },
|
37 | typeof style === 'function' ? style({ pressed }) : style,
|
38 | ]}
|
39 | {...rest}
|
40 | />
|
41 | );
|
42 | }
|