Skip to content

Commit c9a0f95

Browse files
author
Chris Bobbe
committed
LoadingBanner [nfc]: Add, for many places where we need to show loading state.
For zulip#3387, provide the component to be used to show a loading banner during the /register request. This will be much improved with an animation, but progress is blocked by zulip#3899. One idea is to give the exit animation a shorter duration than the entrance animation, to give the impression that we've been awaiting updates just as attentively as the user, and that we're eager to show the updates and get out of the way immediately.
1 parent b3abff0 commit c9a0f95

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

src/common/LoadingBanner.js

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/* @flow strict-local */
2+
3+
import React, { PureComponent } from 'react';
4+
import { StyleSheet, View } from 'react-native';
5+
6+
import type { Dispatch } from '../types';
7+
import { connect } from '../react-redux';
8+
import { getLoading } from '../selectors';
9+
import { Label, LoadingIndicator } from '.';
10+
import type { ThemeColors } from '../styles';
11+
import { ThemeContext } from '../styles';
12+
13+
const key = 'LoadingBanner';
14+
15+
const styles = StyleSheet.create({
16+
block: {
17+
flexDirection: 'row',
18+
justifyContent: 'center',
19+
alignItems: 'center',
20+
backgroundColor: 'hsl(6, 98%, 57%)',
21+
},
22+
none: { display: 'none' },
23+
});
24+
25+
type SelectorProps = $ReadOnly<{|
26+
loading: boolean,
27+
|}>;
28+
29+
type Props = $ReadOnly<{|
30+
spinnerColor?: 'black' | 'white' | 'default',
31+
textColor?: string,
32+
backgroundColor?: string,
33+
34+
dispatch: Dispatch,
35+
...SelectorProps,
36+
|}>;
37+
38+
/**
39+
* Displays a notice that the app is connecting to the server.
40+
* Rendered when session.loading is true (as of 2020/02, only
41+
* during the /register request).
42+
*
43+
* @prop loading
44+
*/
45+
class LoadingBanner extends PureComponent<Props> {
46+
static contextType = ThemeContext;
47+
context: ThemeColors;
48+
49+
render() {
50+
const {
51+
loading,
52+
spinnerColor = 'default',
53+
textColor = this.context.color,
54+
backgroundColor,
55+
} = this.props;
56+
if (!loading) {
57+
return <View key={key} style={styles.none} />;
58+
}
59+
const style = {
60+
width: '100%',
61+
flexDirection: 'row',
62+
justifyContent: 'center',
63+
alignItems: 'center',
64+
backgroundColor: backgroundColor ?? this.context.backgroundColor,
65+
};
66+
return (
67+
<View key={key} style={style}>
68+
<View
69+
/* eslint-disable react-native/no-inline-styles */
70+
style={{ flexDirection: 'row', alignItems: 'center' }}
71+
>
72+
<View>
73+
<LoadingIndicator size={14} color={spinnerColor} />
74+
</View>
75+
<Label
76+
/* eslint-disable react-native/no-inline-styles */
77+
style={{
78+
fontSize: 14,
79+
margin: 2,
80+
color: textColor,
81+
}}
82+
text="Connecting..."
83+
/>
84+
</View>
85+
</View>
86+
);
87+
}
88+
}
89+
90+
export default connect<SelectorProps, _, _>(state => ({
91+
loading: getLoading(state),
92+
}))(LoadingBanner);

0 commit comments

Comments
 (0)