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

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)

Related

Downloadinf PDF from React native webview gives "invaild pdf format or corrupted" after opening on Android but works fine on iOS

I'm using the below code to open an URL. Downloading a PDF from React native webview after opening on Android gives:
"invaild pdf format or corrupted"
but it works fine on iOS.
<WebView
renderToHardwareTextureAndroid={true}
startInLoadingState={isLoading}
renderLoading={() => {
return <BarIndicator color="blue" />;
}}
mediaPlaybackRequiresUserAction={false}
javaScriptEnabled={true}
source={{
uri: webviewUrl,
headers: webviewHeaders,
}}
style={drawerWebviewStyles.container}
/>
pdf doesn't work on android webview check this issue here you may look for other solution like download it and open it with pdf viewer
Seems to be a very well known 5 year old problem
https://react-native.canny.io/feature-requests/p/android---webview-cannot-display-pdf
that needs saveas file.pdf then either call the native pdf handler
or
embed/customise a simple maintained js viewer such as
https://github.com/xcarpentier/rn-pdf-reader-js

Picache gif is a still image (Expo + ReactNative)

I'm trying to speed up loading a bunch of gifs, but a big limitation is that I'm using Expo, and don't want to detach. I found Picache, which states it can be used just like react native Image. When the page loads though, everything loads super fast now, but the gifs are still and not 'gify'.
<Picache
source={{uri: someURL.gif)}}
style={{height: 300, width: 300, borderRadius: 10}}
/>
I've spent so long trynig to figure out how to speed up loading a bunch of images without detaching. Is there a way to make Picache work with gifs, or a similar easy way to implement?
**Before someone suggests, I've already tried... react-native-fast-image-expo but unfortunately it requires detaching as well. That is the desired package though.
If you don't want to bring out the project, you can replace it with this.
Until Expo added the module,
example:
import {Image} from "react-native-expo-image-cache";
// preview can be a local image or a data uri
const preview = { uri: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==" };
const uri = "https://firebasestorage.googleapis.com/v0/b/react-native-e.appspot.com/o/b47b03a1e22e3f1fd884b5252de1e64a06a14126.png?alt=media&token=d636c423-3d94-440f-90c1-57c4de921641";
<Image style={{ height: 100, width: 100 }} {...{preview, uri}} />
Get the local image from a remote URI
import {CacheManager} from "react-native-expo-image-cache";
const {uri} = this.props;
const path = await CacheManager.get(uri).getPath();
// if path is undefined, the image download has failed

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}
/>

Why my images aren't showing in 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>

React-native get cookies from WebView

I have a webview, and I am logging into a website in it, and I want the auth cookies to persist the login, so I can just set the cookie for the user every time, so they don't need to log in every time.
Is this possible?
How can I get the cookie from the webview?
Here is my webview:
<View style={styles.container}>
<WebView
source={{ uri: "anywebsite.com" }}
onLoadStart={this.loadingStarted}
onLoad={this.loadingEnded}
/>
</View>
You can use react-native-cookies for handling cookies in RN.
Note that there is also an attribute on WebView called thirdPartyCookiesEnabled. You should try it out and see if it works for your case, cause manually setting and getting the cookies in the WebView takes some time to set up even with a library like react-native-cookies.