运行版本:
"react-native": "0.54.1",
"react-native-navigation": "1.1.407",
"jcore-react-native": "^1.2.5",
"jpush-react-native": "^2.2.0",
"react-native-swiper": "1.5.13",
"react-native-tab-navigator": "0.3.4"
1.安卓环境在react-native-navigation的导航环境下,部分功能在页面返回后缺失,如react-native-swiper轮播失效,react-native-scrollable-tab-view的UI效果失灵
解决方法如下步骤:
第一步:~项目路径/node_modules/react-native-navigation/android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java
最下方加上这段代码
//先import
import com.facebook.react.shell.MainReactPackage;
//最下方加上
@Nullable
public abstract MainReactPackage readyMainReactPackage();
第二步:~项目目录/node_modules/react-native-navigation/android/app/src/main/java/com/reactnativenavigation/react/NavigationReactGateway.java
将原来的getPackages的方法替换为:
@Override
protected List<ReactPackage> getPackages() {
List<ReactPackage> result = new ArrayList<>();
List<ReactPackage> additionalReactPackages = NavigationApplication.instance.createAdditionalReactPackages();
if (additionalReactPackages != null)
result.addAll(additionalReactPackages);
if (!containsInstanceOfClass(result, MainReactPackage.class)) {
MainReactPackage mainReactPackage = NavigationApplication.instance.readyMainReactPackage();
if (mainReactPackage == null) {
result.add(new MainReactPackage());
} else {
result.add(mainReactPackage);
}
}
if (!containsInstanceOfClass(result, NavigationReactPackage.class)) {
result.add(new NavigationReactPackage());
}
return result;
}
2.安卓使用JPush的RN版本的时候,应用关闭的情况下点击推送,推送跳转无法跳转,解决方法如下
~项目目录/node_modules/jpush-react-native/android/src/main/java/cn/jpush/reactnativejpush/JPushModule.java
加上这段代码
@ReactMethod
public void appExit() {
mRAC = null;
}
然后在js代码里面的一般加载JPush方法的Main类里面加上
const JPushModuleOrigin = NativeModules.JPushModule
componentWillUnmount() {
if (Platform.OS === 'android') {
JPushModuleOrigin.appExit();
}
}
3.使用native-echarts第三方插件做图标的时候,安卓环境下会出现图标无法显示和会滑动的bug,解决方法如下
~项目目录/node_modules/native-echarts/scr/components/Echarts/index.js下的代码替换为如下代码
import React, { Component } from 'react';
import { WebView, View, StyleSheet , Platform } from 'react-native';
import renderChart from './renderChart';
import echarts from './echarts.min';
export default class App extends Component {
componentWillReceiveProps(nextProps) {
if(nextProps.option !== this.props.option) {
this.refs.chart.reload();
}
}
render() {
let scalesPageToFit = Platform.OS === 'ios' ? false : true
let source = Platform.OS === 'ios' ? require('./tpl.html') : {'uri':'file:///android_asset/tpl.html'}
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={false}
source = {source}
onMessage={event => this.props.onPress ? this.props.onPress(JSON.parse(event.nativeEvent.data)) : null}
/>
</View>
);
}
}
然后将~项目目录/node_modules/native-echarts/scr/components/Echarts/tpl.html文件替换到
~项目目录/android/app/src/main/assets/tpl.html即可