File tree Expand file tree Collapse file tree
src/main/kotlin/io/github/revenge
app/src/main/kotlin/io/github/revenge/xposed/modules/bridge Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,4 +20,8 @@ android {
2020repositories {
2121 google()
2222 mavenCentral()
23+ }
24+
25+ dependencies {
26+ compileOnly(" org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2" )
2327}
Original file line number Diff line number Diff line change 1+ package io.github.revenge.bridge
2+
3+ import InternalApi
4+ import io.github.revenge.bridge.impl.BridgeHost
5+ import io.github.revenge.plugins.MethodArgs
6+
7+ @Suppress(" UNUSED" )
8+ @OptIn(InternalApi ::class )
9+ /* *
10+ * Bridge for plugins to communicate with the JavaScript side of the application.
11+ *
12+ * In order for a method to be exposed, you must register the method using the `modules` API.
13+ * Return values must be serializable by React Native, otherwise may result in unexpected behavior.
14+ *
15+ * ```js
16+ * import { registerJSMethod } from '@revenge-mod/modules/native'
17+ *
18+ * registerJSMethod('meaningOfLife', (arg1, arg2) => {
19+ * console.log(arg1 + arg2)
20+ * return 42
21+ * })
22+ * ```
23+ */
24+ object JavaScriptBridge {
25+ fun callJSMethod (methodName : String , args : MethodArgs ) =
26+ BridgeHost .callJSMethod!! .invoke(methodName, args)
27+ }
Original file line number Diff line number Diff line change 1+ package io.github.revenge.bridge.impl
2+
3+ import InternalApi
4+ import io.github.revenge.plugins.MethodArgs
5+ import kotlinx.coroutines.CompletableDeferred
6+
7+ @Suppress(" UNUSED" )
8+ @InternalApi
9+ /* *
10+ * Host for the bridge system to communicate with the application. For example, a Xposed module.
11+ */
12+ object BridgeHost {
13+ /* *
14+ * Callback for when a plugin calls a JS method.
15+ */
16+ var callJSMethod: ((methodName: String , args: MethodArgs ) -> CompletableDeferred <Any ?>)? = null
17+ }
Original file line number Diff line number Diff line change 11package io.github.revenge.plugins
22
33/* *
4- * See for possible return types:
5- * https://github.com/facebook/react-native/blob/c23e84ae9/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Arguments.kt#L19
4+ * You may return a [Unit] and it will be converted to `null`.
65 *
7- * You may return a [Unit] and the resulting value will be `null` .
6+ * See [NativeObject] for more information .
87 */
9- typealias MethodCallback = (args: MethodArgs ) -> Any?
8+ typealias MethodCallback = (args: MethodArgs ) -> NativeObject
109
11- typealias MethodArgs = ArrayList <Any ?>
10+ typealias MethodArgs = ArrayList <NativeObject >
11+
12+ /* *
13+ * Represents a React Native JNI serializable object. These objects can be passed to JavaScript as values.
14+ *
15+ * See: https://github.com/facebook/react-native/blob/7dcedf1/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridge/Arguments.kt#L19
16+ */
17+ typealias NativeObject = Any?
You can’t perform that action at this time.
0 commit comments