Documentation

$open and $share

Send the reader to a web page, or send something out through the system share sheet.

<Button onClick={() => $open("https://example.com/docs")}>Docs</Button>
<Button onClick={() => $share({ title: post.title, url: post.link })}>Share</Button>

Why these exist

Both need an Android Context and a task to launch into. They carry their own, so neither threads an Activity through the call and neither is something you build from $appContext by hand.

$open

$open(url) launches a Custom Tab over the app, or the browser on a device with no Custom Tabs provider. It is how a link leaves the app. For markup that stays in the app, see <Document>.

$share

$share(…) opens the system share sheet. It takes navigator.share's three fields, any of them:

  • title
  • text
  • url

Text only. There is no field for a file or an image.

Any other field is a build error, share-shape, naming the field that does not belong. $share({ files: … }) does not compile.

Try it

Share.wh
import $lib.components.ui.Button

<Button onClick={() => $open("https://example.com/docs")}>Docs</Button>
Kotlin waiting
Scroll into view to compile.

$open is a call, so it works in a click handler. It launches a Custom Tab over the app, or the browser where the device has none.

See Also