我们如何让一个Android片段显示在react-native中?

前端之家收集整理的这篇文章主要介绍了我们如何让一个Android片段显示在react-native中?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经尝试过构建原生的ui组件,它经常受到欢迎.该组件似乎不以react-native呈现.

虽然,对于这个问题,我特意尝试在反应原生中呈现Android片段,但没有任何东西出现.示例代码

public class PreferenceViewManager extends SimpleViewManager<FrameLayout> {
    public static final String REACT_CLASS = "RCTPreferenceView";

    private WeakReference<Activity> activityWeakReference;

    public PreferenceViewManager(WeakReference<Activity> activityWeakReference) {
        this.activityWeakReference = activityWeakReference;
    }

    @Override
    public String getName() {
        return REACT_CLASS;
    }

    @Override
    public FrameLayout createViewInstance(ThemedReactContext context) {
        Log.d(REACT_CLASS,"PreferenceView createViewInstance");
        final FrameLayout view = new FrameLayout(context);
        view.setId(View.generateViewId());
        // Testing if the view does get rendered,it should show white even if fragment is not rendered!
        view.setBackgroundColor(Color.WHITE);
        // not sure where to call fragment beginTransaction properly,the code below is just for testing
        view.postDelayed(new Runnable() {
            @Override
            public void run() {
                onAfterUpdateTransaction(view);
            }
        },2000);
        return view;
    }

    @Override
    public void onAfterUpdateTransaction(FrameLayout view) {
        super.onAfterUpdateTransaction(view);

        activityWeakReference.get().getFragmentManager().beginTransaction().replace(view.getId(),new PreferenceView()).commit();
        Log.d(REACT_CLASS,"PreferenceView Commit"); // for debug
    }
}

使用上面的视图管理器,视图所在的位置甚至不是白色,表示FrameLayout本身不会被渲染.

我究竟做错了什么?

解决方法

原文链接:https://www.f2er.com/android/318184.html

猜你在找的Android相关文章