-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
AttachmentOfflineIndicator.tsx
57 lines (48 loc) · 2.05 KB
/
AttachmentOfflineIndicator.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
import React, {useEffect, useState} from 'react';
import {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import Text from './Text';
type AttachmentOfflineIndicatorProps = {
/** Whether the offline indicator is displayed for the attachment preview. */
isPreview?: boolean;
};
function AttachmentOfflineIndicator({isPreview = false}: AttachmentOfflineIndicatorProps) {
const theme = useTheme();
const styles = useThemeStyles();
const {isOffline} = useNetwork();
const {translate} = useLocalize();
// We don't want to show the offline indicator when the attachment is a cached one, so
// we delay the display by 200 ms to ensure it is not a cached one.
const [onCacheDelay, setOnCacheDelay] = useState(true);
useEffect(() => {
const timeout = setTimeout(() => setOnCacheDelay(false), 200);
return () => clearTimeout(timeout);
}, []);
if (!isOffline || onCacheDelay) {
return null;
}
return (
<View style={[styles.flexColumn, styles.alignItemsCenter, styles.justifyContentCenter, styles.pAbsolute, styles.h100, styles.w100, isPreview && styles.hoveredComponentBG]}>
<Icon
fill={theme.border}
src={Expensicons.OfflineCloud}
width={variables.iconSizeSuperLarge}
height={variables.iconSizeSuperLarge}
/>
{!isPreview && (
<View>
<Text style={[styles.notFoundTextHeader]}>{translate('common.youAppearToBeOffline')}</Text>
<Text>{translate('common.attachementWillBeAvailableOnceBackOnline')}</Text>
</View>
)}
</View>
);
}
AttachmentOfflineIndicator.displayName = 'AttachmentOfflineIndicator';
export default AttachmentOfflineIndicator;