react-native-echarts 解決數(shù)據(jù)刷新閃爍,不能動態(tài)連續(xù)繪制問題

最終能實(shí)現(xiàn)效果:動態(tài)繪制K線圖,安卓,iOS正常顯示

dynamic.gif

替換node_modules/native-echarts/src/components/Echarts/中的index.jsrenderChart.js

index.js替換代碼


import React, { Component } from 'react';
import { WebView, View, StyleSheet,Platform } from 'react-native';
import renderChart from './renderChart';
import renderChartNoFirst from './renderChart'
import echarts from './echarts.min';



export default class App extends Component {
// 預(yù)防過渡渲染

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
}

componentWillReceiveProps(nextProps) {
if(nextProps.option !== this.props.option) {
  
// 解決數(shù)據(jù)改變時頁面閃爍的問題
this.refs.chart.injectJavaScript(renderChart(nextProps,false))
}
}

  render() {
    if (Platform.OS == 'android'){
      return (
      <View style={{flex: 1, height: this.props.height || 400,}}>
        <WebView
          ref="chart"
          scrollEnabled = {false}
          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={require('./tpl.html')}
        />
      </View>
    );
    }
    
  }
}

renderChart.js替換代碼

import echarts from './echarts.min';
import toString from '../../util/toString';
var myChart = null;
export default function renderChart(props,isFirst) {
  const height = props.height || 400;
    if (isFirst){
      return `
    document.getElementById('main').style.height = "${height}px";
    myChart = echarts.init(document.getElementById('main'));
    myChart.setOption(${toString(props.option)});
  `
    }else{
      return `
    document.getElementById('main').style.height = "${height}px";
    
    myChart.setOption(${toString(props.option)});
  `
    }
}

安卓打包echart不顯示修復(fù)

1.將上述代碼替換,注意備注部分

//解決安卓打包不顯示問題        
source={{uri: 'file:///android_asset/tpl.html'}} 

2.將node_modules/native-echarts/src/components/Echarts/tpl.html拷貝一份到/android/app/src/main/assets/目錄下

3.運(yùn)行js打包命令
4.刪除/android/app/src/main/res/drawable-mdpi/node_modules_nativeecharts_src_components_echarts_tpl.html
5.安卓打包APK

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,001評論 25 709
  • 1 修改 node_modules/native-echarts/src/components/Echarts/i...
  • 也說堅(jiān)持 這兩周工作開始忙起來了,之前堅(jiān)持的事情也松懈了不少。作文拖拖拉拉,經(jīng)常臨近周末才能補(bǔ)上,連續(xù)好久徘徊再被...
    白大炮閱讀 256評論 2 0
  • 那是一封很怪的情書。 很多時候我在想,如果沒有這封情書,后來的故事會不會就不會發(fā)生,那樣的話,我也不會遇見他。 依...
    曲小呆_不二閱讀 509評論 0 0
  • 今天,忽然想起來,很多的往事,于是,就有了一這篇感謝的話。 首先要感謝媽媽 ,生了我,育了我,在爸爸去世后,她也...
    此狐修仙中閱讀 392評論 0 0

友情鏈接更多精彩內(nèi)容