native-echarts集成与打包遇到的问题以及 react-native-orientation横竖屏问题


native-echarts(Echarts图表集成)

1.集成方法

npm install native-echarts –save

2.注意

(1)在集成图表功能后,可能会遇到安卓或者iOS打包后图表显示空白的情况,具体解决方法是修改<mark>node_modules/native-echarts/src/components/Echarts/index.js</mark>中的WebView组件:

<WebView originWhitelist={['']} ref="chart" 
   scrollEnabled = {false}    
   injectedJavaScript = {renderChart(this.props)}    
   style={{height: this.props.height || 400,        
   backgroundColor: this.props.backgroundColor || 
   'transparent'}} scalesPageToFit={Platform.OS === 'android' ? true : false}
   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}/>

(2)当图表数据没有更改,但是进行setState操作时,图表会重新绘制,解决方法如下:

componentWillReceiveProps(nextProps) {
        if(nextProps.option !== this.props.option) { 
            this.refs.chart.injectJavaScript(renderChart(nextProps))        
        }
    }    


react-native-orientation(横竖屏切换)

1.集成方法

npm install react-native-orientation –save
react-native link react-native-orientation

2.注意

iOS需要在工程中开启权限

avatar

安卓端使用并未有任何问题,但是在iOS中,会出现用户将手机横竖切换时,界面会进行横竖屏切换的问题,需要写原生方法来配合使用,原生方法如下:
在AppDelegate.m中加入下列方法,监控手机横竖屏状态(这里监控的是横竖屏切换之前)

 - (UIInterfaceOrientationMask)application:(UIApplication *)application 
    supportedInterfaceOrientationsForWindow:(UIWindow *)window{
        if (_allowRotate == 1) {
            return UIInterfaceOrientationMaskLandscape;
        }
        else {
                return (UIInterfaceOrientationMaskPortrait);
        }
    }
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return YES;
 }
 - (BOOL)shouldAutorotate{
    return YES;
 }

在AppDelegate.h中添加属性allowRotate

@property (nonatomic,assign)NSInteger allowRotate;

添加RN与原生的交互类PushCustom,在RCT_EXPORT_METHOD方法中更改allowRotate的属性,从而锁定手机横竖屏,这样就不会出现用户将手机横竖切换时的问题了。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 持续更新中...... 一套企业级的 UI 设计语言和 React 实现。 https://mobile.ant....
    日不落000阅读 11,160评论 0 35
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,733评论 4 61
  • 我是个爱好很多的人,但是从小唯一不变的是画画的爱好,可是学业,工作,结婚,生子,画画这件事就一直耽误了。 2019...
    sunny赛赛阅读 3,717评论 0 1
  • 城里的人想出去,城外的人想进来,钱先生如是说。 在清迈听到这样的故事,说是邓丽君的那首《小城故事》唱的就是清迈这座...
    爱嗑瓜子的兔子阅读 3,434评论 0 1
  • 想 你在眼前 望 你的身后 读 你在唇边 念 你的耳畔 让 我如此恋 把 你留心田 驻 足难往返 心...
    顾纯熙阅读 9,413评论 4 2

友情链接更多精彩内容