Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.hudl:react-native-android-fragment:v0.46.2.2'
}
dependencies {
implementation("com.github.hudl:react-native-android-fragment:v0.46.2.2")
}
<dependency>
<groupId>com.github.hudl</groupId>
<artifactId>react-native-android-fragment</artifactId>
<version>v0.46.2.2</version>
</dependency>
libraryDependencies += "com.github.hudl" % "react-native-android-fragment" % "v0.46.2.2"
:dependencies [[com.github.hudl/react-native-android-fragment "v0.46.2.2"]]
This library has been deprecated and is no longer in use at Hudl. If you've been using this library, please consider adopting ReactFragment in the main react-native repo.
A utility library for facilitating React Native development with Android Fragments.
$ npm install react-native-android-fragment --save
or
$ yarn add react-native-android-fragment
$ react-native link react-native-android-fragment
Append the following lines to android/settings.gradle
:
include ':react-native-android-fragment'
project(':react-native-android-fragment').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-fragment/android')
Insert the following lines inside the dependencies block in android/app/build.gradle
:
compile project(':react-native-android-fragment')
android/app/src/main/java/[...]/MainActivity.java
import com.hudl.oss.react.fragment.ReactFragment;
to the imports at the top of the fileThe primary component in this library is ReactFragment You can use this class directly if you wish, or you can extend from it to simplify your code.
A Builder pattern is provided out of the box for easy usage:
Fragment messagingFragment = new ReactFragment.Builder()
.setComponentName("HelloWorld")
.setLaunchOptions(launchOptions) // A Bundle of launch options
.build();
In your Activity make sure to override onKeyUp()
in order to access the In-App Developer menu:
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
boolean handled = false;
Fragment activeFragment = getSupportFragmentManager().findFragmentById(R.id.container_main);
if (activeFragment instanceof ReactFragment) {
handled = ((ReactFragment) activeFragment).onKeyUp(keyCode, event);
}
return handled || super.onKeyUp(keyCode, event);
}
NOTE: Make sure your environment is set up for React Native and Android development.
yarn link
cd example
yarn link react-native-android-fragment
react-native link react-native-android-fragment
react-native run-android