@sigx/lynx-share 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Andreas Ekdahl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # @sigx/lynx-share
2
+
3
+ Native share dialog for sigx-lynx. `UIActivityViewController` on iOS, `Intent.ACTION_SEND` chooser on Android.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @sigx/lynx-share
9
+ ```
10
+
11
+ ```ts
12
+ // sigx.lynx.config.ts
13
+ export default defineLynxConfig({
14
+ modules: ['@sigx/lynx-share'],
15
+ });
16
+ ```
17
+
18
+ No special permissions on either platform.
19
+
20
+ ## Usage
21
+
22
+ ```ts
23
+ import { Share } from '@sigx/lynx-share';
24
+
25
+ Share.share({
26
+ title: 'Check this out',
27
+ message: 'Built with sigx-lynx!',
28
+ url: 'https://sigx.dev',
29
+ });
30
+ ```
31
+
32
+ ## API
33
+
34
+ | Method | Notes |
35
+ | ------------------------------------- | -------------------------------------------------------------------------------------------------- |
36
+ | `share(options: ShareOptions): void` | Sync — fire-and-forget. The share sheet dismissal isn't surfaced as a callback. |
37
+ | `isAvailable(): boolean` | Whether the native module is registered in the current build. |
38
+
39
+ ```ts
40
+ interface ShareOptions {
41
+ title?: string;
42
+ message?: string;
43
+ url?: string;
44
+ }
45
+ ```
46
+
47
+ ## Gotchas
48
+
49
+ - **Sharing files** isn't directly supported — `url` is treated as a string (web URL). For local file sharing, the native side would need to handle file URIs and FileProvider authority, which isn't wired here yet.
50
+ - **No completion callback.** If you need to know whether the user actually shared (vs. cancelled the sheet), you'll need to extend the native module with `UIActivityViewController.completionWithItemsHandler` (iOS) / `ACTION_SEND` result handling (Android, harder — there's no clean signal).
51
+
52
+ ## Reference app
53
+
54
+ `examples/lynx-one/my-sigx-app/src/cards/ShareCard.tsx` covers a simple share-sheet trigger with title + message + URL.
@@ -0,0 +1,44 @@
1
+ package com.sigx.share
2
+
3
+ import android.content.Context
4
+ import android.content.Intent
5
+ import com.lynx.jsbridge.LynxMethod
6
+ import com.lynx.jsbridge.LynxModule
7
+ import com.lynx.react.bridge.ReadableMap
8
+
9
+ /**
10
+ * Native share dialog module.
11
+ * JS usage: NativeModules.Share.share({ title: "Check this out", text: "Hello!", url: "https://..." })
12
+ */
13
+ class ShareModule(context: Context) : LynxModule(context) {
14
+
15
+ @LynxMethod
16
+ fun share(options: ReadableMap?) {
17
+ if (options == null) return
18
+
19
+ val title = if (options.hasKey("title")) options.getString("title") else null
20
+ val text = if (options.hasKey("text")) options.getString("text") else null
21
+ val url = if (options.hasKey("url")) options.getString("url") else null
22
+
23
+ val shareText = buildString {
24
+ text?.let { append(it) }
25
+ url?.let {
26
+ if (isNotEmpty()) append("\n")
27
+ append(it)
28
+ }
29
+ }
30
+
31
+ val intent = Intent(Intent.ACTION_SEND).apply {
32
+ type = "text/plain"
33
+ if (title != null) putExtra(Intent.EXTRA_SUBJECT, title)
34
+ if (shareText.isNotEmpty()) putExtra(Intent.EXTRA_TEXT, shareText)
35
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
36
+ }
37
+
38
+ val chooser = Intent.createChooser(intent, title ?: "Share").apply {
39
+ addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
40
+ }
41
+ mContext.startActivity(chooser)
42
+ }
43
+ }
44
+
@@ -0,0 +1,3 @@
1
+ export { Share } from './share.js';
2
+ export type { ShareOptions } from './share.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { Share } from './share.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,20 @@
1
+ export interface ShareOptions {
2
+ title?: string;
3
+ message?: string;
4
+ url?: string;
5
+ }
6
+ /**
7
+ * Native share dialog APIs.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { Share } from '@sigx/lynx-share';
12
+ *
13
+ * Share.share({ title: 'Check this out', message: 'Built with sigx-lynx!', url: 'https://sigx.dev' });
14
+ * ```
15
+ */
16
+ export declare const Share: {
17
+ readonly share: (options: ShareOptions) => void;
18
+ readonly isAvailable: () => boolean;
19
+ };
20
+ //# sourceMappingURL=share.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share.d.ts","sourceRoot":"","sources":["../src/share.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,KAAK;8BACC,YAAY,KAAG,IAAI;gCAInB,OAAO;CAGhB,CAAC"}
package/dist/share.js ADDED
@@ -0,0 +1,21 @@
1
+ import { callSync, isModuleAvailable } from '@sigx/lynx-core';
2
+ const MODULE = 'Share';
3
+ /**
4
+ * Native share dialog APIs.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { Share } from '@sigx/lynx-share';
9
+ *
10
+ * Share.share({ title: 'Check this out', message: 'Built with sigx-lynx!', url: 'https://sigx.dev' });
11
+ * ```
12
+ */
13
+ export const Share = {
14
+ share(options) {
15
+ callSync(MODULE, 'share', options);
16
+ },
17
+ isAvailable() {
18
+ return isModuleAvailable(MODULE);
19
+ },
20
+ };
21
+ //# sourceMappingURL=share.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"share.js","sourceRoot":"","sources":["../src/share.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE9D,MAAM,MAAM,GAAG,OAAO,CAAC;AAQvB;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACjB,KAAK,CAAC,OAAqB;QACvB,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,WAAW;QACP,OAAO,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACrC,CAAC;CACK,CAAC"}
@@ -0,0 +1,47 @@
1
+ import UIKit
2
+ import Lynx
3
+
4
+ /// Native share dialog module.
5
+ /// JS usage: NativeModules.Share.share({ title: "Check this", text: "Hello!", url: "https://..." })
6
+ class ShareModule: NSObject, LynxModule {
7
+
8
+ @objc static var name: String { "Share" }
9
+
10
+ @objc static var methodLookup: [String: String] {
11
+ [
12
+ "share": NSStringFromSelector(#selector(share(_:))),
13
+ ]
14
+ }
15
+
16
+ required override init() { super.init() }
17
+ required init(param: Any) { super.init() }
18
+
19
+ @objc func share(_ options: [String: Any]?) {
20
+ guard let options = options else { return }
21
+
22
+ let title = options["title"] as? String
23
+ let text = options["text"] as? String
24
+ let urlString = options["url"] as? String
25
+
26
+ var items: [Any] = []
27
+ if let text = text { items.append(text) }
28
+ if let urlString = urlString, let url = URL(string: urlString) {
29
+ items.append(url)
30
+ }
31
+
32
+ guard !items.isEmpty else { return }
33
+
34
+ DispatchQueue.main.async {
35
+ let activityVC = UIActivityViewController(activityItems: items, applicationActivities: nil)
36
+ activityVC.setValue(title, forKey: "subject")
37
+
38
+ if let popover = activityVC.popoverPresentationController {
39
+ popover.sourceView = UIApplication.shared.windows.first?.rootViewController?.view
40
+ popover.sourceRect = CGRect(x: UIScreen.main.bounds.midX, y: UIScreen.main.bounds.midY, width: 0, height: 0)
41
+ popover.permittedArrowDirections = []
42
+ }
43
+
44
+ UIApplication.shared.windows.first?.rootViewController?.present(activityVC, animated: true)
45
+ }
46
+ }
47
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@sigx/lynx-share",
3
+ "version": "0.1.0",
4
+ "description": "Native share dialog for sigx-lynx",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ },
13
+ "./sigx-module.json": "./sigx-module.json"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "ios",
18
+ "android",
19
+ "sigx-module.json"
20
+ ],
21
+ "dependencies": {
22
+ "@sigx/lynx-core": "^0.1.0"
23
+ },
24
+ "devDependencies": {
25
+ "typescript": "^5.9.3"
26
+ },
27
+ "author": "Andreas Ekdahl",
28
+ "license": "MIT",
29
+ "scripts": {
30
+ "build": "tsc",
31
+ "dev": "tsc --watch"
32
+ }
33
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "Share",
3
+ "package": "@sigx/lynx-share",
4
+ "description": "Native share dialog",
5
+ "platforms": ["android", "ios"],
6
+ "ios": {
7
+ "moduleClass": "ShareModule",
8
+ "sourceDir": "ios",
9
+ "methods": ["share"]
10
+ },
11
+ "android": {
12
+ "moduleClass": "com.sigx.share.ShareModule",
13
+ "sourceDir": "android",
14
+ "permissions": []
15
+ }
16
+ }