Sharing
Shows the system share sheet so users can send content to other apps. Share.share takes files, links and a message, like React Native's Share. Sharing.shareAsync shares one local file, like expo-sharing.
- pyxpo-sharing
- v0.1.0a1
- Native: Swift + Kotlin
- Like expo-sharing and React Native Share
Install
Install the package into the same environment as pyxpo.
Add sharing to modules in your app config, then import it in your code.
[tool.pyxpo]
modules = ["sharing"]from pyxpo_sharing import Share, SharingThis module has native code. After you add it, run pyxpo run or pyxpo build again so it is compiled into the app. Hot reload alone is not enough.
Platforms
Quick start
from pyxpo_sharing import Share
async def share_photo(uri):
res = await Share.share({"url": uri, "message": "Look at this"})
return res["action"] # "sharedAction" or "dismissedAction"Permissions
pyxpo adds these to Info.plist and AndroidManifest.xml for you when the module is listed.
| iOS | None. |
|---|---|
| Android | None. The module declares its own FileProvider. |
API reference
Share
await Share.share(content, options=None)→ {"action"}content is {"url": ...} or {"urls": [...]}, with an optional "message". Local paths are shared as files. http and https links are added to the message. options: {"dialogTitle"} (Android).
Sharing
snake_case names also work: share_async, is_available_async.
await Sharing.isAvailableAsync()→ boolTrue when the module is linked.
await Sharing.shareAsync(url, options=None)→ NoneShares one local file. A web link raises ValueError. options: mimeType, dialogTitle (Android).
Examples
Share several files
Send all edited photos in one share sheet.
from pyxpo_sharing import Share
async def share_all(uris):
await Share.share({"urls": uris, "message": "Edited with my app"},
{"dialogTitle": "Send photos"})Share a generated file
Write a file, then hand it to another app.
from pyxpo_file_system import File, Paths
from pyxpo_sharing import Sharing
async def export_csv(rows):
f = File(Paths.cache, "export.csv")
f.write("\n".join(",".join(map(str, r)) for r in rows))
if await Sharing.isAvailableAsync():
await Sharing.shareAsync(f.uri, {"mimeType": "text/csv"})Good to know
- Android always reports "sharedAction", because the system does not say whether the user finished.
- On Android, files are shared from the app's cache and files folders.