{"id":15690600,"url":"https://github.com/linusu/flutter_jsbridge","last_synced_at":"2025-05-07T23:45:00.230Z","repository":{"id":56829586,"uuid":"174125998","full_name":"LinusU/flutter_jsbridge","owner":"LinusU","description":"Bridge your JavaScript library for usage in Flutter 🚀","archived":false,"fork":false,"pushed_at":"2019-04-11T16:19:22.000Z","size":90,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T23:44:53.614Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LinusU.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-06T10:44:19.000Z","updated_at":"2024-12-27T02:16:38.000Z","dependencies_parsed_at":"2022-08-29T00:20:24.762Z","dependency_job_id":null,"html_url":"https://github.com/LinusU/flutter_jsbridge","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusU%2Fflutter_jsbridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusU%2Fflutter_jsbridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusU%2Fflutter_jsbridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LinusU%2Fflutter_jsbridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LinusU","download_url":"https://codeload.github.com/LinusU/flutter_jsbridge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252973616,"owners_count":21834105,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T18:12:36.497Z","updated_at":"2025-05-07T23:45:00.214Z","avatar_url":"https://github.com/LinusU.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSBridge for Flutter\n\nBridge your JavaScript library for usage in Flutter 🚀\n\n## Usage\n\n```dart\nimport 'package:flutter_jsbridge/jsbridge.dart';\n\nfinal _libraryCode = \"\"\"\n  window.Foobar = {\n    add (a, b) {\n      return a + b\n    },\n    greet (name) {\n      return `Hello, \\${name}!`\n    },\n    async fetch (url) {\n      const response = await fetch(url)\n      const body = await response.text()\n\n      return { status: response.status, body }\n    }\n  }\n\"\"\";\n\nclass FetchResponse {\n  final int status;\n  final String body;\n\n  FetchResponse(dynamic data): status = data['status'], body = data['body'];\n}\n\nclass Foobar {\n  static final _bridge = JSBridge(_libraryCode);\n\n  static Future\u003cint\u003e add(int lhs, int rhs) async {\n    return await Foobar._bridge.call(\"Foobar.add\", [lhs, rhs]);\n  }\n\n  static Future\u003cString\u003e greet(String name) async {\n    return await Foobar._bridge.call(\"Foobar.greet\", [name]);\n  }\n\n  static Future\u003cFetchResponse\u003e fetch(String url) async {\n    return FetchResponse(await Foobar._bridge.call(\"Foobar.fetch\", [url]));\n  }\n}\n```\n\n## iOS\n\nTo be able to use JSBridge on iOS, you need to give JSBridge a hook to your view hierarchy. Otherwise the `WKWebView` will get suspended by the OS, and your Promises will never settle.\n\nThis is accomplished by using the `setGlobalUIHook` function before instantiating any `JSBridge` instances.\n\n**Flutter:**\n\nIf you have a non-modified Flutter application, this should be added to `ios/Runner/AppDelegate.swift`, in the `application(_:didFinishLaunchingWithOptions:)` function.\n\n```diff\n--- a/ios/Runner/AppDelegate.swift\n+++ b/ios/Runner/AppDelegate.swift\n@@ -1,5 +1,6 @@\n import UIKit\n import Flutter\n+import flutter_jsbridge\n\n @UIApplicationMain\n @objc class AppDelegate: FlutterAppDelegate {\n   override func application(\n     _ application: UIApplication,\n     didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?\n   ) -\u003e Bool {\n+    SwiftFlutterJsbridgePlugin.setGlobalUIHook(window: UIApplication.shared.windows.first!)\n     GeneratedPluginRegistrant.register(with: self)\n     return super.application(application, didFinishLaunchingWithOptions: launchOptions)\n   }\n```\n\n**App:**\n\n```swift\n// Can be called from anywhere, e.g. your AppDelegate\nSwiftFlutterJsbridgePlugin.setGlobalUIHook(window: UIApplication.shared.windows.first!)\n```\n\n**App Extension:**\n\n```swift\n// From within your root view controller\nSwiftFlutterJsbridgePlugin.setGlobalUIHook(viewController: self)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinusu%2Fflutter_jsbridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinusu%2Fflutter_jsbridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinusu%2Fflutter_jsbridge/lists"}