Merge d659fbcb33 into 0ae9a6386c
This commit is contained in:
commit
c2cd210453
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
## install
|
## install
|
||||||
|
|
||||||
$ npm install native-echarts --save
|
$ npm install native-echarts react-native-webview --save
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
@ -80,6 +80,7 @@ screenshots:
|
||||||

|

|
||||||
|
|
||||||
### Android
|
### Android
|
||||||
|
copy tpl.html to android\app\src\main\assets
|
||||||
|
|
||||||
Open the Android project in the android directory with Android Studio and click run.
|
Open the Android project in the android directory with Android Studio and click run.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,40 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { WebView, View, StyleSheet, Platform } from 'react-native';
|
import { View, StyleSheet, Platform } from 'react-native';
|
||||||
import renderChart from './renderChart';
|
import renderChart from './renderChart';
|
||||||
|
import WebView from 'react-native-webview';
|
||||||
import echarts from './echarts.min';
|
import echarts from './echarts.min';
|
||||||
|
// 版本变更https://zhuanlan.zhihu.com/p/89494013
|
||||||
export default class App extends Component {
|
export default class App extends Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.state = {chart:null};
|
||||||
|
// refs 弃用了 https://reactjs.org/docs/refs-and-the-dom.html#legacy-api-string-refs
|
||||||
|
this.chart = null;
|
||||||
|
this.setChart = element => {
|
||||||
|
this.setState({chart:element})
|
||||||
|
};
|
||||||
this.setNewOption = this.setNewOption.bind(this);
|
this.setNewOption = this.setNewOption.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getDerivedStateFromProps(nextProps, prevState) {
|
||||||
|
if(nextProps.option !== prevState.option) {
|
||||||
|
prevState.chart && prevState.chart.reload();
|
||||||
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
return null;
|
||||||
if(nextProps.option !== this.props.option) {
|
|
||||||
this.refs.chart.reload();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
setNewOption(option) {
|
setNewOption(option) {
|
||||||
this.refs.chart.postMessage(JSON.stringify(option));
|
this.state.chart && this.state.chart.postMessage(JSON.stringify(option));
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View style={{flex: 1, height: this.props.height || 400,}}>
|
<View style={{flex: 1, height: this.props.height || 400,}}>
|
||||||
<WebView
|
<WebView
|
||||||
ref="chart"
|
ref = {this.setChart}
|
||||||
scrollEnabled = {false}
|
scrollEnabled = {false}
|
||||||
injectedJavaScript = {renderChart(this.props)}
|
injectedJavaScript = {renderChart(this.props)}
|
||||||
style={{
|
style={{
|
||||||
|
|
@ -34,7 +43,8 @@ export default class App extends Component {
|
||||||
}}
|
}}
|
||||||
scalesPageToFit={Platform.OS !== 'ios'}
|
scalesPageToFit={Platform.OS !== 'ios'}
|
||||||
originWhitelist={['*']}
|
originWhitelist={['*']}
|
||||||
source={require('./tpl.html')}
|
// source={require('./tpl.html')}
|
||||||
|
source= {Platform.OS === 'ios' ? require('./tpl.html') : { uri: 'file:///android_asset/tpl.html' }}
|
||||||
onMessage={event => this.props.onPress ? this.props.onPress(JSON.parse(event.nativeEvent.data)) : null}
|
onMessage={event => this.props.onPress ? this.props.onPress(JSON.parse(event.nativeEvent.data)) : null}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
width: 100%;
|
width: 100%;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
// overflow: hidden;
|
/* overflow: hidden; */
|
||||||
|
|
||||||
}
|
}
|
||||||
#main {
|
#main {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import { WebView, View } from 'react-native';
|
|
||||||
import { Container, Echarts } from './components'
|
import { Container, Echarts } from './components'
|
||||||
|
|
||||||
export default class App extends Component {
|
export default class App extends Component {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue