forked from zulip/zulip-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LoadingBanner: Add, to show loading state and stale data simultaneously.
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.
- Loading branch information
Chris Bobbe
committed
Mar 9, 2020
1 parent
2297e32
commit 19f1bd7
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* @flow strict-local */ | ||
|
||
import React, { PureComponent } from 'react'; | ||
import { StyleSheet, View } from 'react-native'; | ||
|
||
import type { Dispatch } from '../types'; | ||
import { connect } from '../react-redux'; | ||
import { getLoading } from '../selectors'; | ||
import { Label, LoadingIndicator } from '.'; | ||
import type { ThemeColors } from '../styles'; | ||
import { ThemeContext } from '../styles'; | ||
|
||
const key = 'LoadingBanner'; | ||
|
||
const styles = StyleSheet.create({ | ||
block: { | ||
flexDirection: 'row', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: 'hsl(6, 98%, 57%)', | ||
}, | ||
none: { display: 'none' }, | ||
}); | ||
|
||
type SelectorProps = $ReadOnly<{| | ||
loading: boolean, | ||
|}>; | ||
|
||
type Props = $ReadOnly<{| | ||
spinnerColor?: 'black' | 'white' | 'default', | ||
textColor?: string, | ||
backgroundColor?: string, | ||
|
||
dispatch: Dispatch, | ||
...SelectorProps, | ||
|}>; | ||
|
||
/** | ||
* Display a notice that the app is connecting to the server, when appropriate. | ||
*/ | ||
class LoadingBanner extends PureComponent<Props> { | ||
static contextType = ThemeContext; | ||
context: ThemeColors; | ||
|
||
render() { | ||
if (!this.props.loading) { | ||
return <View key={key} style={styles.none} />; | ||
} | ||
const { | ||
spinnerColor = 'default', | ||
textColor = this.context.color, | ||
backgroundColor = this.context.backgroundColor, | ||
} = this.props; | ||
const style = { | ||
width: '100%', | ||
flexDirection: 'row', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor, | ||
}; | ||
return ( | ||
<View key={key} style={style}> | ||
<View> | ||
<LoadingIndicator size={14} color={spinnerColor} /> | ||
</View> | ||
<Label | ||
style={{ | ||
fontSize: 14, | ||
margin: 2, | ||
color: textColor, | ||
}} | ||
text="Connecting..." | ||
/> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
export default connect<SelectorProps, _, _>(state => ({ | ||
loading: getLoading(state), | ||
}))(LoadingBanner); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters