whalecloud-dxp-nudges-react-native
v1.2.0
Published
whalecloud-nudges
Downloads
650
Maintainers
Readme
whalecloud-dxp-nudges-react-native
whalecloud-Nudges
Installation
npm install whalecloud-dxp-nudges-react-native
目前还没发布npm所以
yarn add file:../whalecloud-dxp-ads-react-native
Usage
1 Android项目里面需要再 app 文件夹下面的build.gradle 加入implementation project(':whalecloud-dxp-nudges-react-native')
2 先在Android 工程的 Application 里调用 init如下 并且配置url以及config如下
//Nudges
WhalecloudDxpAdsReactNativeModule.initAds(this,"http://172.16.22.5:9110");
// DXP NUDGES 后端服务地址
String DXP_NUDGES_BASE_URL = "http://172.16.22.5:9110/portal-web/dmc/mccm-outer/";
DxpNudgesUtil.setNudgesBaseUrl(DXP_NUDGES_BASE_URL);
//DXP NUDGES CEG 后web Socket地址
String DXP_NUDGES_CEG_BASE_URL = "http://10.10.177.38/ceg/ceg/";
String DXP_NUDGES_CEG_WS_URL = "ws://10.10.177.38/ceg/ceg/nudges/socket";
DxpNudgesUtil.setCegNudgesBaseUrl(DXP_NUDGES_CEG_BASE_URL);
DxpNudgesUtil.setCegNudgesWsBaseUrl(DXP_NUDGES_CEG_WS_URL);
//Nudges
WhalecloudDxpNudgesReactNativeModule.init(this);// 默认设置
WhalecloudDxpNudgesReactNativeModule.initNudgesConfig("ditoapp","MzUzOWQ2YzY4NjJmYWMzOWQ5ZGIxMjFm");
3 在MainActivity 上 实现 IRouteName
重写
@Override
public String getRouterName() {
return WhalecloudDxpNudgesReactNativeModule.currentPage;
}
import { DXPNudges } from './whalecloud-dxp-nudges-react-native';
DXPNudges.setOnNudgesShowListener();
DXPNudges.setOnNudgesButtonClickListener();
调用好后在NavigationContainer 里面加入 onStateChange 监听页面变化调用DXPNudges.startNudges(url)
例子:
<NavigationContainer
onStateChange={state => {
const currentRoute = state.routes[state.index];
console.log('Current route:', currentRoute.name);
DXPNudges.startNudges(currentRoute.name)
}}>