react-native-poc-usabilla

1.3.0 • Public • Published

Android

  1. Enter the android folder in home directory of the RN app
  2. Copy the latest .aar version of the Usabilla SDK in the path app/libs/
  3. Change the Gradle wrapper to be at least 4.1-all in gradle-wrapper.properties
  4. Replace the original Project-level build.gradle file with this
    buildscript {
        ext.kotlin_version = '1.2.10'
        repositories {
            jcenter()
            google()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.0.1'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
    allprojects {
        repositories {
            mavenLocal()
            jcenter()
            maven {
                // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
                url "$rootDir/../node_modules/react-native/android"
            }
            google()
        }
    }
    
  5. Add the following to the App-level build.gradle file
    apply plugin: 'kotlin-android'
    
    ...
    
    implementation fileTree(dir: "libs", include: ["*.aar"])
    implementation "com.android.support:appcompat-v7:26.1.0"
    implementation 'com.mcxiaoke.volley:library:1.0.19'
    implementation "com.facebook.react:react-native:0.52.0"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support.test.espresso:espresso-idling-resource:3.0.1'
    
  6. Create a class called UsabillaBridge.kt which will host all the methods bridging from React Native to Java/Kotlin, such as
    class BridgeModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
    
        override fun getName() = "UsabillaBridge"
    
        @ReactMethod
        fun initialize(appId: String) {
            currentActivity?.let {
                Usabilla.initialize(it.baseContext, appId)
                Toast.makeText(it.baseContext, "SDK initialised with AppId $appId", Toast.LENGTH_SHORT).show()
            }
        }
        
        // Other methods
    }
    
  7. Create a class called BridgePackage.kt to be able to reference the previous class from React Native, such as
    class BridgePackage : ReactPackage {
    
        override fun createNativeModules(reactContext: ReactApplicationContext): MutableList<NativeModule> =
                mutableListOf(UsabillaBridge(reactContext))
    
        override fun createViewManagers(reactContext: ReactApplicationContext?): MutableList<ViewManager<View, ReactShadowNode<*>>> =
                Collections.emptyList()
    }
    
  8. In MainApplication.kt (or its java version) add the BridgePackage to the method getPackages()
  9. Run the app either opening the project in the android folder with AndroidStudio, or via command line typing react-native run-android from within the RN folder
  10. Add the following to App.js
    import { NativeModules } from 'react-native';
    
  11. You should be able to call a method in the UsabillaBridge.kt from the RN app with
    NativeModules.UsabillaBridge.initialize('5a37c12145380769f373d71b');
    

Readme

Keywords

none

Package Sidebar

Install

npm i react-native-poc-usabilla

Weekly Downloads

4

Version

1.3.0

License

none

Last publish

Collaborators

  • kioli