-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
index.tsx
executable file
·268 lines (258 loc) · 11.6 KB
/
index.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import React, {useMemo} from 'react';
import {Keyboard, StyleSheet, View} from 'react-native';
import Avatar from '@components/Avatar';
import AvatarWithDisplayName from '@components/AvatarWithDisplayName';
import Header from '@components/Header';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import PinButton from '@components/PinButton';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import ThreeDotsMenu from '@components/ThreeDotsMenu';
import Tooltip from '@components/Tooltip';
import useKeyboardState from '@hooks/useKeyboardState';
import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useThrottledButtonState from '@hooks/useThrottledButtonState';
import getButtonState from '@libs/getButtonState';
import Navigation from '@libs/Navigation/Navigation';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type HeaderWithBackButtonProps from './types';
function HeaderWithBackButton({
icon,
iconFill,
guidesCallTaskID = '',
onBackButtonPress = () => Navigation.goBack(),
onCloseButtonPress = () => Navigation.dismissModal(),
onDownloadButtonPress = () => {},
onThreeDotsButtonPress = () => {},
report = null,
policy,
policyAvatar,
shouldShowReportAvatarWithDisplay = false,
shouldShowBackButton = true,
shouldShowBorderBottom = false,
shouldShowCloseButton = false,
shouldShowDownloadButton = false,
shouldShowGetAssistanceButton = false,
shouldDisableGetAssistanceButton = false,
shouldShowPinButton = false,
shouldSetModalVisibility = true,
shouldShowThreeDotsButton = false,
shouldDisableThreeDotsButton = false,
stepCounter,
subtitle = '',
title = '',
titleColor,
threeDotsAnchorPosition = {
vertical: 0,
horizontal: 0,
},
threeDotsMenuItems = [],
shouldEnableDetailPageNavigation = false,
children = null,
shouldOverlayDots = false,
shouldOverlay = false,
shouldNavigateToTopMostReport = false,
progressBarPercentage,
style,
}: HeaderWithBackButtonProps) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const [isDownloadButtonActive, temporarilyDisableDownloadButton] = useThrottledButtonState();
const {translate} = useLocalize();
const {isKeyboardShown} = useKeyboardState();
// If the icon is present, the header bar should be taller and use different font.
const isCentralPaneSettings = !!icon;
const middleContent = useMemo(() => {
if (progressBarPercentage) {
return (
<>
{/* Reserves as much space for the middleContent as possible */}
<View style={styles.flexGrow1} />
{/* Uses absolute positioning so that it's always centered instead of being affected by the
presence or absence of back/close buttons to the left/right of it */}
<View style={styles.headerProgressBarContainer}>
<View style={styles.headerProgressBar}>
<View style={[{width: `${progressBarPercentage}%`}, styles.headerProgressBarFill]} />
</View>
</View>
</>
);
}
if (shouldShowReportAvatarWithDisplay) {
return (
<AvatarWithDisplayName
report={report}
policy={policy}
shouldEnableDetailPageNavigation={shouldEnableDetailPageNavigation}
/>
);
}
return (
<Header
title={title}
subtitle={stepCounter ? translate('stepCounter', stepCounter) : subtitle}
textStyles={[titleColor ? StyleUtils.getTextColorStyle(titleColor) : {}, isCentralPaneSettings && styles.textHeadlineH2]}
/>
);
}, [
StyleUtils,
isCentralPaneSettings,
policy,
progressBarPercentage,
report,
shouldEnableDetailPageNavigation,
shouldShowReportAvatarWithDisplay,
stepCounter,
styles.flexGrow1,
styles.headerProgressBar,
styles.headerProgressBarContainer,
styles.headerProgressBarFill,
styles.textHeadlineH2,
subtitle,
title,
titleColor,
translate,
]);
return (
<View
// Hover on some part of close icons will not work on Electron if dragArea is true
// https://github.com/Expensify/App/issues/29598
dataSet={{dragArea: false}}
style={[
styles.headerBar,
isCentralPaneSettings && styles.headerBarDesktopHeight,
shouldShowBorderBottom && styles.borderBottom,
// progressBarPercentage can be 0 which would
// be falsey, hence using !== undefined explicitly
progressBarPercentage !== undefined && styles.pl0,
shouldShowBackButton && [styles.pl2, styles.pr2],
shouldOverlay && StyleSheet.absoluteFillObject,
style,
]}
>
<View style={[styles.dFlex, styles.flexRow, styles.alignItemsCenter, styles.flexGrow1, styles.justifyContentBetween, styles.overflowHidden]}>
{shouldShowBackButton && (
<Tooltip text={translate('common.back')}>
<PressableWithoutFeedback
onPress={() => {
if (isKeyboardShown) {
Keyboard.dismiss();
}
const topmostReportId = Navigation.getTopmostReportId();
if (shouldNavigateToTopMostReport && topmostReportId) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(topmostReportId));
} else {
onBackButtonPress();
}
}}
style={[styles.touchableButtonImage]}
role="button"
accessibilityLabel={translate('common.back')}
id={CONST.BACK_BUTTON_NATIVE_ID}
>
<Icon
src={Expensicons.BackArrow}
fill={iconFill ?? theme.icon}
/>
</PressableWithoutFeedback>
</Tooltip>
)}
{icon && (
<Icon
src={icon}
width={variables.iconHeader}
height={variables.iconHeader}
additionalStyles={[styles.mr2]}
/>
)}
{policyAvatar && (
<Avatar
containerStyles={[StyleUtils.getWidthAndHeightStyle(StyleUtils.getAvatarSize(CONST.AVATAR_SIZE.DEFAULT)), styles.mr3]}
source={policyAvatar?.source}
name={policyAvatar?.name}
accountID={policyAvatar?.id}
type={policyAvatar?.type}
/>
)}
{middleContent}
<View style={[styles.reportOptions, styles.flexRow, styles.pr5, styles.alignItemsCenter]}>
{children}
{shouldShowDownloadButton && (
<Tooltip text={translate('common.download')}>
<PressableWithoutFeedback
onPress={(event) => {
// Blur the pressable in case this button triggers a Growl notification
// We do not want to overlap Growl with the Tooltip (#15271)
(event?.currentTarget as HTMLElement)?.blur();
if (!isDownloadButtonActive) {
return;
}
onDownloadButtonPress();
temporarilyDisableDownloadButton();
}}
style={[styles.touchableButtonImage]}
role="button"
accessibilityLabel={translate('common.download')}
>
<Icon
src={Expensicons.Download}
fill={iconFill ?? StyleUtils.getIconFillColor(getButtonState(false, false, !isDownloadButtonActive))}
/>
</PressableWithoutFeedback>
</Tooltip>
)}
{shouldShowGetAssistanceButton && (
<Tooltip text={translate('getAssistancePage.questionMarkButtonTooltip')}>
<PressableWithoutFeedback
disabled={shouldDisableGetAssistanceButton}
onPress={() => Navigation.navigate(ROUTES.GET_ASSISTANCE.getRoute(guidesCallTaskID, Navigation.getActiveRoute()))}
style={[styles.touchableButtonImage]}
role="button"
accessibilityLabel={translate('getAssistancePage.questionMarkButtonTooltip')}
>
<Icon
src={Expensicons.QuestionMark}
fill={iconFill ?? theme.icon}
/>
</PressableWithoutFeedback>
</Tooltip>
)}
{shouldShowPinButton && !!report && <PinButton report={report} />}
{shouldShowThreeDotsButton && (
<ThreeDotsMenu
disabled={shouldDisableThreeDotsButton}
menuItems={threeDotsMenuItems}
onIconPress={onThreeDotsButtonPress}
anchorPosition={threeDotsAnchorPosition}
shouldOverlay={shouldOverlayDots}
shouldSetModalVisibility={shouldSetModalVisibility}
/>
)}
{shouldShowCloseButton && (
<Tooltip text={translate('common.close')}>
<PressableWithoutFeedback
onPress={onCloseButtonPress}
style={[styles.touchableButtonImage]}
role={CONST.ROLE.BUTTON}
accessibilityLabel={translate('common.close')}
>
<Icon
src={Expensicons.Close}
fill={iconFill ?? theme.icon}
/>
</PressableWithoutFeedback>
</Tooltip>
)}
</View>
</View>
</View>
);
}
HeaderWithBackButton.displayName = 'HeaderWithBackButton';
export default HeaderWithBackButton;