https://github.com/porum/jb
js-bridge jsbridge jsbridge-webview
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/porum/jb
- Owner: porum
- License: apache-2.0
- Created: 2025-08-15T08:07:43.000Z (10 months ago)
- Default Branch: master
- Last Pushed: 2025-08-21T09:15:40.000Z (10 months ago)
- Last Synced: 2025-08-21T11:32:48.782Z (10 months ago)
- Topics: js-bridge, jsbridge, jsbridge-webview
- Language: Kotlin
- Homepage:
- Size: 131 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# JB
Yet another js bridge for Android.
## Usage
1. Javascript side
```javascript
window.JB.sendMessage(
name = 'share',
payload = {
message: 'Hi, I share a JB to you.',
},
callback = function(resp) {
console.log(`share ${resp.data}(${resp.code})`);
}
);
```
2. Android side
```kotlin
@Keep
data class SharePayload(
val message: String
)
@Name(value = "share")
class ShareBridge : JB {
override fun call(context: Context, requestPayload: SharePayload, callback: Callback) {
// Invokes native android sharing
val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, requestPayload.message)
type = "text/plain"
}
val shareIntent = Intent.createChooser(sendIntent, null)
context.startActivity(shareIntent, null)
// Callback to javascript
callback(
ResponsePayload(
code = 200,
data = "Thank you share me a JB, I love it."
)
)
}
}
```
That's it, enjoy JB!