31 lines
934 B
JavaScript
31 lines
934 B
JavaScript
import React, { Component } from 'react';
|
|
import { WebView, View, StyleSheet } from 'react-native';
|
|
import renderChart from './renderChart';
|
|
import echarts from './echarts.min';
|
|
|
|
export default class App extends Component {
|
|
componentWillReceiveProps(nextProps) {
|
|
if(nextProps.option !== this.props.option) {
|
|
this.refs.chart.reload();
|
|
}
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<View style={{flex: 1, height: this.props.height || 400,}}>
|
|
<WebView
|
|
ref="chart"
|
|
scrollEnabled = {false}
|
|
injectedJavaScript = {renderChart(this.props)}
|
|
style={{
|
|
height: this.props.height || 400,
|
|
}}
|
|
source={require('./tpl.html')}
|
|
style={{backgroundColor: this.props.option.backgroundColor || '#FFFFFF'}}
|
|
onMessage={event => this.props.onPress ? this.props.onPress(JSON.parse(event.nativeEvent.data)) : null}
|
|
/>
|
|
</View>
|
|
);
|
|
}
|
|
}
|