我已经尝试过构建原生的ui组件,它经常受到欢迎.该组件似乎没有以react-native呈现.
虽然,对于这个问题,我特意尝试在反应原生中呈现Android片段,但没有任何东西出现.示例代码:
public class PreferenceViewManager extends SimpleViewManager{ public static final String REACT_CLASS = "RCTPreferenceView"; private WeakReference activityWeakReference; public PreferenceViewManager(WeakReference 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本身不会被渲染.
我究竟做错了什么?