forked from software-mansion/react-native-gesture-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTouchableNativeFeedback.android.js
More file actions
65 lines (60 loc) · 1.91 KB
/
TouchableNativeFeedback.android.js
File metadata and controls
65 lines (60 loc) · 1.91 KB
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
60
61
62
63
64
65
import GenericTouchable from './GenericTouchable';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
/**
* TouchableNativeFeedback behaves slightly different than RN's TouchableNativeFeedback.
* There's small difference with handling long press ripple since RN's implementation calls
* ripple animation via bridge. This solution leaves all animations' handling for native components so
* it follows native behaviours.
*/
export default class TouchableNativeFeedback extends Component {
static SelectableBackground = () => ({ type: 'SelectableBackground' });
static SelectableBackgroundBorderless = () => ({
type: 'SelectableBackgroundBorderless',
});
static Ripple = (color, borderless) => ({
type: 'Ripple',
color,
borderless,
});
static canUseNativeForeground = () =>
Platform.OS === 'android' && Platform.Version >= 23;
static defaultProps = {
...GenericTouchable.defaultProps,
useForeground: true,
extraButtonProps: {
// Disable hiding ripple on Android
rippleColor: null,
},
};
static propTypes = {
...GenericTouchable.publicPropTypes,
useForeground: PropTypes.bool,
background: PropTypes.string,
style: PropTypes.object,
};
getExtraButtonProps = () => {
const extraProps = {};
const { background } = this.props;
if (background) {
if (background.type === 'Ripple') {
extraProps['borderless'] = background.borderless;
extraProps['rippleColor'] = background.color;
} else if (background.type === 'SelectableBackgroundBorderless') {
extraProps['borderless'] = true;
}
}
extraProps['foreground'] = this.props.useForeground;
return extraProps;
};
render() {
const { style = {}, ...rest } = this.props;
return (
<GenericTouchable
{...rest}
style={style}
extraButtonProps={this.getExtraButtonProps()}
/>
);
}
}