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

[Android] not all images are shown #13600

Closed
sergey-akhalkov opened this issue Apr 20, 2017 · 25 comments
Closed

[Android] not all images are shown #13600

sergey-akhalkov opened this issue Apr 20, 2017 · 25 comments
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@sergey-akhalkov
Copy link

sergey-akhalkov commented Apr 20, 2017

Hey guys,

Description

I've created sample app, that should show 100 images.
Actual: App randomly shows around 50% of the images. example1, example2
Expected: All 100 images should be shown.

Reproduction Steps and Sample Code

Download the app where the issues reproduces: rnapp.zip

Repro steps:

  1. Perform react-native init rnapp command.
  2. Add 100 images in the ./images folder
  3. Change index.android.js file like this:
import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Image,
  View
} from 'react-native';

export default class rnapp extends Component {
  render() {
    return (
      <View style={styles.container}>
        <View style={{ flexDirection: 'row', flexWrap: 'wrap' }}>
          <Image style={styles.image} resizeMode={Image.resizeMode.contain} source={require("./images/laptop_phone_howitworks.1.png")}/>
          ...
          <Image style={styles.image} resizeMode={Image.resizeMode.contain} source={require("./images/laptop_phone_howitworks.100.png")}/>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  image: {
    width: 25,
    height: 25,
    margin: 3,
  }
});

AppRegistry.registerComponent('rnapp', () => rnapp);

Additional Information

  • React Native version: 0.43.3
  • Platform: Android
  • Development Operating System: Windows
  • Dev tools: Android Studio version 2.3.1, Android SDK version 23
@nihgwu
Copy link
Contributor

nihgwu commented Apr 20, 2017

That's a known bug for quit a long time
#7408 #9581 #10470 I believe they are related
This would be a better choice, #9581 (comment)

@sergey-akhalkov
Copy link
Author

sergey-akhalkov commented Apr 21, 2017

Hi @nihgwu, thanks for the clarification. Do I get it right that the root cause of this issues is a memory problem? As of now, I've found a workaround that fixes the issue: add android:largeHeap="true" to AndroidManifest.xml Application section.

@jcampalo
Copy link

@sergey-akhalkov Thanks it worked for me

@surmerming
Copy link

@sergey-akhalkov I tried as your method, but it does not help

@pepavesely
Copy link

I see android:largeHeap="true" as an accepted solution very often but this is not the right solution. You just enlarge the heap (if the target device has an ability to do so) which means that your application might work longer but might fail eventually anyway.

@treemore
Copy link

@pepavesely that is right . before i set android:largeHeap="true" ,the image will not show when i get 50 records. but after i set it , i can only show 200 records.
use ListView and set renderItem use an Image ,when every Image uri different ,the problem will be come.
if use FlatList ,Image will be show right .but FlatList has a delay problem..
#12884

@treemore
Copy link

every renderItem has a different Image uri .
if all the image has the same uri will work well.

@pepavesely
Copy link

For me, #10569 worked very well. I'm using ScrollViews and setting removeClippedSubviews={true} solved my issue.

@treemore
Copy link

@pepavesely . very thank you.

@jjoe64
Copy link

jjoe64 commented Aug 2, 2017

It's also worth mention that with the property resizeMethod="resize" I was able to display large images, even though I don't resize the image.

@stale
Copy link

stale bot commented Oct 17, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Oct 17, 2017
@stale stale bot closed this as completed Oct 24, 2017
@adielhercules
Copy link

I am having this issue, images are shown (local & remote) on iOS but not in Android

@iamtekeste
Copy link

I am facing this issue too, not all images render inside my FlatList. Is this related to memory issue? My images are large in size.

@itneste
Copy link

itneste commented Nov 2, 2017

@adielhercules @iamtekeste
try this
Image: resizeMethod="resize"
FlatList: removeClippedSubviews={true} scrollEventThrottle={16}

but on the IOS removeClippedSubviews={true} may cause problem.see 8607

@adielhercules
Copy link

@itneste totally correct, I am using the resizeMethod="resize" over Image and it just works, I did not have to add any other props in my case.

Thanks for the suggestion.

I just realized that we can find these props in the react-native documentation. If it helps anyone else here is the link. And for further information, if you are wondering why these tree options in the resizeMethod prop, here is the documentation of the lib (fresco) that is used by react-native under the hood.

@iamtekeste
Copy link

Adding removeClippedSubviews={true} to my FlatList solved it for me.
Thanks everyone!

@pacozaa
Copy link

pacozaa commented Nov 15, 2017

@sergey-akhalkov Problem solved! Thank you ;)

@pacozaa
Copy link

pacozaa commented Nov 16, 2017

android:largeHeap="true" only works for android 7.0 but not android 5.0

@MultiformMusic
Copy link

removeClippedSubviews={true} works for me on android and ios, good !!

@fatfatson
Copy link

I want to know what's the size of image cache ? can we set it manually ?
I try to load 30 2500x1500 pics at the same time, the memory cost should be 2500x1500x4x30=450MB, my tablet device has 4G ram, it's enough for holding them on, but I couldn't display all the pics correctly, some are randomly empty.

@fatfatson
Copy link

I have found the reason: it's due to RN ImageView's backend fresco
it has a cache pool for decoded bitmap, whose default size is calculated by the available runtime memory:
image

when the pool is exhausted, it will throw a PoolSizeViolationException exception:
image

but RN don't process this well(just ignored):
image

so we may set a bigger pool size when initializing fresco in com.facebook.react.modules.fresco.FrescoModule#initialize

@shubhi15
Copy link

Changing windowsize property of flatlist (VirtualizedList) to {5} worked for me.

@okboy5555
Copy link

我在ios能够显示图片,安卓7.1版本以前能够显示,7.1之后版本大部分图片不能显示

@h-asadollahi
Copy link

I found the solution myself.
It was very easy. Just load a child component instead of rendering in a rowRenderer.

render() {
    return (
            <View style={{flex: 1}}>
                <RecyclerListView
                    ref="memories_ref"
                    forceNonDeterministicRendering={true}
                    layoutProvider={this._layoutProvider}
                    dataProvider={this.state.dataProvider}
                    rowRenderer={this.renderMemories.bind(this)}
                    renderAheadOffset={50}
                />
            </View>
        );

}

and in rowRenderer:

renderMemories(type, item) {
    return (<Memory liked={liked} item={item}/>);
}

I've also answered this question here:
https://stackoverflow.com/a/50085668/1670669

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests