Skip to content

fixed errors in RN 0.64 #168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "native-echarts",
"version": "0.5.0",
"version": "0.7.0",
"description": "echarts for react-native",
"main": "src/index.js",
"directories": {
Expand Down
45 changes: 27 additions & 18 deletions src/components/Echarts/index.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,52 @@
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 echarts from './echarts.min';
import WebView from "react-native-webview";
import getTpl from "./tpl" ;

export default class App extends Component {

constructor(props) {
super(props);
this.setNewOption = this.setNewOption.bind(this);
}


componentWillReceiveProps(nextProps) {
if(nextProps.option !== this.props.option) {
this.refs.chart.reload();
// this.refs.chart.reload();
if(Platform.OS === 'android'){
this.refs.chart.reload();
}else {
this.setNewOption(nextProps.option) ;
}
}
}
shouldComponentUpdate() {
return false ;
}

setNewOption(option) {
this.refs.chart.postMessage(JSON.stringify(option));
}

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,
backgroundColor: this.props.backgroundColor || 'transparent'
}}
scalesPageToFit={Platform.OS !== 'ios'}
originWhitelist={['*']}
source={require('./tpl.html')}
onMessage={event => this.props.onPress ? this.props.onPress(JSON.parse(event.nativeEvent.data)) : null}
/>
</View>
<View style={{flex: 1, height: this.props.height || 400,}}>
<WebView
ref="chart"
scrollEnabled = {false}
injectedJavaScript = {renderChart(this.props)}
style={{
height: this.props.height || 400,
backgroundColor: this.props.backgroundColor || 'transparent'
}}
originWhitelist={['*']}
source={Platform.OS === "ios"?{ html:getTpl() }:{uri:'file:///android_asset/tpl.html'}}
onMessage={event => this.props.onPress ? this.props.onPress(JSON.parse(event.nativeEvent.data)) : null}
/>
</View>
);
}
}
63 changes: 0 additions & 63 deletions src/components/Echarts/tpl.html

This file was deleted.

28 changes: 28 additions & 0 deletions src/components/Echarts/tpl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export default ()=>`<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
<title>echarts</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<style type="text/css">
html,body {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
// overflow: hidden;

}
#main {
height: 100%;
}
</style>
<script src="https://cdn.bootcss.com/echarts/4.2.1/echarts.min.js"></script>
</head>

<body>
<div id="main" ></div>
<body>
<html>
` ;