私はReact Nativeを使用したいと思うように既にAndroidアプリケーションを構築しています。それは大規模なアプリケーションであり、すべてを一度に移行したくありません。たとえば、私のツールバーのコードはちょっと複雑なので、今はそのままにしておきたいと思います。しかし、私は(setContentView上のエラーを取得していますReactRootViewを入れ子にすることができます(アンドロイド)
mReactRootView = (ReactRootView) findViewById(R.id.react_root);
... // Other init
setContentView(mReactRootView);
:
<RelativeLayout
android:id="@+id/relative_layout"
android:background="@color/background_color"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<android.support.v7.widget.Toolbar
android:id="@+id/action_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
<com.facebook.react.ReactRootView
android:id="@+id/react_root"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
とのonCreateで()の代わりに、私はこれをやっている新しいReactRootViewの作成:だから、私のレイアウトは次のようになりますmReactRootView):
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
これは私が巣を他のビュー内ルートビューを反応することはできないと信じて私をリード。現在のツールバーの実装を維持するにはどうすればよいですか?他のページではReact Nativeを使用していますか?私はこれが存在することを知っています:https://facebook.github.io/react-native/docs/native-components-android.htmlネイティブコンポーネントへのブリッジングは私の唯一のオプションですか?
編集は:以下コンスタンチンの提案に続き、ここで私が持っているものです。
ReactFragment.java
public class ReactFragment extends Fragment implements DefaultHardwareBackBtnHandler {
ViewGroup group = (ViewGroup) inflater.inflate(R.layout.react_fragment, container, false);
activity = getActivity();
mReactRootView = new ReactRootView(activity);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(activity.getApplication())
.setBundleAssetName("index.bundle")
.setJSMainModuleName("index")
.addPackage(new MainReactPackage())
.setUseDeveloperSupport(true)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
group.addView(mReactRootView);
mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", null);
mReactInstanceManager.onHostResume(activity, this);
return group;
}
// onPause() onDestroy() etc.
react_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/react_root"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
追加
をmain_content.xmlします...
<fragment
android:name="com.amazon.kindlestore.main.ReactFragment"
android:id="@+id/react_frag"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
...
そして、私の主な活動に私はこのようなフラグメントを追加している:
ReactFragment reactFragment = (ReactFragment) getFragmentManager().findFragmentById(R.id.react_frag);
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.react_frag, reactFragment);
fragmentTransaction.commit();
これが動作しているようだ、私は私の母国ツールバーの下に
私は私のアプリで同じ問題を持っている(トップメニューにアンドロイドを選択することを忘れないでください)。私はアンドロイドネイティブアプリケーションを使用するカスタムタブバーを使用する必要があります。しかし今では私のアプリケーションの一部は反応ネイティブです反応するネイティブブリッジを使用して反応ネイティブでタブバーを表示/非表示する可能性があります –