2018-04-17 05:41:14 +00:00
|
|
|
// 修改后
|
2016-10-21 07:05:57 +00:00
|
|
|
import React, { Component } from 'react';
|
2017-12-25 13:48:44 +00:00
|
|
|
import { WebView, View, StyleSheet, Platform } from 'react-native';
|
2016-10-21 07:54:29 +00:00
|
|
|
import renderChart from './renderChart';
|
2018-04-17 05:41:14 +00:00
|
|
|
import renderChartNoFirst from './renderChart'
|
2016-10-21 07:05:57 +00:00
|
|
|
import echarts from './echarts.min';
|
|
|
|
|
|
2018-04-17 05:41:14 +00:00
|
|
|
|
2016-10-21 07:05:57 +00:00
|
|
|
export default class App extends Component {
|
2018-04-17 05:41:14 +00:00
|
|
|
// 预防过渡渲染
|
2018-01-03 00:27:48 +00:00
|
|
|
|
2018-04-17 05:41:14 +00:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
|
|
|
const thisProps = this.props || {}
|
|
|
|
|
nextProps = nextProps || {}
|
|
|
|
|
if (Object.keys(thisProps).length !== Object.keys(nextProps).length) {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
for (const key in nextProps) {
|
|
|
|
|
if (JSON.stringify(thisProps[key]) != JSON.stringify(nextProps[key])) {
|
|
|
|
|
// console.log('props', key, thisProps[key], nextProps[key])
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false
|
2018-01-03 00:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
2016-11-03 02:43:21 +00:00
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
|
if(nextProps.option !== this.props.option) {
|
|
|
|
|
|
2018-04-17 05:41:14 +00:00
|
|
|
// 解决数据改变时页面闪烁的问题
|
|
|
|
|
this.refs.chart.injectJavaScript(renderChart(nextProps,false))
|
|
|
|
|
}
|
2018-01-03 00:27:48 +00:00
|
|
|
}
|
|
|
|
|
|
2016-10-21 07:05:57 +00:00
|
|
|
render() {
|
2018-04-17 05:41:14 +00:00
|
|
|
if (Platform.OS == 'android'){
|
|
|
|
|
return (
|
|
|
|
|
<View style={{flex: 1, height: this.props.height || 400,}}>
|
|
|
|
|
<WebView
|
|
|
|
|
ref="chart"
|
|
|
|
|
scrollEnabled = {false}
|
2018-05-19 10:28:21 +00:00
|
|
|
javaScriptEnabled={true}
|
2018-04-17 05:41:14 +00:00
|
|
|
injectedJavaScript = {renderChart(this.props,true)}
|
|
|
|
|
style={{
|
|
|
|
|
height: this.props.height || 400,
|
|
|
|
|
}}
|
|
|
|
|
//source={require('./tpl.html')}
|
|
|
|
|
source={{uri: 'file:///android_asset/tpl.html'}}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
}else{
|
|
|
|
|
return (
|
|
|
|
|
<View style={{flex: 1, height: this.props.height || 400,}}>
|
|
|
|
|
<WebView
|
|
|
|
|
ref="chart"
|
|
|
|
|
scrollEnabled = {false}
|
|
|
|
|
scalesPageToFit={false}
|
|
|
|
|
injectedJavaScript = {renderChart(this.props,true)}
|
|
|
|
|
style={{
|
|
|
|
|
height: this.props.height || 400,
|
|
|
|
|
}}
|
|
|
|
|
source= {Platform.OS === 'ios' ? require('./tpl.html') : { uri: 'file:///android_asset/tpl.html' }}
|
|
|
|
|
/>
|
|
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-21 07:05:57 +00:00
|
|
|
}
|
|
|
|
|
}
|