bubble-whatsapp-status 0.0.0-stage → 1.0.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/README.md +134 -2
- package/android/build.gradle +19 -0
- package/android/src/main/AndroidManifest.xml +24 -0
- package/android/src/main/java/expo/modules/bubblewhatsappstatus/WhatsAppStatusModule.kt +162 -0
- package/android/src/main/res/xml/whatsapp_status_paths.xml +5 -0
- package/expo-module.config.json +9 -0
- package/index.d.ts +22 -0
- package/index.js +75 -0
- package/ios/BubbleWhatsAppStatus.podspec +25 -0
- package/ios/WhatsAppStatusModule.swift +176 -0
- package/package.json +31 -4
package/README.md
CHANGED
|
@@ -1,3 +1,135 @@
|
|
|
1
|
-
#
|
|
1
|
+
# bubble-whatsapp-status
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Native bridge for WhatsApp's official **Share to Status** API, built for Bubble
|
|
4
|
+
native mobile plugins (Expo SDK 57 / React Native 0.86).
|
|
5
|
+
|
|
6
|
+
It implements the two official Meta reference integrations:
|
|
7
|
+
|
|
8
|
+
- Android: `fbsamples/whatsapp_status_api_android`
|
|
9
|
+
- iOS: `fbsamples/whatsapp_status_api_ios`
|
|
10
|
+
|
|
11
|
+
The package does **not** open a general share sheet and does **not** use the
|
|
12
|
+
WhatsApp Business Cloud API. It hands one media item at a time to the WhatsApp
|
|
13
|
+
status composer and returns immediately after WhatsApp was opened.
|
|
14
|
+
|
|
15
|
+
## API
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const WaStatus = require('bubble-whatsapp-status');
|
|
19
|
+
|
|
20
|
+
await WaStatus.isWhatsAppInstalled();
|
|
21
|
+
// Android: "installed" | "missing"
|
|
22
|
+
// iOS: "installed" | "missing" | "unknown"
|
|
23
|
+
|
|
24
|
+
await WaStatus.shareToStatus({
|
|
25
|
+
filePath: '/var/mobile/.../whatsapp-status/0.jpg', // absolute path, no file:// needed
|
|
26
|
+
mimeType: 'image/jpeg'
|
|
27
|
+
});
|
|
28
|
+
// { opened: true, reason: "" }
|
|
29
|
+
// { opened: false, reason: "WHATSAPP_NOT_INSTALLED" | "FILE_NOT_FOUND" | ... }
|
|
30
|
+
|
|
31
|
+
await WaStatus.renderTextImage({
|
|
32
|
+
text: 'Hello status',
|
|
33
|
+
subtitle: 'optional small line',
|
|
34
|
+
theme: 'dark', // or 'light'
|
|
35
|
+
width: 1080,
|
|
36
|
+
height: 1920
|
|
37
|
+
});
|
|
38
|
+
// absolute path of a rendered PNG
|
|
39
|
+
|
|
40
|
+
await WaStatus.deleteTempFiles();
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## What WhatsApp actually supports
|
|
44
|
+
|
|
45
|
+
Verified against both reference repositories:
|
|
46
|
+
|
|
47
|
+
| Capability | Android | iOS |
|
|
48
|
+
|---|---|---|
|
|
49
|
+
| One image | yes (`EXTRA_STREAM`) | yes (`background_media`) |
|
|
50
|
+
| One video | yes (`EXTRA_STREAM`) | yes (`background_media` + `background_media_type: "mp4"`) |
|
|
51
|
+
| Second overlay media | yes (`foreground_media`) | yes (`foreground_media`) |
|
|
52
|
+
| Background color / gradient | yes | yes |
|
|
53
|
+
| Standalone text status | **not documented** | **not documented** |
|
|
54
|
+
| Standalone link status | **not documented** | **not documented** |
|
|
55
|
+
| Publish confirmation callback | **no** | **no** |
|
|
56
|
+
| Cancel callback | **no** | **no** |
|
|
57
|
+
|
|
58
|
+
Consequences implemented in the Bubble plugin:
|
|
59
|
+
|
|
60
|
+
- `text` and `link` are rendered locally to a PNG (1080×1920) and shared as an
|
|
61
|
+
image. A URL inside that image is **not clickable**.
|
|
62
|
+
- A return to the app is reported as `returned` / `returned_unconfirmed`.
|
|
63
|
+
`was_cancelled` is only set by the explicit in-app Cancel action.
|
|
64
|
+
- Only one media item per WhatsApp open. Up to five items are handed over
|
|
65
|
+
sequentially.
|
|
66
|
+
|
|
67
|
+
## Android details
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
Intent(ACTION_VIEW)
|
|
71
|
+
data = https://wa.me/status
|
|
72
|
+
package = com.whatsapp
|
|
73
|
+
extras = EXTRA_STREAM (content:// URI), share_type=SHARE_TO_STATUS,
|
|
74
|
+
source_app_package_name=<package>
|
|
75
|
+
flags = FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_PREFIX_URI_PERMISSION
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The library ships its own `FileProvider`
|
|
79
|
+
(`${applicationId}.whatsappstatus.fileprovider`, `cache-path whatsapp-status/`)
|
|
80
|
+
and a `<queries><package android:name="com.whatsapp"/></queries>` entry, both
|
|
81
|
+
merged into the app manifest automatically.
|
|
82
|
+
|
|
83
|
+
The reference app uses `startActivityForResult` and a transparent proxy
|
|
84
|
+
activity on Android 14+ **only because it launches from the system share
|
|
85
|
+
sheet**. From a foreground app, `startActivity` is allowed and is what this
|
|
86
|
+
module uses. WhatsApp does not return a documented "published" result code.
|
|
87
|
+
|
|
88
|
+
## iOS details
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
UIPasteboard.general.setItems(
|
|
92
|
+
[["com.whatsapp.media-share-external.data": [
|
|
93
|
+
"bundle_id": <bundle id>,
|
|
94
|
+
"background_media": <Data>,
|
|
95
|
+
"background_media_type": "png" | "jpg" | "mp4"
|
|
96
|
+
]]],
|
|
97
|
+
options: [.expirationDate: now + 120s]
|
|
98
|
+
)
|
|
99
|
+
UIApplication.shared.open(https://wa.me/media-share-external,
|
|
100
|
+
options: [.universalLinksOnly: true])
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`universalLinksOnly` makes the completion handler authoritative: it only
|
|
104
|
+
succeeds when an installed app claims the `wa.me` universal link, so the module
|
|
105
|
+
can report "not installed" without `LSApplicationQueriesSchemes`.
|
|
106
|
+
`isWhatsAppInstalled()` still uses `canOpenURL("whatsapp://")` and returns
|
|
107
|
+
`"unknown"` when the plist key is missing rather than a false negative.
|
|
108
|
+
|
|
109
|
+
Large videos are loaded into memory (`Data(contentsOf:)`), exactly like the
|
|
110
|
+
Meta sample. Keep the Bubble `max_file_size_mb` at 64 or lower unless you have
|
|
111
|
+
a reason to go higher.
|
|
112
|
+
|
|
113
|
+
## Installation in a Bubble plugin
|
|
114
|
+
|
|
115
|
+
1. Publish this package to npm (`npm publish`). The name
|
|
116
|
+
`bubble-whatsapp-status` is free at the time of writing.
|
|
117
|
+
2. In the Bubble plugin editor → *Shared technical settings* → *Additional
|
|
118
|
+
libraries*, add:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{ "bubble-whatsapp-status": "1.0.0" }
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
3. Create a **development build** (or a new production build) so the native
|
|
125
|
+
module is compiled into the app. BubbleGo cannot load third-party native
|
|
126
|
+
modules.
|
|
127
|
+
|
|
128
|
+
Bubble's documentation: additional libraries "have to be compiled into the
|
|
129
|
+
app", which is exactly this step.
|
|
130
|
+
|
|
131
|
+
## License
|
|
132
|
+
|
|
133
|
+
MIT for this package. The integration approach follows the Meta sample
|
|
134
|
+
projects, which are licensed under the Meta Platform Policy license; the
|
|
135
|
+
required copyright notice is reproduced in `NOTICE`.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
plugins {
|
|
2
|
+
id 'com.android.library'
|
|
3
|
+
id 'expo-module-gradle-plugin'
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
group = 'expo.modules.bubblewhatsappstatus'
|
|
7
|
+
version = '1.0.0'
|
|
8
|
+
|
|
9
|
+
android {
|
|
10
|
+
namespace "expo.modules.bubblewhatsappstatus"
|
|
11
|
+
defaultConfig {
|
|
12
|
+
versionCode 1
|
|
13
|
+
versionName '1.0.0'
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
dependencies {
|
|
18
|
+
implementation "androidx.core:core-ktx:1.17.0"
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
|
|
3
|
+
<!-- Required so getPackageInfo("com.whatsapp") can see the installed app
|
|
4
|
+
on Android 11+ (package visibility). -->
|
|
5
|
+
<queries>
|
|
6
|
+
<package android:name="com.whatsapp" />
|
|
7
|
+
<package android:name="com.whatsapp.w4b" />
|
|
8
|
+
</queries>
|
|
9
|
+
|
|
10
|
+
<application>
|
|
11
|
+
<!-- Serves the cached media file to WhatsApp with a temporary read grant.
|
|
12
|
+
Authority is unique per app: <applicationId>.whatsappstatus.fileprovider -->
|
|
13
|
+
<provider
|
|
14
|
+
android:name="androidx.core.content.FileProvider"
|
|
15
|
+
android:authorities="${applicationId}.whatsappstatus.fileprovider"
|
|
16
|
+
android:exported="false"
|
|
17
|
+
android:grantUriPermissions="true">
|
|
18
|
+
<meta-data
|
|
19
|
+
android:name="android.support.FILE_PROVIDER_PATHS"
|
|
20
|
+
android:resource="@xml/whatsapp_status_paths" />
|
|
21
|
+
</provider>
|
|
22
|
+
</application>
|
|
23
|
+
|
|
24
|
+
</manifest>
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
package expo.modules.bubblewhatsappstatus
|
|
2
|
+
|
|
3
|
+
import android.content.Intent
|
|
4
|
+
import android.graphics.Bitmap
|
|
5
|
+
import android.graphics.Canvas
|
|
6
|
+
import android.graphics.Color
|
|
7
|
+
import android.graphics.Paint
|
|
8
|
+
import android.graphics.Typeface
|
|
9
|
+
import android.net.Uri
|
|
10
|
+
import android.text.Layout
|
|
11
|
+
import android.text.StaticLayout
|
|
12
|
+
import android.text.TextPaint
|
|
13
|
+
import androidx.core.content.FileProvider
|
|
14
|
+
import expo.modules.kotlin.modules.Module
|
|
15
|
+
import expo.modules.kotlin.modules.ModuleDefinition
|
|
16
|
+
import java.io.File
|
|
17
|
+
import java.io.FileOutputStream
|
|
18
|
+
import java.util.UUID
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Native bridge for WhatsApp's official Share-to-Status API on Android.
|
|
22
|
+
*
|
|
23
|
+
* Mirrors the integration in fbsamples/whatsapp_status_api_android:
|
|
24
|
+
* ACTION_VIEW + https://wa.me/status
|
|
25
|
+
* package = com.whatsapp
|
|
26
|
+
* EXTRA_STREAM = content:// FileProvider URI (one media item per call)
|
|
27
|
+
* "share_type" = "SHARE_TO_STATUS"
|
|
28
|
+
* "source_app_package_name" = <our package>
|
|
29
|
+
* FLAG_GRANT_READ_URI_PERMISSION
|
|
30
|
+
*
|
|
31
|
+
* The official API accepts ONE background media item per intent. There is no
|
|
32
|
+
* documented extra for a standalone text or link status, and no documented
|
|
33
|
+
* result code that distinguishes "published" from "cancelled".
|
|
34
|
+
*/
|
|
35
|
+
class WhatsAppStatusModule : Module() {
|
|
36
|
+
override fun definition() = ModuleDefinition {
|
|
37
|
+
Name("WhatsAppStatus")
|
|
38
|
+
|
|
39
|
+
AsyncFunction("isWhatsAppInstalled") {
|
|
40
|
+
val context = appContext.reactContext ?: return@AsyncFunction "missing"
|
|
41
|
+
try {
|
|
42
|
+
context.packageManager.getPackageInfo("com.whatsapp", 0)
|
|
43
|
+
"installed"
|
|
44
|
+
} catch (e: Exception) {
|
|
45
|
+
"missing"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
AsyncFunction("shareToStatus") { filePath: String, mimeType: String ->
|
|
50
|
+
val context = appContext.reactContext
|
|
51
|
+
?: return@AsyncFunction mapOf("opened" to false, "reason" to "NO_CONTEXT")
|
|
52
|
+
val activity = appContext.currentActivity
|
|
53
|
+
?: return@AsyncFunction mapOf("opened" to false, "reason" to "NO_ACTIVITY")
|
|
54
|
+
|
|
55
|
+
val cleanPath = filePath.removePrefix("file://")
|
|
56
|
+
val file = File(cleanPath)
|
|
57
|
+
if (!file.exists() || file.length() <= 0L) {
|
|
58
|
+
return@AsyncFunction mapOf("opened" to false, "reason" to "FILE_NOT_FOUND")
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
val authority = context.packageName + ".whatsappstatus.fileprovider"
|
|
62
|
+
val uri: Uri = try {
|
|
63
|
+
FileProvider.getUriForFile(context, authority, file)
|
|
64
|
+
} catch (e: Exception) {
|
|
65
|
+
return@AsyncFunction mapOf("opened" to false, "reason" to "FILE_PROVIDER_ERROR")
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
val intent = Intent(Intent.ACTION_VIEW).apply {
|
|
69
|
+
data = Uri.parse("https://wa.me/status")
|
|
70
|
+
setPackage("com.whatsapp")
|
|
71
|
+
putExtra(Intent.EXTRA_STREAM, uri)
|
|
72
|
+
putExtra("share_type", "SHARE_TO_STATUS")
|
|
73
|
+
putExtra("source_app_package_name", context.packageName)
|
|
74
|
+
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
75
|
+
addFlags(Intent.FLAG_GRANT_PREFIX_URI_PERMISSION)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
activity.startActivity(intent)
|
|
80
|
+
} catch (e: android.content.ActivityNotFoundException) {
|
|
81
|
+
return@AsyncFunction mapOf("opened" to false, "reason" to "WHATSAPP_NOT_INSTALLED")
|
|
82
|
+
} catch (e: Exception) {
|
|
83
|
+
return@AsyncFunction mapOf("opened" to false, "reason" to "INTENT_FAILED")
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
mapOf("opened" to true, "reason" to "")
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
AsyncFunction("renderTextImage") { text: String, subtitle: String, theme: String, width: Int, height: Int ->
|
|
90
|
+
val context = appContext.reactContext ?: throw Exception("NO_CONTEXT")
|
|
91
|
+
val safeWidth = if (width in 320..4096) width else 1080
|
|
92
|
+
val safeHeight = if (height in 320..4096) height else 1920
|
|
93
|
+
|
|
94
|
+
val dark = theme != "light"
|
|
95
|
+
val background = if (dark) Color.parseColor("#0B141A") else Color.parseColor("#FFFFFF")
|
|
96
|
+
val foreground = if (dark) Color.parseColor("#FFFFFF") else Color.parseColor("#111111")
|
|
97
|
+
val secondary = if (dark) Color.parseColor("#B8C4CC") else Color.parseColor("#4A4A4A")
|
|
98
|
+
|
|
99
|
+
val bitmap = Bitmap.createBitmap(safeWidth, safeHeight, Bitmap.Config.ARGB_8888)
|
|
100
|
+
val canvas = Canvas(bitmap)
|
|
101
|
+
canvas.drawColor(background)
|
|
102
|
+
|
|
103
|
+
val padding = safeWidth * 0.10f
|
|
104
|
+
val contentWidth = (safeWidth - padding * 2).toInt()
|
|
105
|
+
|
|
106
|
+
val titlePaint = TextPaint().apply {
|
|
107
|
+
isAntiAlias = true
|
|
108
|
+
color = foreground
|
|
109
|
+
textSize = safeWidth * 0.070f
|
|
110
|
+
typeface = Typeface.create("sans-serif", Typeface.NORMAL)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
val titleLayout = StaticLayout.Builder
|
|
114
|
+
.obtain(text, 0, text.length, titlePaint, contentWidth)
|
|
115
|
+
.setAlignment(Layout.Alignment.ALIGN_CENTER)
|
|
116
|
+
.setLineSpacing(0f, 1.18f)
|
|
117
|
+
.setIncludePad(false)
|
|
118
|
+
.build()
|
|
119
|
+
|
|
120
|
+
val subtitlePaint = Paint().apply {
|
|
121
|
+
isAntiAlias = true
|
|
122
|
+
color = secondary
|
|
123
|
+
textSize = safeWidth * 0.038f
|
|
124
|
+
typeface = Typeface.create("sans-serif", Typeface.NORMAL)
|
|
125
|
+
textAlign = Paint.Align.CENTER
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
val subtitleHeight = if (subtitle.isNotEmpty()) subtitlePaint.textSize * 1.6f else 0f
|
|
129
|
+
val blockHeight = titleLayout.height + subtitleHeight
|
|
130
|
+
val startY = (safeHeight - blockHeight) / 2f
|
|
131
|
+
|
|
132
|
+
canvas.save()
|
|
133
|
+
canvas.translate(padding, startY)
|
|
134
|
+
titleLayout.draw(canvas)
|
|
135
|
+
canvas.restore()
|
|
136
|
+
|
|
137
|
+
if (subtitle.isNotEmpty()) {
|
|
138
|
+
canvas.drawText(
|
|
139
|
+
subtitle,
|
|
140
|
+
safeWidth / 2f,
|
|
141
|
+
startY + titleLayout.height + subtitlePaint.textSize * 1.2f,
|
|
142
|
+
subtitlePaint
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
val dir = File(context.cacheDir, "whatsapp-status").apply { mkdirs() }
|
|
147
|
+
val output = File(dir, "text-${UUID.randomUUID()}.png")
|
|
148
|
+
FileOutputStream(output).use { stream ->
|
|
149
|
+
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream)
|
|
150
|
+
}
|
|
151
|
+
bitmap.recycle()
|
|
152
|
+
|
|
153
|
+
output.absolutePath
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
AsyncFunction("deleteTempFiles") {
|
|
157
|
+
val context = appContext.reactContext ?: return@AsyncFunction false
|
|
158
|
+
File(context.cacheDir, "whatsapp-status").deleteRecursively()
|
|
159
|
+
true
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type Availability = 'installed' | 'missing' | 'unknown';
|
|
2
|
+
|
|
3
|
+
export interface ShareResult {
|
|
4
|
+
opened: boolean;
|
|
5
|
+
reason?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface RenderOptions {
|
|
9
|
+
text: string;
|
|
10
|
+
subtitle?: string;
|
|
11
|
+
theme?: 'dark' | 'light';
|
|
12
|
+
width?: number;
|
|
13
|
+
height?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export declare function isWhatsAppInstalled(): Promise<Availability>;
|
|
17
|
+
export declare function shareToStatus(options: {
|
|
18
|
+
filePath: string;
|
|
19
|
+
mimeType?: string;
|
|
20
|
+
}): Promise<ShareResult>;
|
|
21
|
+
export declare function renderTextImage(options: RenderOptions): Promise<string>;
|
|
22
|
+
export declare function deleteTempFiles(): Promise<boolean>;
|
package/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { requireNativeModule } = require('expo-modules-core');
|
|
4
|
+
|
|
5
|
+
let Native = null;
|
|
6
|
+
let loadError = null;
|
|
7
|
+
|
|
8
|
+
function native() {
|
|
9
|
+
if (Native) return Native;
|
|
10
|
+
if (loadError) throw loadError;
|
|
11
|
+
try {
|
|
12
|
+
Native = requireNativeModule('WhatsAppStatus');
|
|
13
|
+
return Native;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
loadError = new Error(
|
|
16
|
+
'bubble-whatsapp-status: native module not found. ' +
|
|
17
|
+
'The plugin library must be compiled into a development build or production build. ' +
|
|
18
|
+
'(' + (e && e.message ? e.message : String(e)) + ')'
|
|
19
|
+
);
|
|
20
|
+
throw loadError;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Availability probe.
|
|
26
|
+
* Android: returns "installed" or "missing".
|
|
27
|
+
* iOS: returns "installed", "missing" or "unknown" (canOpenURL needs
|
|
28
|
+
* LSApplicationQueriesSchemes; "unknown" means the plugin cannot decide
|
|
29
|
+
* before the first hand-off, and the actual open call is authoritative).
|
|
30
|
+
*/
|
|
31
|
+
async function isWhatsAppInstalled() {
|
|
32
|
+
return await native().isWhatsAppInstalled();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Hands ONE media file to the WhatsApp status composer.
|
|
37
|
+
* @param {{ filePath: string, mimeType?: string }} options
|
|
38
|
+
* @returns {Promise<{opened: boolean, reason?: string}>}
|
|
39
|
+
*/
|
|
40
|
+
async function shareToStatus(options) {
|
|
41
|
+
const filePath = options && options.filePath;
|
|
42
|
+
if (!filePath) throw new Error('shareToStatus: filePath is required');
|
|
43
|
+
const mimeType = (options && options.mimeType) || 'image/jpeg';
|
|
44
|
+
return await native().shareToStatus(filePath, mimeType);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Renders text (and an optional non-clickable subtitle/URL) to a PNG in the
|
|
49
|
+
* app cache directory. Returns the absolute file path.
|
|
50
|
+
* @param {{ text: string, subtitle?: string, theme?: 'dark'|'light', width?: number, height?: number }} options
|
|
51
|
+
* @returns {Promise<string>}
|
|
52
|
+
*/
|
|
53
|
+
async function renderTextImage(options) {
|
|
54
|
+
const text = options && options.text;
|
|
55
|
+
if (!text) throw new Error('renderTextImage: text is required');
|
|
56
|
+
return await native().renderTextImage(
|
|
57
|
+
String(text),
|
|
58
|
+
String((options && options.subtitle) || ''),
|
|
59
|
+
(options && options.theme) === 'light' ? 'light' : 'dark',
|
|
60
|
+
(options && options.width) || 1080,
|
|
61
|
+
(options && options.height) || 1920
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Deletes every temporary file created by this module. */
|
|
66
|
+
async function deleteTempFiles() {
|
|
67
|
+
return await native().deleteTempFiles();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
isWhatsAppInstalled,
|
|
72
|
+
shareToStatus,
|
|
73
|
+
renderTextImage,
|
|
74
|
+
deleteTempFiles,
|
|
75
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'BubbleWhatsAppStatus'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.description = package['description']
|
|
10
|
+
s.license = package['license']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.homepage = package['homepage']
|
|
13
|
+
s.platforms = { :ios => '15.1' }
|
|
14
|
+
s.swift_version = '5.9'
|
|
15
|
+
s.source = { :git => 'https://github.com/' }
|
|
16
|
+
s.static_framework = true
|
|
17
|
+
|
|
18
|
+
s.dependency 'ExpoModulesCore'
|
|
19
|
+
|
|
20
|
+
s.source_files = '**/*.{h,m,swift}'
|
|
21
|
+
s.pod_target_xcconfig = {
|
|
22
|
+
'DEFINES_MODULE' => 'YES',
|
|
23
|
+
'SWIFT_COMPILATION_MODE' => 'wholemodule'
|
|
24
|
+
}
|
|
25
|
+
end
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Native bridge for WhatsApp's official Share-to-Status API on iOS.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors fbsamples/whatsapp_status_api_ios:
|
|
8
|
+
* UIPasteboard.general.setItems(
|
|
9
|
+
* [["com.whatsapp.media-share-external.data": [
|
|
10
|
+
* "bundle_id": <our bundle id>,
|
|
11
|
+
* "background_media": <Data>,
|
|
12
|
+
* "background_media_type": "png" | "jpg" | "mp4"
|
|
13
|
+
* ]]],
|
|
14
|
+
* options: [.expirationDate: Date + 120s]
|
|
15
|
+
* )
|
|
16
|
+
* then open https://wa.me/media-share-external
|
|
17
|
+
*
|
|
18
|
+
* One media item per call. No text/link payload is documented by Meta.
|
|
19
|
+
*/
|
|
20
|
+
public class WhatsAppStatusModule: Module {
|
|
21
|
+
public func definition() -> ModuleDefinition {
|
|
22
|
+
Name("WhatsAppStatus")
|
|
23
|
+
|
|
24
|
+
AsyncFunction("isWhatsAppInstalled") { () -> String in
|
|
25
|
+
// canOpenURL("whatsapp://") requires LSApplicationQueriesSchemes.
|
|
26
|
+
// If the key is not declared iOS always returns false, so we report
|
|
27
|
+
// "unknown" instead of pretending WhatsApp is missing.
|
|
28
|
+
guard let url = URL(string: "whatsapp://") else { return "missing" }
|
|
29
|
+
if UIApplication.shared.canOpenURL(url) { return "installed" }
|
|
30
|
+
return "unknown"
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
AsyncFunction("shareToStatus") { (filePath: String, mimeType: String, promise: Promise) in
|
|
34
|
+
let cleanPath = filePath.replacingOccurrences(of: "file://", with: "")
|
|
35
|
+
guard FileManager.default.fileExists(atPath: cleanPath) else {
|
|
36
|
+
promise.resolve(["opened": false, "reason": "FILE_NOT_FOUND"])
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
guard let data = try? Data(contentsOf: URL(fileURLWithPath: cleanPath)), !data.isEmpty else {
|
|
40
|
+
promise.resolve(["opened": false, "reason": "FILE_READ_ERROR"])
|
|
41
|
+
return
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let mediaType: String
|
|
45
|
+
if mimeType.contains("mp4") {
|
|
46
|
+
mediaType = "mp4"
|
|
47
|
+
} else if mimeType.contains("png") {
|
|
48
|
+
mediaType = "png"
|
|
49
|
+
} else {
|
|
50
|
+
mediaType = "jpg"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
guard let bundleId = Bundle.main.bundleIdentifier else {
|
|
54
|
+
promise.resolve(["opened": false, "reason": "NO_BUNDLE_ID"])
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let payload: [String: Any] = [
|
|
59
|
+
"bundle_id": bundleId,
|
|
60
|
+
"background_media": data,
|
|
61
|
+
"background_media_type": mediaType
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
DispatchQueue.main.async {
|
|
65
|
+
UIPasteboard.general.setItems(
|
|
66
|
+
[["com.whatsapp.media-share-external.data": payload]],
|
|
67
|
+
options: [.expirationDate: Date().addingTimeInterval(120)]
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
guard let url = URL(string: "https://wa.me/media-share-external") else {
|
|
71
|
+
promise.resolve(["opened": false, "reason": "BAD_URL"])
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// universalLinksOnly makes the completion handler authoritative:
|
|
76
|
+
// success == WhatsApp handled the universal link.
|
|
77
|
+
UIApplication.shared.open(url, options: [.universalLinksOnly: true]) { success in
|
|
78
|
+
if success {
|
|
79
|
+
promise.resolve(["opened": true, "reason": ""])
|
|
80
|
+
} else {
|
|
81
|
+
promise.resolve(["opened": false, "reason": "WHATSAPP_NOT_INSTALLED"])
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
AsyncFunction("renderTextImage") { (text: String, subtitle: String, theme: String, width: Int, height: Int) -> String in
|
|
88
|
+
let safeWidth = (320...4096).contains(width) ? width : 1080
|
|
89
|
+
let safeHeight = (320...4096).contains(height) ? height : 1920
|
|
90
|
+
let size = CGSize(width: CGFloat(safeWidth), height: CGFloat(safeHeight))
|
|
91
|
+
let dark = theme != "light"
|
|
92
|
+
|
|
93
|
+
let background = dark
|
|
94
|
+
? UIColor(red: 11.0 / 255.0, green: 20.0 / 255.0, blue: 26.0 / 255.0, alpha: 1)
|
|
95
|
+
: UIColor.white
|
|
96
|
+
let foreground = dark ? UIColor.white : UIColor(white: 0.07, alpha: 1)
|
|
97
|
+
let secondary = dark
|
|
98
|
+
? UIColor(red: 184.0 / 255.0, green: 196.0 / 255.0, blue: 204.0 / 255.0, alpha: 1)
|
|
99
|
+
: UIColor(white: 0.29, alpha: 1)
|
|
100
|
+
|
|
101
|
+
let renderer = UIGraphicsImageRenderer(size: size)
|
|
102
|
+
let image = renderer.image { context in
|
|
103
|
+
background.setFill()
|
|
104
|
+
context.fill(CGRect(origin: .zero, size: size))
|
|
105
|
+
|
|
106
|
+
let inset = CGFloat(safeWidth) * 0.10
|
|
107
|
+
let contentWidth = CGFloat(safeWidth) - inset * 2
|
|
108
|
+
|
|
109
|
+
let paragraph = NSMutableParagraphStyle()
|
|
110
|
+
paragraph.alignment = .center
|
|
111
|
+
paragraph.lineSpacing = 10
|
|
112
|
+
|
|
113
|
+
let titleAttributes: [NSAttributedString.Key: Any] = [
|
|
114
|
+
.font: UIFont.systemFont(ofSize: CGFloat(safeWidth) * 0.070, weight: .regular),
|
|
115
|
+
.foregroundColor: foreground,
|
|
116
|
+
.paragraphStyle: paragraph
|
|
117
|
+
]
|
|
118
|
+
|
|
119
|
+
let bounding = (text as NSString).boundingRect(
|
|
120
|
+
with: CGSize(width: contentWidth, height: .greatestFiniteMagnitude),
|
|
121
|
+
options: [.usesLineFragmentOrigin, .usesFontLeading],
|
|
122
|
+
attributes: titleAttributes,
|
|
123
|
+
context: nil
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
let subtitleAttributes: [NSAttributedString.Key: Any] = [
|
|
127
|
+
.font: UIFont.systemFont(ofSize: CGFloat(safeWidth) * 0.038, weight: .regular),
|
|
128
|
+
.foregroundColor: secondary,
|
|
129
|
+
.paragraphStyle: paragraph
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
let subtitleHeight: CGFloat = subtitle.isEmpty ? 0 : CGFloat(safeWidth) * 0.038 * 2.2
|
|
133
|
+
let blockHeight = bounding.height + subtitleHeight
|
|
134
|
+
let startY = (CGFloat(safeHeight) - blockHeight) / 2
|
|
135
|
+
|
|
136
|
+
(text as NSString).draw(
|
|
137
|
+
with: CGRect(x: inset, y: startY, width: contentWidth, height: bounding.height),
|
|
138
|
+
options: [.usesLineFragmentOrigin, .usesFontLeading],
|
|
139
|
+
attributes: titleAttributes,
|
|
140
|
+
context: nil
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
if !subtitle.isEmpty {
|
|
144
|
+
(subtitle as NSString).draw(
|
|
145
|
+
with: CGRect(x: inset, y: startY + bounding.height + 12, width: contentWidth, height: subtitleHeight),
|
|
146
|
+
options: [.usesLineFragmentOrigin, .usesFontLeading],
|
|
147
|
+
attributes: subtitleAttributes,
|
|
148
|
+
context: nil
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
guard let data = image.pngData() else {
|
|
154
|
+
throw Exception("PNG_ENCODE_FAILED")
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let directory = FileManager.default
|
|
158
|
+
.urls(for: .cachesDirectory, in: .userDomainMask)[0]
|
|
159
|
+
.appendingPathComponent("whatsapp-status", isDirectory: true)
|
|
160
|
+
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
|
|
161
|
+
|
|
162
|
+
let file = directory.appendingPathComponent("text-\(UUID().uuidString).png")
|
|
163
|
+
try data.write(to: file)
|
|
164
|
+
|
|
165
|
+
return file.path
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
AsyncFunction("deleteTempFiles") { () -> Bool in
|
|
169
|
+
let directory = FileManager.default
|
|
170
|
+
.urls(for: .cachesDirectory, in: .userDomainMask)[0]
|
|
171
|
+
.appendingPathComponent("whatsapp-status", isDirectory: true)
|
|
172
|
+
try? FileManager.default.removeItem(at: directory)
|
|
173
|
+
return true
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bubble-whatsapp-status",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Native WhatsApp Share-to-Status bridge (Android + iOS) for Bubble native mobile plugins.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "Nils Klinger",
|
|
9
|
+
"homepage": "https://github.com/",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"expo",
|
|
12
|
+
"react-native",
|
|
13
|
+
"whatsapp",
|
|
14
|
+
"status",
|
|
15
|
+
"bubble"
|
|
16
|
+
],
|
|
17
|
+
"files": [
|
|
18
|
+
"index.js",
|
|
19
|
+
"index.d.ts",
|
|
20
|
+
"expo-module.config.json",
|
|
21
|
+
"android",
|
|
22
|
+
"ios",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"expo": "*",
|
|
27
|
+
"react": "*",
|
|
28
|
+
"react-native": "*"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"expo-modules-core": "^57.0.11"
|
|
32
|
+
}
|
|
33
|
+
}
|