Documentation
¶
Overview ¶
Package plugin calls native code: a method of a plugin registered in the iOS or Android host, written in Swift or Kotlin. Arguments and results travel as JSON, so a plugin needs no generated code on either side.
type token struct{ Value string `json:"value"` }
t, err := plugin.Call[token](ctx, "secureStorage", "get", map[string]string{"key": "token"})
Call blocks until the native side answers, so call it where blocking is fine: in ui.UseQuery, ui.UseAction, an effect or your own goroutine, not in Render. The host runs every plugin method on its main thread.
Plugins are registered in the host:
Plugins.register("battery") { call in call.resolve(UIDevice.current.batteryLevel) } // Swift
Plugins.register("battery") { call -> call.resolve(level) } // Kotlin
Index ¶
- Constants
- Variables
- func Call[Resp any](ctx context.Context, name, method string, args any) (Resp, error)
- func CallJSON(ctx context.Context, name, method string, args any) (json.RawMessage, error)
- func Deliver(r *render.PluginResult)
- func IsCode(err error, code string) bool
- func RunBackground(name string)
- type Error
Constants ¶
const ( Cancelled = "cancelled" Denied = "denied" NotFound = "not_found" Failed = "failed" )
Codes of Error.
Variables ¶
var OnBackground func(name string)
OnBackground is called with the name of each background task the host starts; plugins/backgroundtasks sets it.
Functions ¶
func Call ¶
Call runs method on the named plugin with args (any JSON-encodable value, or nil) and decodes the answer into Resp. Use struct{} or any for a method with no useful answer.
func Deliver ¶
func Deliver(r *render.PluginResult)
Deliver hands a plugin's outcome to the waiting Call. The UI runtime calls it for every PluginResult the host sends.
func RunBackground ¶ added in v0.0.13
func RunBackground(name string)
RunBackground starts a background task. The UI runtime calls it.