
Receiving a success callback and failure callback as parameter.

How can we call Kotlin methods from Javascript? It’s pretty simple – we only have to add the required method to the BridgeModule class annotated with important thing to note is that this method ALWAYS must return void or unit, the operations are asynchronous, so to inform Javascript code what happened there are two options: As of June 2020, when converting BridgePackage to Kotlin you will need to remove the override word to the method createJSModules () because the method was deprecated and if you keep the override it won’t compile. Implementation ":kotlin-stdlib-jdk7:$kotlin_version"Īfter doing this we can start using Kotlin and convert our Java files to Kotlin. Implementation fileTree(dir: "libs", include: ) In order to be able to compile Kotlin code, add this to the adle file, and add Koin and coroutines dependency:Ĭlasspath ':gradle:4.0.0'Ĭlasspath ":kotlin-gradle-plugin:$kotlin_version"

Two files are important: BridgeModule: This class will contain all the methods that can be called from javascript codeīridgePackage: Here we must inform React Native that it must add BridgeModule to the list of native modules This creates the basic files of the new native module library. $ create-react-native-module -platforms android -package-identifier Bridge $ yarn global add create-react-native-module

This article focuses on Android.įirst, we install a tool to get the basic scaffolding, run this command in the folder that you want to contain the new library: The printer’s manufacturer has support for Android, iOS and Xamarin, but nothing on React Native, so the only way we can use the printer’s SDK is by making a native module both for iOS and Android devices. As a Mobile Software Engineer, I had to implement the connection between a React Native application and a printer by TCP/IP protocol.
