-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 url #347
Comments
I had solution by using react-native-fetch-blob |
@hle50 Care to share any code, seems like i've hit the same problem as you. I'm working with react-native-fetch-blob but can't seem to get the SVG I've currently got a function which goes and fetches a remote image:
I've then got a function which generates a set of avatars, essentially a collection of
My render function then outputs the result of generateAvatars(). This works, if I replace the The code above is purely conceptual, so anything outside of what i've explained isn't worth pointing out :) Any help would be appriciated! |
This seems to work for me |
Thanks @nadude i'll test this tomorrow and let the thread know how it went! |
Any solution to this yet? |
@hle50 can u post ur solution? |
hi @msand does this only work for apps via expo and not when importing
Edit: Using react-native-fetch-blob and using it as a temp file uri works. import React from 'react'
import RNFetchBlob from 'react-native-fetch-blob'
import Svg, {
Image,
} from 'react-native-svg'
import { View } from 'react-native'
class SvgImage extends React.Component {
state = {
uri: undefined,
}
async componentWillMount() {
const res = await RNFetchBlob
.config({
// add this option that makes response data to be stored as a file,
// this is much more performant.
fileCache : true,
// by adding this option, the temp files will have a file extension
appendExt : 'jpg',
})
.fetch('GET', 'https://avatars2.githubusercontent.com/u/1131362?s=460&v=4')
this.setState({
uri: `file://${res.path()}`,
})
}
render() {
const { uri } = this.state
return (
<View>
<Svg
height="100"
width="100"
viewBox="0 0 100 100"
>
<Image
x="0"
y="0"
width="100%"
height="100%"
preserveAspectRatio="xMidYMid slice"
href={!uri ? require('./placeholder.png') : { uri }}
/>
</Svg>
</View>
)
}
} |
@ricklancee Oh, I didn't try in plain RN or iOS, just a Snack and Android. Having a filecache certainly seems like a great idea! Thanks for the example! |
@ricklancee that seems like a good solution. However, I am having trouble loading Can you post your package.json so that I can make sure I'm trying with the same set of files? I even started a new project to make sure it wasn't something else. Regards, |
@sanealytics i pasted the code from a typescript project so it might not be 100% working. Maybe check the RNFetchBlob docs if you installed it correctly https://github.com/wkh237/react-native-fetch-blob im using versions:
|
RN 0.54 now has Blob support and Expo will probably get in the next version later this month expo/expo#123 |
ah, that's what it is... thanks. |
OK, I am where you are (I think) after ejecting and hooking things up to the Android simulator (on ubuntu). I am also matching your version numbers. The good news is that it works. Unfortunately, it is unstable. When I start the app, no image show up initially, upon refresh, fallback image shows up. But it never changes to the fetched image. I then added am SVG text component to show the base uri. Here is the modestly modified code. I am using an android simulator now.
You use the above component like so from the main app
I guess that having to show the Should there be a delay of some sort? Regards |
@sanealytics I had the same issue on android where the image would not get switched out once loaded. This was my work around: switching the image component out for a new one:
|
hmm, unfortunately, I have the same behavior as before 😢 |
Currently I want to load image from url not from local, and this is the code I use and it is not working, please help me to resolve this
The text was updated successfully, but these errors were encountered: