Why my images aren't showing in React Native - react-native

I'm trying to show some images in my React Native app. It's a simple app, only for Android. The app get informations from an API. The initial View is a list of items and when I click in one item, it gets more info from the API and show in a new page. I also get some urls that points to images that are kept in a S3 bucket in AWS.
This is how I show the images:
<ScrollView>
{this.state.urls.map(url => {
<Image
source={{uri: url}}
style={{width:400, height:200}}
/>
}
</ScrollView>
The problem is that it's not showing those images. I can see that there is a part of the page that is for the image. I can see that because if a put the image first and after that some text, the text will appear at the bottom of the page. I don't know what is going on that the image doesn't appear.
I searched for an answer, found something about using https instead of http (at least for iOS). Found that I need to set width and height. I already did those things and others but it's not working.
I also tried just picking a image from the internet and putting it url direct in uri but it still doesnt't work.

You're missing a return statement in your map function.
<ScrollView>
{this.state.urls.map(url => {
return <Image
source={{uri: url}}
style={{width:400, height:200}}
/>
}
</ScrollView>
UPDATE
I just tried the url that you provided in the above comment and it doesn't work on my device. I tried a different image from the internet this one and it works. There may also be something that is stopping you from accessing the images from within a mobile app.
To debug further I try would a single <Image .../> with the image hosted on AWS and see if you can get that to show. There may need to be some AWS configuration that you need to change to allow the image to be accessed from a mobile device.

Assuming your image URLs are accessible in your application.
The below code will show your images. Actually you forgot to return a component from the map which is a must have.
<ScrollView>
{this.state.urls.map(url => {
return <Image
source={{uri: url}}
style={{width:400, height:200}} /> }
}
</ScrollView>

Related

Video in full Screen not working in Android react-native-video

<Video
source={{ uri: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" }}
resizeMode="cover"
repeat
controls
fullscreen = {this.state.fullscreen}
fullscreenOrientation = {"landscape"}
//onBuffer={this.onBuffer} // Callback when remote video is buffering
//onError={this.videoError} // Callback when video cannot be loaded
style={styles.backgroundVideo}
/>
I am using this above code and in the Android manifest orientation in portrait. I am click on the full screen state has been changes according to it. But it just exit in a second. As i am getting a little fluctuation and maybe the app is showing full screen and then exit from full screen. But i am not able to see it. Or you can say full screen is not working. As in the IOS it is working properly. I tried multiple from github but not able to achieve it.

Image is disappearing with same uri

I am running sample application. I am using amazon s3 to store the profile pics. So, I have to use the same url for the profile pictures. I give the Image a unique key prop to try and get it to reload the image, but it displays a previously uploaded image. It means cache is not cleared for image component.
I tried this below code. Image should be updated perfectly but any changes doing in that screen then image will be disappearing.
This issue only appears in android.
<Image
source={{uri: this.state.uri + '?' + new Date()}}
/>
Please refer this link:- enter link description here
Screenshot:-
set a local const variable as
const url = {uri: this.state.uri + '?' + new Date()};
Use the url as follows:
<Image
source={uri}
/>

React-native WebView WebKitErrorDomain Error Code: 204

I'm trying to use WebView to display a video hosted on reddit. The link i am using is https://v.redd.it/e3u0b3ej71k11/DASH_2_4_M which is for this post https://v.redd.it/e3u0b3ej71k11/ . On IOS the video will automatically go full screen and play but gives me this error
On android it doesn't give me an error but it has a video that is just black, but does have the correct run time. I'm not really sure how the endpoint DASH_2_4_M works but I got that url from reddit api.
<WebView
source={{uri: this.state.data[0].data.children[0].data.media.reddit_video.fallback_url}}
style={{height: 650, width: '100%'}}
bounces={false}
scrollEnable={false}
/>

Possibility of loading Google places images in react-native Image component?

I am trying to find a way to load image reference I get from places api into places photo API using Image component of react-native like below,
const imageLink = 'https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=CmRaAAAAuZ36wzrMYCVNWM1smQkRKuQyXecPgRpcsMfrSqbJM0EUTXZ62j8Ljxtk8HsxohXbtAwZAwmj_F3HmDwLoQaH9qt2TZJhhA6EuXK41UFo0Ow750MJujtrr5hgHR2lF7EXEhCkWj_dZ4LefrYzLU1_5RF1GhTR7Ggem5IJ-v7V2U8fjKoU9tBUOg&key=--MyKey--'
return (
<View >
<TouchableHighlight >
<View>
<Image
style={{width:64, height:64,flex:1,backgroundColor:'red'}}
source={{uri: imageLink}}
/>
</View>
</TouchableHighlight>
</View>
);
I am getting only empty placeholder with above code. However, I am able to load this link in browser.One caveat is that google places photo's link is redirecting to some other url which then displays image in browser. Am I doing it right? or is there any other way I can accomplish the same. Note: I tried react-native-network-image library as well.
You can have a look at the ImagePrefetch function in googleplace module:
https://github.com/srirangan/googleplaces.js/blob/master/test/ImageFetchTest.js
However, I am having issue with the whole module at the moment because of the line var https = require("https"); called in this specific function.
Not sure if it's an issue with new version of RN (upgraded to 0.55 recently) or just some other error in my new setup.
This worked perfectly in previous RN (was running on 0.48)

React Native Webview get html

I want to get html in web view.
I read react-native-doc(https://facebook.github.io/react-native/docs/webview.html#content) but I cannot found it.
Can I do this?
None of the answers above worked for me, but this did. It displays the received html content of the webview in the console:
const jsCode = 'window.ReactNativeWebView.postMessage(document.documentElement.innerHTML)'
return (
<WebView
injectedJavaScript={jsCode}
source={{ uri: 'https://www.whatever.com' }}
onMessage={event => console.log('Received: ', event.nativeEvent.data)}
javaScriptEnabled
/>
)
I found this.
https://github.com/alinz/react-native-webview-bridge
But I could not use this in android. This works only in android.
I don't know this problem is only my problem or library problem.
In Android I use onNavigationStateChange.
Read https://github.com/facebook/react-native/issues/586#issuecomment-90826117
I think this is not good way. But I really need this. so I used this.
In case anyone comes across this in the future. You options here is to use javascript. You can use injectedJavaScript on the webview to inject a window.postmessge($('body').html()) and then handle the reply in the onMessage function on the webview. The cleaner way would be to fetch the page yourself and then load it into the webview.