Mobile Kotlin Javascript
Evaluate JavaScript code from kotlin common code on android & iOS using new moko-javascript library. You can find this library on https://github.com/icerockdev/moko-javascript.
Features
- Evaluate JavaScript code from Kotlin common code
- Pass objects to JavaScript as global vars
Installation
root build.gradle
allprojects {
repositories {
mavenCentral()
}
}
project build.gradle
dependencies {
commonMainApi("dev.icerock.moko:javascript:0.1.0")
}
Usage
val javaScriptEngine = JavaScriptEngine()
val result: JsType = try {
javaScriptEngine.evaluate(
context = emptyMap(),
script = """ "Hello" + "World" """.trimIndent()
)
} catch (ex: JavaScriptEvaluationException) {
// Handle script evaluation error
JsType.Null
}
if (result is JsType.Str) {
println(result.value)
}
Samples
More examples can be found in the sample directory.