運行版本:
"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.安卓環(huán)境在react-native-navigation的導航環(huán)境下六水,部分功能在頁面返回后缺失,如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第三方插件做圖標的時候,安卓環(huán)境下會出現(xiàn)圖標無法顯示和會滑動的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即可