Arouter跨module调用组件
2021-07-20 本文已影响0人
咚咚_Coding
场景
A module使用B module下的一个弹框组件,A和B均依赖arouter
A关注自己想要的,定义一个接口,让B去具体实现
arouter组件下定义服务接口
//名称:订单弹窗服务
public interface OrderPopService extends IProvider {
/**
* 数据组装: list key jsonList, value json数组
* 埋点上报
* key: click_name, value: 名称
* key: exposure_name, value: 名称
*/
void showDialog(Context mContext, HashMap<String, String> json);
}
在B module下实现具体弹框逻辑
/**
* 名称: 服务具体功能实现类
*/
@Route(path = “pop_service”, name = "xxx")
public class CouponPopServiceImpl implements OrderPopService {
@Override
public void showDialog(Context mContext, HashMap<String, String> json) {
//TODO 在这里写你的弹框逻辑......
}
}
@Override
public void init(Context context) {
}
}
A调用B的服务
val popService = ARouter.getInstance().navigation(OrderPopService::class.java)
val mapList=HashMap<String,String>()
mapList["jsonList"]= JSON.toJSONString("你的data”)
popService.showDialog(context,mapList)