Skip to content

Commit 3a5470d

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 0 to 1 and flex value of 'PhotoView' also will be changed from 0 to 1. Fixes #2896.
1 parent 13c1e61 commit 3a5470d

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/lightbox/Lightbox.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +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({
20-
img: {
21-
height: 300,
22-
flex: 1,
23-
},
21+
img: {},
2422
header: {},
2523
overlay: {
2624
backgroundColor: 'black',
@@ -46,12 +44,14 @@ type Props = {
4644

4745
type State = {
4846
movement: 'in' | 'out',
47+
loaded: 0 | 1,
4948
};
5049

5150
class Lightbox extends PureComponent<Props, State> {
5251
props: Props;
5352
state: State = {
5453
movement: 'out',
54+
loaded: 0,
5555
};
5656

5757
handleImagePress = () => {
@@ -90,6 +90,12 @@ class Lightbox extends PureComponent<Props, State> {
9090
movement: this.state.movement,
9191
});
9292

93+
showImage = () => {
94+
this.setState(({ loaded }, props) => ({
95+
loaded: 1,
96+
}));
97+
};
98+
9399
render() {
94100
const { src, message, auth } = this.props;
95101
const footerMessage =
@@ -110,10 +116,12 @@ class Lightbox extends PureComponent<Props, State> {
110116
realm={auth.realm}
111117
{...this.getAnimationProps()}
112118
/>
119+
{!this.state.loaded && <LoadingIndicator />}
113120
<PhotoView
114121
source={resource}
115-
style={[styles.img, { width }]}
122+
style={[styles.img, { width }, { flex: this.state.loaded }]}
116123
resizeMode="contain"
124+
onLoadEnd={this.showImage}
117125
onTap={this.handleImagePress}
118126
/>
119127
<AnimatedLightboxFooter

0 commit comments

Comments
 (0)