-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathCarouselButtons.js
89 lines (78 loc) · 3.25 KB
/
CarouselButtons.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import PropTypes from 'prop-types';
import React from 'react';
import {View} from 'react-native';
import _ from 'underscore';
import * as AttachmentCarouselViewPropTypes from '@components/Attachments/propTypes';
import Button from '@components/Button';
import * as Expensicons from '@components/Icon/Expensicons';
import Tooltip from '@components/Tooltip';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
const propTypes = {
/** Where the arrows should be visible */
shouldShowArrows: PropTypes.bool.isRequired,
/** The current page index */
page: PropTypes.number.isRequired,
/** The attachments from the carousel */
attachments: AttachmentCarouselViewPropTypes.attachmentsPropType.isRequired,
/** Callback to go one page back */
onBack: PropTypes.func.isRequired,
/** Callback to go one page forward */
onForward: PropTypes.func.isRequired,
autoHideArrow: PropTypes.func,
cancelAutoHideArrow: PropTypes.func,
};
const defaultProps = {
autoHideArrow: () => {},
cancelAutoHideArrow: () => {},
};
function CarouselButtons({page, attachments, shouldShowArrows, onBack, onForward, cancelAutoHideArrow, autoHideArrow}) {
const theme = useTheme();
const styles = useThemeStyles();
const isBackDisabled = page === 0;
const isForwardDisabled = page === _.size(attachments) - 1;
const {translate} = useLocalize();
const {isSmallScreenWidth} = useWindowDimensions();
return shouldShowArrows ? (
<>
{!isBackDisabled && (
<Tooltip text={translate('common.previous')}>
<View style={[styles.attachmentArrow, isSmallScreenWidth ? styles.l2 : styles.l8]}>
<Button
small
innerStyles={[styles.arrowIcon]}
icon={Expensicons.BackArrow}
iconFill={theme.text}
iconStyles={[styles.mr0]}
onPress={onBack}
onPressIn={cancelAutoHideArrow}
onPressOut={autoHideArrow}
/>
</View>
</Tooltip>
)}
{!isForwardDisabled && (
<Tooltip text={translate('common.next')}>
<View style={[styles.attachmentArrow, isSmallScreenWidth ? styles.r2 : styles.r8]}>
<Button
small
innerStyles={[styles.arrowIcon]}
icon={Expensicons.ArrowRight}
iconFill={theme.text}
iconStyles={[styles.mr0]}
onPress={onForward}
onPressIn={cancelAutoHideArrow}
onPressOut={autoHideArrow}
/>
</View>
</Tooltip>
)}
</>
) : null;
}
CarouselButtons.propTypes = propTypes;
CarouselButtons.defaultProps = defaultProps;
CarouselButtons.displayName = 'CarouselButtons';
export default CarouselButtons;