Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Loading Twice #29

Closed
drewg233 opened this issue Apr 8, 2019 · 2 comments
Closed

Image Loading Twice #29

drewg233 opened this issue Apr 8, 2019 · 2 comments

Comments

@drewg233
Copy link

drewg233 commented Apr 8, 2019

Hello, I am not sure if I am doing something wrong, but basically I noticed images are loading twice before being presented. So in my case I see a flash of white in between showing the placeholder and the actual image.

import React from 'react';
import { StyleSheet, Text, View, Image } from 'react-native';
import ShimmerPlaceHolder from 'react-native-shimmer-placeholder';

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = { isLoaded: false };
  }

  handleLoad(event) {
    console.log(event.nativeEvent.loaded === event.nativeEvent.total)
  }

  render() {
    const { isLoaded } = this.state;

    return (
      <View style={styles.container}>
      <ShimmerPlaceHolder
        width={200}
        height={200}
        style={{ width: 200, height: 200, borderRadius: 100 }}
        visible={isLoaded}
        backgroundColorBehindBorder={'white'}
      >
        <Image
          style={{ width: 200, height: 200, borderRadius: 100 }}
          source={{ uri: 'https://images.pexels.com/photos/2082087/pexels-photo-2082087.jpeg?cs=srgb&dl=apartment-bed-bedroom-2082087.jpg&fm=jpg' }}
          onLoad={() => { this.setState({ isLoaded: true }); }}
          onProgress={ this.handleLoad.bind(this) }
        />
      </ShimmerPlaceHolder>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

As you can see I added an onProgress on the image that only logs if the image is done loading. If you run the above code you can see false 266 times, then a true, then you see false again another 266 times and then another last true

@tomzaku
Copy link
Owner

tomzaku commented May 20, 2019

@drewg233 Did you find the solution of this problem.

@tomzaku tomzaku closed this as completed Sep 1, 2020
tomzaku pushed a commit that referenced this issue Sep 3, 2020
@tomzaku
Copy link
Owner

tomzaku commented Sep 3, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants