avr*_*iis 0 react-native victory-charts
我正在使用Expo的应用程序中使用Victory Native图表库。然而,我遇到了一些胜利组件导致应用程序崩溃的问题,例如这对于使用库非常重要。有谁知道是否可以与Expo一起使用?<VictoryChart>victory-native
我在这里了解到 Expo 不允许使用 Victory Native 可能使用的原生元素?
这是我所做的:
exp init expo-victory-native-democd expo-victory-native-demo(从这里)npm install --save victory-native react-native-svgnpm installreact-native link react-native-svg然后我玩过这里找到的演示,即将一些 Victory 组件放入 App.js,但是当我运行exp start应用程序时,如果 example<VictoryChart>存在,则在启动后立即崩溃,如果我只使用example ,则不是问题<VictoryBar>。
有一个使用 Victory Native 和 Expo 的演示(见这里),但我需要将它与一个现有的、更大的项目构建一起使用 Expo,并且尝试在此演示之外使用 Victory Native 失败,如上所述。这也使用旧版本的 Expo 和 Victory Native。
为了完整起见,这是我崩溃的 App.js:
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { VictoryBar, VictoryChart, VictoryTheme } from "victory-native";
const data = [
{ quarter: 1, earnings: 13000 },
{ quarter: 2, earnings: 16500 },
{ quarter: 3, earnings: 14250 },
{ quarter: 4, earnings: 19000 }
];
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<VictoryChart width={350} theme={VictoryTheme.material}>
<VictoryBar data={data} x="quarter" y="earnings" />
</VictoryChart>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Run Code Online (Sandbox Code Playgroud)
并且在<VictoryChart>删除时不会崩溃:
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { VictoryBar, VictoryChart, VictoryTheme } from "victory-native";
const data = [
{ quarter: 1, earnings: 13000 },
{ quarter: 2, earnings: 16500 },
{ quarter: 3, earnings: 14250 },
{ quarter: 4, earnings: 19000 }
];
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<VictoryBar data={data} x="quarter" y="earnings" />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Run Code Online (Sandbox Code Playgroud)
这是package.json:
{
"main": "node_modules/expo/AppEntry.js",
"private": true,
"dependencies": {
"expo": "^25.0.0",
"react": "16.2.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-25.0.0.tar.gz",
"react-native-svg": "^6.3.1",
"victory-native": "^0.17.2"
}
}
Run Code Online (Sandbox Code Playgroud)
通过执行以下操作解决了该问题:
rm -rf node_modules/ react-native-svg从package.json(见这里)中删除npm install --save lodash yarn install然后在exp start我得到以下内容之后:
App.js 看起来是这样的:
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { VictoryBar, VictoryChart, VictoryTheme } from "victory-native";
const data = [
{ quarter: 1, earnings: 13000 },
{ quarter: 2, earnings: 16500 },
{ quarter: 3, earnings: 14250 },
{ quarter: 4, earnings: 19000 }
];
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<VictoryChart width={350} theme={VictoryTheme.material}>
<VictoryBar data={data} x="quarter" y="earnings" />
</VictoryChart>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Run Code Online (Sandbox Code Playgroud)
并且package.json:
{
"main": "node_modules/expo/AppEntry.js",
"private": true,
"dependencies": {
"expo": "^25.0.0",
"lodash": "^4.17.5",
"react": "16.2.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-25.0.0.tar.gz",
"victory-native": "^0.17.2"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3012 次 |
| 最近记录: |