Skip to content

Commit 20ed076

Browse files
Lightbox spinner: Show spinner in Lightbox when slow to load
Previously, Lightbox remains black until an image is loaded from the server. Spinner will be shown to user in Lightbox, while an image is being loaded. New state 'loaded' is defined in Lightbox component. When an image is loaded, the state will be changed from false to true and display value of 'PhotoView' also will be changed from 'none' to 'flex'. Fixes #2896.
1 parent b0730a0 commit 20ed076

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/lightbox/Lightbox.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import { constructActionSheetButtons, executeActionSheetAction } from './Lightbo
1515
import { NAVBAR_SIZE } from '../styles';
1616
import { getGravatarFromEmail } from '../utils/avatar';
1717
import { navigateBack } from '../actions';
18+
import { LoadingIndicator } from '../common';
1819

1920
const styles = StyleSheet.create({
2021
img: {
21-
height: 300,
2222
flex: 1,
2323
},
2424
header: {},
@@ -45,12 +45,14 @@ type Props = {
4545

4646
type State = {
4747
movement: 'in' | 'out',
48+
loaded: boolean,
4849
};
4950

5051
class Lightbox extends PureComponent<Props, State> {
5152
props: Props;
5253
state: State = {
5354
movement: 'out',
55+
loaded: false,
5456
};
5557

5658
handleImagePress = () => {
@@ -89,12 +91,19 @@ class Lightbox extends PureComponent<Props, State> {
8991
movement: this.state.movement,
9092
});
9193

94+
showImage = () => {
95+
this.setState({
96+
loaded: true,
97+
});
98+
};
99+
92100
render() {
93101
const { src, message, auth } = this.props;
94102
const footerMessage =
95103
message.type === 'stream' ? `Shared in #${message.display_recipient}` : 'Shared with you';
96104
const resource = getResource(src, auth);
97105
const { width, height } = Dimensions.get('window');
106+
const displayImage = this.state.loaded ? 'flex' : 'none';
98107

99108
return (
100109
<View style={styles.container}>
@@ -109,10 +118,12 @@ class Lightbox extends PureComponent<Props, State> {
109118
realm={auth.realm}
110119
{...this.getAnimationProps()}
111120
/>
121+
{!this.state.loaded && <LoadingIndicator />}
112122
<PhotoView
113123
source={resource}
114-
style={[styles.img, { width }]}
124+
style={[styles.img, { width }, { display: displayImage }]}
115125
resizeMode="contain"
126+
onLoadEnd={this.showImage}
116127
onTap={this.handleImagePress}
117128
/>
118129
<AnimatedLightboxFooter

0 commit comments

Comments
 (0)