-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathLoadingIndicator.tsx
More file actions
76 lines (65 loc) · 2.14 KB
/
LoadingIndicator.tsx
File metadata and controls
76 lines (65 loc) · 2.14 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
66
67
68
69
70
71
72
73
74
75
76
import React, { useMemo } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { useTheme } from '../../contexts/themeContext/ThemeContext';
import { useTranslationContext } from '../../contexts/translationContext/TranslationContext';
import { primitives } from '../../theme';
import { Spinner } from '../UIComponents/Spinner';
type LoadingIndicatorWrapperProps = { text: string | undefined };
const LoadingIndicatorWrapper = ({ text }: LoadingIndicatorWrapperProps) => {
const styles = useStyles();
return (
<View style={styles.container}>
<Spinner height={20} width={20} />
{text ? (
<Text style={styles.loadingText} testID='loading'>
{text}
</Text>
) : null}
</View>
);
};
export type LoadingProps = {
listType?: 'channel' | 'message' | 'threads' | 'default';
loadingText?: string;
};
/**
* UI Component for LoadingIndicator
*/
export const LoadingIndicator = (props: LoadingProps) => {
const { listType, loadingText } = props;
const { t } = useTranslationContext();
if (loadingText) {
return <LoadingIndicatorWrapper text={loadingText} />;
}
switch (listType) {
case 'channel':
return <LoadingIndicatorWrapper text={t('Loading channels...')} />;
case 'message':
return <LoadingIndicatorWrapper text={t('Loading messages...')} />;
case 'threads':
return <LoadingIndicatorWrapper text={undefined} />;
default:
return <LoadingIndicatorWrapper text={t('Loading...')} />;
}
};
LoadingIndicator.displayName = 'LoadingIndicator{loadingIndicator}';
const useStyles = () => {
const {
theme: {
loadingIndicator: { container, loadingText },
semantics,
},
} = useTheme();
return useMemo(() => {
return StyleSheet.create({
container: { alignItems: 'center', flex: 1, justifyContent: 'center', ...container },
loadingText: {
fontSize: primitives.typographyFontSizeMd,
fontWeight: primitives.typographyFontWeightSemiBold,
marginTop: primitives.spacingSm,
color: semantics.textPrimary,
...loadingText,
},
});
}, [container, loadingText, semantics]);
};