-
-
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
Base64 image data not rendered in iOS #891
Comments
import React from 'react' const SvgComponent = props => ( export default SvgComponent Above code not working in iOS |
This seems to work fine at least: https://github.com/magicismight/react-native-svg-example/blob/5a972149f22e0464152d487e6aab015a368ba02a/examples/Svg.js#L153-L185 |
Sorry I couldn't understand. Is there a react-native-svg support for images in base64 or the only solution is to use the Image component from react-native? |
You can use it, but you need to use the href attribute: import React, { Component } from 'react';
import { View, StyleSheet, Image } from 'react-native';
import { Svg, G, Circle, Path, Image as SvgImage } from 'react-native-svg';
const b64 =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYoAAAEHCAYAAACwUAEWAAAABHNCSVQICAgIfAhkiAAADq5JREFU\neJzt3XusZeVZx/HvmjMX6I1DkUJbHQchUy7l4qDA0NYZCmqpFqZqpTQmOIUGa7SMaWyspqlJW6uJ\nf5gotlWotNS2iUmllyi1pDMTUaEWOsMMt5KUS8BykZlhhsswt8c/9j7OYeYczt5nve96197r+0ne\nDAHW+zzv3nPe31lrn7MWSJIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIkSZIk\nSZIkSfVUpRuQ0olJ4FJgGfX+bj8JfBaqAym6kiS1QpwHsR0iEo2vQUyUXpUkKYmoIB5OGBJTY23p\nlUltsKB0A1ICpwJLM8z7jgxzSiPHoNA4OGvE5pVGikGhcXBmpnmXQ7wi09zSyDAoNA5yfuefK4Sk\nkWFQaBz8fMa5DQp1nkGhERevByYzFvBzCnWeQaFRl/s7foNCnWdQaNTl3sh/NvP8UusZFBp1uc8o\nFkO8KXMNqdUMCo26Ji4NZa4Rb4H4PYhj89aRpNaI8yA2QOyBeAbiYxALM9RZDLE/w607Dh2fTt87\nQCyDWD+tzvMQ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SJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS\nJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS\nJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmS\nJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSJEmSpNHzf/LMnJz3PpPV\nAAAAAElFTkSuQmCC\n';
class SvgNativeMethods extends Component {
static title = 'Tap the shapes to render the Image below based on the base64-data of the Svg';
state = {
base64: null,
};
alert = function() {
this.root.toDataURL(base64 => {
this.setState({
base64,
});
});
};
render() {
return (
<View>
<Svg
height="100"
width="150"
ref={ele => {
this.root = ele;
}}
>
<SvgImage
x={50}
width="150"
height="100"
href={{
uri: b64,
}}
/>
<G x="40" onPress={this.alert.bind(this)}>
<Circle
cx="32"
cy="32"
r="4.167"
fill={this.state.base64 ? 'red' : 'blue'}
/>
<Path
d="M55.192 27.87l-5.825-1.092a17.98 17.98 0 0 0-1.392-3.37l3.37-4.928c.312-.456.248-1.142-.143-1.532l-4.155-4.156c-.39-.39-1.076-.454-1.532-.143l-4.928 3.37a18.023 18.023 0 0 0-3.473-1.42l-1.086-5.793c-.103-.543-.632-.983-1.185-.983h-5.877c-.553 0-1.082.44-1.185.983l-1.096 5.85a17.96 17.96 0 0 0-3.334 1.393l-4.866-3.33c-.456-.31-1.142-.247-1.532.144l-4.156 4.156c-.39.39-.454 1.076-.143 1.532l3.35 4.896a18.055 18.055 0 0 0-1.37 3.33L8.807 27.87c-.542.103-.982.632-.982 1.185v5.877c0 .553.44 1.082.982 1.185l5.82 1.09a18.013 18.013 0 0 0 1.4 3.4l-3.31 4.842c-.313.455-.25 1.14.142 1.53l4.155 4.157c.39.39 1.076.454 1.532.143l4.84-3.313c1.04.563 2.146 1.02 3.3 1.375l1.096 5.852c.103.542.632.982 1.185.982h5.877c.553 0 1.082-.44 1.185-.982l1.086-5.796c1.2-.354 2.354-.82 3.438-1.4l4.902 3.353c.456.313 1.142.25 1.532-.142l4.155-4.154c.39-.39.454-1.076.143-1.532l-3.335-4.874a18.016 18.016 0 0 0 1.424-3.44l5.82-1.09c.54-.104.98-.633.98-1.186v-5.877c0-.553-.44-1.082-.982-1.185zM32 42.085c-5.568 0-10.083-4.515-10.083-10.086 0-5.568 4.515-10.084 10.083-10.084 5.57 0 10.086 4.516 10.086 10.083 0 5.57-4.517 10.085-10.086 10.085z"
fill="blue"
/>
</G>
{this.state.base64 && (
<SvgImage
y="50"
width="150"
height="100"
href={{
uri: `data:image/png;base64,${this.state.base64}`,
}}
/>
)}
</Svg>
<View style={{ width: 150, height: 100, borderWidth: 1, marginTop: 5 }}>
{this.state.base64 && (
<Image
source={{ uri: `data:image/png;base64,${this.state.base64}` }}
style={{ width: 150, height: 100 }}
/>
)}
</View>
</View>
);
}
}
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<SvgNativeMethods />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
}); |
Thank you! I'm testing this solution but it's making my svg completely black. Any idea what could it be? |
Old version perhaps? Are you using Expo? |
No, I'm using a project with native modules. I'm not using the last RN version so I'll update it to the latest and give feedback. Thanks! |
Sorry my issue was apparently related to a missing transform attribute in the Image. Thanks! |
data:image/svg+xml;base64,...... does not work for SvgImage |
No description provided.
The text was updated successfully, but these errors were encountered: