【发布时间】:2022-01-12 20:07:45
【问题描述】:
我正在尝试在 React-Native 中使用 SVG 获取背景图案。
我使用“react-native-svg”库创建了一个组件,如下所示:
import React from "react";
import { SvgXml } from "react-native-svg";
const xml = `
<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'>
<g
fill='#ffb6c1'
fill-opacity='0.2'
>
<polygon
fill-rule='evenodd'
points='8 4 12 6 8 8 6 12 4 8 0 6 4 4 6 0 8 4'
/>
</g>
</svg>
`;
export default () => <SvgXml xml={xml} />;
然后我尝试将其导入 App.js,如下所示:
import React from 'react';
import { StyleSheet, ImageBackground, Text, View } from 'react-native';
import Header from './components/Header'
import SVG from './assets/4-point-star'
export default function App() {
return (
<View style={styles.container}>
<ImageBackground source={{uri: SVG}} style={styles.image}>
<View>
<Text style={styles.text}>Open up App.js to start working on your app!</Text>
</View>
</ImageBackground>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'black',
color: 'white',
alignItems: 'center',
justifyContent: 'center',
},
image: {
width: '100%',
height: '100%',
},
text: {
color: 'white'
},
});
感谢任何帮助
谢谢
【问题讨论】:
标签: reactjs react-native svg