{"id":18270436,"url":"https://github.com/BeamApp/Transit","last_synced_at":"2025-04-05T01:30:40.643Z","repository":{"id":6825363,"uuid":"8073547","full_name":"BeamApp/Transit","owner":"BeamApp","description":"Library to Bridge between JavaScript and iOS, OSX, Android","archived":false,"fork":false,"pushed_at":"2015-03-17T11:40:01.000Z","size":10776,"stargazers_count":150,"open_issues_count":13,"forks_count":13,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-04T06:35:39.433Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BeamApp.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2013-02-07T13:46:37.000Z","updated_at":"2024-06-12T08:48:06.000Z","dependencies_parsed_at":"2022-08-21T05:20:50.567Z","dependency_job_id":null,"html_url":"https://github.com/BeamApp/Transit","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BeamApp%2FTransit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BeamApp%2FTransit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BeamApp%2FTransit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BeamApp%2FTransit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BeamApp","download_url":"https://codeload.github.com/BeamApp/Transit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276022,"owners_count":20912285,"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-11-05T11:38:37.986Z","updated_at":"2025-04-05T01:30:35.630Z","avatar_url":"https://github.com/BeamApp.png","language":"Objective-C","readme":"\n\n# Transit [![Build Status](https://travis-ci.org/BeamApp/Transit.png)](https://travis-ci.org/BeamApp/Transit) [![Cocoa Pod](http://cocoapod-badges.herokuapp.com/p/Transit/badge.svg)](http://cocoadocs.org/docsets/Transit/) [![Cocoa Pod](http://cocoapod-badges.herokuapp.com/v/Transit/badge.svg)](http://cocoadocs.org/docsets/Transit/)\n\nTransit bridges between JavaScript and iOS, OSX, Android. You can easily embed a WebView or scripted logic via JS into your application and pass in native code as functions and especially event handlers. Whenever your native code got called you can use all arguments as well as the `this` argument even if they are JavaScript, functions again! (some change before MTC presentation)\n\nIt does not rely on special JavaScript runtimes such as JavaScript Core or Rhino but can be used with any visual or non-visual component that understands JavaScript. That way, you can easily modify existing web pages to integrate with your native application (e.g. make `history.go(-1)` close the WebView or bind a button's `onClick` event to your native code). On the other hand, you can expose native functionality as accessible JavaScript functions (e.g. `[transit bind:\u003cnative code\u003e toVariable:'navigator.vibrate']`).\n\n## Example for Objective-C\n\nCreate a transit context from any (non-)visible webview\n\n```objc\nTransitUIWebViewContext *context = [TransitUIWebViewContext contextWithUIWebView:someViewView];\n```\n\nEvaluate JavaScript with convenient placeholders `@` and implicit type conversion. So, calling\n\n```objc\nNSLog(@\"%@\", [context eval:@\" {result: @ + Math.max(23, @) } \" val: @\"foo\" val: @42.5]);\n```\nprints `NSDictionary: { result: \"foo42.5\" }` to the console.\n\n\nYou can store JavaScript functions in native variables and call them later or pass them back to JavaScript at any time. This code\n\n```objc\nTransitFunction *mathMax = [context eval:@\"Math.max\"];\nNSLog(@\"%@\", [mathMax callWithArg:@3.5 arg:@6] );\nNSLog(@\"%@\", [context eval:@\" @(3.5, @)\" val: mathMax val:@6] );\n```\nprints `6` in both cases.\n\nThe same works the other way around, were you can pass blocks to JavaScript, e.g. to register or override global functions\n\n```objc\ncontext[@\"log\"] = ^(id object){\n  NSLog(@\"%@\", object);\n};\n[context eval:@\"log('Hello, World!')\"];\n```\n\nBut the real strength of transit comes when you combine native code with JavaScript. Blocks or delegates can be called from JavaScript and can even receive JavaScript functions as arguments. This code snippet\n\n```objc\nTransitFunction *applyFunc = [context functionWithBlock:^(TransitFunction* func, float a, int b){\n  NSLog(@\"arguments: func: %@, a: %f, b: %d\", func, a, b);\n  return [func callWithArg:@(a) arg:@(b)];\n}];\n\nNSNumber* result = [context eval:@\"@(Math.max, 3.5, @)\" val:applyFunc val:@6];\nNSLog(@\"result: %f\", result.floatValue);\n```\n\noutputs\n\n```\narguments: func: \u003cTransitJSFunction: 0x11b34fc0\u003e, a: 3.500000, b: 6\nresult: 6.0000\n```\n\nto the console.\n\nThere's a lot more. e.g. `TransitCurrentCall` gives you access to the `this` variable, all `arguments` and let's you even print the unified call stack from JavaScript and native functions:\n\n```\n002 TransitNativeFunctionCallScope(this=\u003cTransitUIWebViewContext: 0x75250d0\u003e(\u003cTransitJSFunction:0x11b34fc0\u003e, 3.5, {field = 6;})\n001 TransitEvalCallScope(this=\u003cTransitUIWebViewContext: 0x75250d0\u003e) @(Math.max, 3.5, {field:@}) -- values:(\u003cTransitNativeFunction: 0x752ff00\u003e, 6)\n```\n\nRead the [API documentation](http://cocoadocs.org/docsets/Transit/) for further details.\n\n\n## Additional Information\n\nYou can find additional information in the Wiki, e.g.\n\n * [Internal Architecture](https://github.com/BeamApp/Transit/wiki/Internals)\n * [Android Internals](https://github.com/BeamApp/Transit/wiki/Android:-Communication)\n","funding_links":[],"categories":["etc"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBeamApp%2FTransit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FBeamApp%2FTransit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FBeamApp%2FTransit/lists"}