Skip to content

aitherios/react-native-android-fragment

 
 

Repository files navigation

react-native-android-fragment

A utility library for facilitating React Native development with Android Fragments.

Download

React Native Android Fragment isn't available via npm. This is intended to be used solely in an Android Project and therefore we are shipping this over jcenter (maven/gradle). You can download via Gradle:

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

dependencies {
  // Version will correspond to its dependnecy on React Native
  compile 'com.github.hudl:react-native-android-fragment:v0.43.2'
}

Or Maven:

<dependency>
  <groupId>com.hudl.oss</groupId>
  <artifactId>react-native-android-fragment</artifactId>
  <version>0.43.2</version>
</dependency>

Usage

The 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);
}

Running Sample App

NOTE: Make sure your environment is set up for React Native and Android development.

  • Clone the repo
  • Open a terminal and navigate to the root directory of your checkout
  • cd sample-app
  • yarn
  • Open the project in Android Studio and let everything build
  • Back in your terminal run react-native start
  • In Android Studio run the app on an emulator or your device

About

A utility library for facilitating React Native development with Android Fragments.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 95.4%
  • JavaScript 4.6%