*react-native 原生将Activity转换成rn的view
在有些开发场景中有将activity转换成view的场景,我这边是用阿里百川碰到的,因为有些操作必须在activity操作所以需要在次转换成view
1、定义全局LocalActivityManager变量
LocalActivityManager mLocalActivityManager;
oncreate()方法实例化mLocalActivityManager = new LocalActivityManager((Activity) context, true);
2、在oncreate,onresume,onpause方法中分别加入如下代码:
oncreate()--------------mLocalActivityManager.dispatchCreate(arg0);参数arg0为oncreate方法的形参
onpause()--------------mLocalActivityManager.dispatchPause(isFinishing());
onresume()--------------mLocalActivityManager.dispatchResume();
版权声明:本文为CSDN博主「省身」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/xingshen58/article/details/13503701
public View activityToView(ThemedReactContext parent, Intent intent) {
final Window w = MainActivity.mLocalActivityManager.startActivity("id", intent);
final View wd = w != null ? w.getDecorView() : null;
if (wd != null) {
wd.setVisibility(View.VISIBLE);
wd.setFocusableInTouchMode(true);
((ViewGroup) wd)
.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
}
return wd;
}