Setting image source to Firebase Storage URL with React Native

Viewed 4830

So I am trying to set a image source to the download url that I get back from Firebase Storage...the issue is that it is not showing the image but the console and download url both show correct Storage urls to pictures... here is my code that I currently have:

this.state = {
      itemDataSource: ds,
      modalVisible: false,
      user: undefined,
      imgSource: undefined,
    };

  getTrucks(truckRef, storageRef) {
    truckRef.once('value', (snap) => {
      console.log(snap.val());
      // console.log(snap.key);
      let trucks = [];
      snap.forEach((trucksSnap) => {
        console.log(trucksSnap.key);
        uid = trucksSnap.key;
        this.setState({user: uid});
        trucksSnap.forEach((truckSnap) => {
          console.log(truckSnap.key);
          console.log(truckSnap.val());
          let truck = truckSnap.val();
          trucks.push({
            uid: uid,
            name: truck.name,
            food: truck.foodType,
            desc: truck.description,
            menu: truck.menu,
            phone: truck.phone, 
          });
        });
      });
      console.log(trucks);
      this.setState({
        itemDataSource: this.state.itemDataSource.cloneWithRows(trucks)
      });
    });
  }

getPics(storageRef) {
        setTimeout(() => {
        storageRef.ref('trucks/' + this.state.user + '/pic-1').getDownloadURL()
          .then((url) => {
            console.log(url);
            this.setState({imgSource: url});
          });
        }, 3000);
      }

<Image
  source={{uri: this.state.imgSource}} 
  style={styles.iosCardImage}/>

the Image is in the render function and there is no image that shows up on screen but the console shows it other wise as the actual url that I can click on and see the image

console log

I did look at other example questions though there was not an actual working answer posted or checked as correct.

React-Native: Download Image from Firebase Storage

Load and return an image from Firebase database/storage in React Native

React Native is at version 0.45.1 & Firebase is at version 4.1.3

Can someone please help me to set the source tag correctly who has done it before? Thank you

3 Answers

I fixed the problem with this... path/android/app/src/main/AndroidManifest.xml

android:largeHeap="true

<application
  android:name=".MainApplication"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:roundIcon="@mipmap/ic_launcher_round"
  android:allowBackup="false"
  android:largeHeap="true"
  android:theme="@style/AppTheme">

I see android:largeHeap="true" as an accepted solution very often but this is not the right solution. We 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.

Related