2016-10-21 07:05:57 +00:00
|
|
|
import React, { Component } from 'react';
|
2019-08-17 05:29:01 +00:00
|
|
|
import { View, StyleSheet, Platform } from 'react-native';
|
2016-10-21 07:54:29 +00:00
|
|
|
import renderChart from './renderChart';
|
2016-10-21 07:05:57 +00:00
|
|
|
import echarts from './echarts.min';
|
2019-08-17 05:29:01 +00:00
|
|
|
import WebView from "react-native-webview";
|
|
|
|
|
import getTpl from "./tpl" ;
|
2016-10-21 07:05:57 +00:00
|
|
|
|
|
|
|
|
export default class App extends Component {
|
2018-01-03 00:27:48 +00:00
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.setNewOption = this.setNewOption.bind(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-11-03 02:43:21 +00:00
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
|
if(nextProps.option !== this.props.option) {
|
|
|
|
|
this.refs.chart.reload();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-03 00:27:48 +00:00
|
|
|
setNewOption(option) {
|
|
|
|
|
this.refs.chart.postMessage(JSON.stringify(option));
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-21 07:05:57 +00:00
|
|
|
render() {
|
|
|
|
|
return (
|
2016-11-03 02:43:21 +00:00
|
|
|
<View style={{flex: 1, height: this.props.height || 400,}}>
|
|
|
|
|
<WebView
|
|
|
|
|
ref="chart"
|
|
|
|
|
scrollEnabled = {false}
|
|
|
|
|
injectedJavaScript = {renderChart(this.props)}
|
|
|
|
|
style={{
|
|
|
|
|
height: this.props.height || 400,
|
2017-10-02 15:54:21 +00:00
|
|
|
backgroundColor: this.props.backgroundColor || 'transparent'
|
2016-11-03 02:43:21 +00:00
|
|
|
}}
|
2017-12-25 13:48:44 +00:00
|
|
|
scalesPageToFit={Platform.OS !== 'ios'}
|
2018-11-15 06:46:47 +00:00
|
|
|
originWhitelist={['*']}
|
2019-08-17 05:29:01 +00:00
|
|
|
source={{ html:getTpl() }}
|
2017-05-13 01:15:33 +00:00
|
|
|
onMessage={event => this.props.onPress ? this.props.onPress(JSON.parse(event.nativeEvent.data)) : null}
|
2016-11-03 02:43:21 +00:00
|
|
|
/>
|
|
|
|
|
</View>
|
2016-10-21 07:05:57 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|