tauri-plugin-live-activity 0.2.1 → 0.5.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.ko.md +185 -25
- package/README.md +185 -26
- package/cli/ios.mjs +102 -43
- package/cli/main.mjs +32 -7
- package/cli/migration.mjs +55 -0
- package/cli/report.mjs +2 -2
- package/cli/setup.mjs +27 -10
- package/cli/steps.mjs +1 -1
- package/cli/templates/LiveActivityCustomViews.swift +25 -0
- package/cli/widget-files.mjs +148 -0
- package/cli/xcodegen.mjs +70 -16
- package/dist-js/index.d.ts +16 -4
- package/dist-js/index.js +17 -2
- package/dist-js/jsx/index.d.ts +59 -0
- package/dist-js/jsx/index.js +101 -0
- package/dist-js/jsx/jsx-dev-runtime.d.ts +4 -0
- package/dist-js/jsx/jsx-dev-runtime.js +6 -0
- package/dist-js/jsx/jsx-runtime.d.ts +16 -0
- package/dist-js/jsx/jsx-runtime.js +9 -0
- package/dist-js/layout.d.ts +14 -3
- package/dist-js/layout.js +18 -3
- package/dist-js/react/index.d.ts +12 -0
- package/dist-js/react/index.js +42 -0
- package/dist-js/react/session.d.ts +68 -0
- package/dist-js/react/session.js +138 -0
- package/dist-js/types.d.ts +83 -19
- package/package.json +17 -4
package/README.ko.md
CHANGED
|
@@ -23,8 +23,12 @@ Tauri 2 앱이 하고 있는 일을 iPhone 잠금 화면과 Dynamic Island에, A
|
|
|
23
23
|
</table>
|
|
24
24
|
|
|
25
25
|
네 장 모두 고양이 Mochi를 따라가는 [데모 앱](https://github.com/1eedaegon/tauri-plugin-live-activity/tree/main/examples/demo)에서
|
|
26
|
-
캡처했습니다. 플러그인은 iOS 16.
|
|
27
|
-
`UNSUPPORTED_PLATFORM`을 돌려줍니다.
|
|
26
|
+
캡처했습니다. 플러그인은 iOS 16.2 이상과 Android 8 이상에서 동작하고, 데스크톱에서는 활동 명령이
|
|
27
|
+
`UNSUPPORTED_PLATFORM`을 돌려줍니다. iOS에서는 [activitykit](https://github.com/1eedaegon/activitykit-rs) 크레이트
|
|
28
|
+
위에서 동작하므로 플러그인 자체의 Swift 코드가 없습니다. Android에서는 진행률과 타이머 템플릿의 수명 주기를
|
|
29
|
+
[liveupdate](https://github.com/1eedaegon/liveupdate-rs) 크레이트로 Rust에서 처리합니다. 레이아웃도 이 크레이트가
|
|
30
|
+
안드로이드 알림 스타일로 그리고, 플러그인의 Kotlin은 권한 명령만 맡습니다. 1.0 전까지는 마이너 버전이 바뀔 때 API도 바뀔 수
|
|
31
|
+
있습니다.
|
|
28
32
|
|
|
29
33
|
## 설치
|
|
30
34
|
|
|
@@ -43,8 +47,9 @@ npx tauri-plugin-live-activity setup
|
|
|
43
47
|
```
|
|
44
48
|
|
|
45
49
|
`setup`은 플러그인 권한을 허용하고, Android 최소 버전을 API 26으로 올리고, Mac에서는 활동을 그리는
|
|
46
|
-
위젯 확장을 Xcode 프로젝트에 추가합니다. `tauri ios init` 뒤에 실행하고, 나중에
|
|
47
|
-
처음부터 다시 만들었다면 한 번 더 실행하세요.
|
|
50
|
+
위젯 확장을 activitykit의 Swift 패키지로 Xcode 프로젝트에 추가합니다. `tauri ios init` 뒤에 실행하고, 나중에
|
|
51
|
+
`src-tauri/gen/apple`을 처음부터 다시 만들었다면 한 번 더 실행하세요. 0.3으로 설정한 앱이라면 다시 한 번
|
|
52
|
+
실행하면 위젯과 직접 만든 뷰를 activitykit으로 옮겨 줍니다. 무엇이 바뀔지는 `--dry-run`으로 먼저 볼 수 있습니다.
|
|
48
53
|
|
|
49
54
|
## 사용법
|
|
50
55
|
|
|
@@ -69,35 +74,190 @@ await endLayout({ id: snack.id, policy: { kind: 'immediate' } });
|
|
|
69
74
|
레이아웃은 시작할 때 모습 그대로 유지됩니다. 갱신할 때는 모든 값을 더 높은 revision과 함께 다시
|
|
70
75
|
보냅니다.
|
|
71
76
|
|
|
77
|
+
## 스타일 바꾸기
|
|
78
|
+
|
|
79
|
+
트리는 시작할 때 정해지지만, 몇몇 스타일 멤버는 값을 가리킬 수 있습니다. 그러면 갱신으로 바꿀 수 있습니다.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
const { bind } = layout;
|
|
83
|
+
// styles: { status: { color: bind('tone'), weight: bind('weight') } }, values: { tone: 'green', weight: 'regular', … }
|
|
84
|
+
await updateLayout({ id, snapshot: { revision: 2, values: { ...values, tone: 'red', weight: 'bold' } } });
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```rust
|
|
88
|
+
let status = Style { color: Some(Bound::key("tone").into()), ..Style::default() };
|
|
89
|
+
// 나중에: 값을 모두 다시 보내면서 색만 바꿉니다.
|
|
90
|
+
values.insert("tone".into(), Value::Text("red".into()));
|
|
91
|
+
app.live_activity().update_layout(LayoutUpdateInput { id, snapshot: LayoutSnapshot { revision: 2, values, stale_at: None, timestamp: None } })?;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
값을 가리킬 수 있는 것은 `color`, `background`, `tint`, `opacity`, `size`, `weight`, `cornerRadius`와
|
|
95
|
+
레이아웃의 `background`, `keyline`뿐입니다. 색은 이름이나 hex 색만 되고, 라이트·다크 쌍은 쓸 수 없습니다.
|
|
96
|
+
나머지는 시작한 그대로 남으니, 바꾸려면 활동을 끝내고 다시 시작하세요. 갱신마다 값을 전부 다시 보내고,
|
|
97
|
+
레이아웃·스타일·값을 합친 weight는 3584를 넘을 수 없습니다. Android는 스타일을 그리지 않습니다.
|
|
98
|
+
0.2.x 크레이트는 바인딩을 거부하므로 npm 패키지와 크레이트의 마이너 버전을 맞추세요.
|
|
99
|
+
[자세히](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#changing-styles)
|
|
100
|
+
|
|
72
101
|
## 레이아웃에 넣을 수 있는 것
|
|
73
102
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
103
|
+
레이아웃은 `text`/`bound`, `path`(SVG path 데이터), `vstack`·`hstack`·`zstack`·`spacer`·`divider`와
|
|
104
|
+
아래 여섯 가지로 만듭니다. 그림은 모두 iOS 잠금화면입니다. 예시의 빌더는 `layout`에서 꺼내 씁니다
|
|
105
|
+
(`const { vstack, hstack, text, bound, symbol, image, gauge, progress, timerText, button } = layout;`).
|
|
106
|
+
같은 레이아웃을 TSX로 쓸 수 있고, React 훅으로 컴포넌트와 액티비티를 함께 움직일 수도 있습니다
|
|
107
|
+
([TSX and React](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#tsx-and-react)).
|
|
108
|
+
|
|
109
|
+
### 심볼
|
|
110
|
+
|
|
111
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-symbols.png" width="400" alt="고양이, 여러 색 하트, 35% 채운 스피커">
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
hstack([
|
|
115
|
+
symbol('cat.fill'),
|
|
116
|
+
symbol('heart.fill', { rendering: 'multicolor' }),
|
|
117
|
+
symbol('speaker.wave.3.fill', { variableBind: 'purr' }), // purr: 0.35
|
|
118
|
+
])
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
SF Symbols입니다. `variableBind`는 0~1 값으로 가변 심볼을 채웁니다. iOS 전용입니다.
|
|
122
|
+
|
|
123
|
+
### 이미지
|
|
124
|
+
|
|
125
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-image.png" width="400" alt="위젯 에셋 카탈로그의 Mochi 사진">
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
hstack([image('mochi', { resizable: true, style: 'portrait' }), bound('title')])
|
|
129
|
+
// styles: { portrait: { frame: { width: 56, height: 56 } } }
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
위젯 확장의 에셋 카탈로그에 있는 그림입니다. iOS 전용입니다.
|
|
133
|
+
|
|
134
|
+
### 게이지
|
|
135
|
+
|
|
136
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-gauge.png" width="400" alt="100 중 80을 가리키는 원형·선형 게이지">
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
hstack([gauge('bowl', { max: 100, kind: 'circular' }), gauge('bowl', { max: 100 })]) // bowl: 80
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`min`~`max` 사이의 숫자를 원이나 막대로 보여 줍니다. iOS 전용입니다.
|
|
143
|
+
|
|
144
|
+
### 진행률
|
|
145
|
+
|
|
146
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-progress.png" width="400" alt="65%를 가리키는 원과 막대">
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
vstack([bound('title'), progress('done', { kind: 'circular' }), progress('done')]) // done: 0.65
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
0~1 사이의 숫자입니다. Android에서는 첫 번째 진행률이 알림의 막대가 됩니다.
|
|
153
|
+
|
|
154
|
+
### 타이머
|
|
155
|
+
|
|
156
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-timer.png" width="400" alt="Mochi 낮잠 아래 4:50에서 줄어드는 타이머">
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
vstack([bound('title'), timerText('start', 'end')]) // end: Date.now() + 5 * 60_000
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
시스템이 세는 타이머로, `end`까지 줄어들거나 `start`부터 늘어납니다(`countsDown: false`). Android에서는 알림의 크로노미터가 됩니다.
|
|
163
|
+
|
|
164
|
+
### 버튼
|
|
165
|
+
|
|
166
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-buttons-after.png" width="400" alt="한 번 쓰다듬은 뒤의 Pet Mochi·All done 버튼">
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
hstack([button('pet', text('Pet Mochi')), button('done', text('All done'))])
|
|
170
|
+
|
|
171
|
+
await onAction(async ({ actionId, activityId }) => {
|
|
172
|
+
if (actionId === 'done') await endLayout({ id: activityId, policy: { kind: 'immediate' } });
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
탭은 `onAction`으로, 앱이 열려 있지 않을 때는 Rust의 `on_action`으로 전달됩니다. iOS 17 이상이며, Android는 최대 세 개를 알림 버튼으로 보여 줍니다.
|
|
177
|
+
|
|
178
|
+
### Dynamic Island
|
|
83
179
|
|
|
84
180
|
<table>
|
|
85
|
-
<tr><th
|
|
181
|
+
<tr><th>컴팩트</th><th>미니멀</th><th>확장</th></tr>
|
|
86
182
|
<tr>
|
|
87
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-
|
|
88
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-
|
|
89
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-
|
|
90
|
-
</tr>
|
|
91
|
-
<tr><th>진행률</th><th>타이머</th><th>버튼</th></tr>
|
|
92
|
-
<tr>
|
|
93
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-progress.png" width="260" alt="65%의 링과 막대"></td>
|
|
94
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-timer.png" width="260" alt="Mochi 낮잠 아래 4:50에서 줄어드는 타이머"></td>
|
|
95
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-buttons-after.png" width="260" alt="한 번 쓰다듬은 뒤의 Pet Mochi, All done 버튼"></td>
|
|
183
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-compact.png" width="270" alt="컴팩트 Dynamic Island의 발바닥과 9 min"></td>
|
|
184
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-minimal.png" width="180" alt="미니멀 Dynamic Island의 진행률 링"></td>
|
|
185
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-expanded.png" width="265" alt="확장 Dynamic Island의 사진, 제목, 시간, 상태, 막대"></td>
|
|
96
186
|
</tr>
|
|
97
187
|
</table>
|
|
98
188
|
|
|
99
|
-
|
|
100
|
-
|
|
189
|
+
```ts
|
|
190
|
+
island: {
|
|
191
|
+
expanded: {
|
|
192
|
+
leading: image('mochi', { resizable: true, style: 'portrait' }),
|
|
193
|
+
center: bound('title'),
|
|
194
|
+
trailing: bound('eta'),
|
|
195
|
+
bottom: vstack([bound('status'), progress('done')]),
|
|
196
|
+
},
|
|
197
|
+
compactLeading: symbol('pawprint.fill'),
|
|
198
|
+
compactTrailing: bound('eta'),
|
|
199
|
+
minimal: progress('done', { kind: 'circular' }),
|
|
200
|
+
},
|
|
201
|
+
keyline: '#A3D9C2', // 아일랜드 테두리 색
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
레이아웃에서 `lockScreen` 옆에 `island`를 둡니다. 빠진 부분은 잠금화면 트리(확장)나 그 첫 심볼(컴팩트 왼쪽, 미니멀)을 보여 줍니다.
|
|
205
|
+
|
|
206
|
+
Android는 레이아웃을 알림으로 보여 줍니다. 첫 두 텍스트가 제목과 본문이 되고, 첫 진행률 막대와 타이머, 버튼 최대 세 개가 들어갑니다. 빠진 것은 `degradedFeatures`에 이름이 남습니다.
|
|
207
|
+
|
|
208
|
+
## 기본 부품 너머
|
|
209
|
+
|
|
210
|
+
대부분은 Swift 없이 바꿀 수 있습니다. 글꼴과 그림을 위젯 확장에 넣고 이름으로 부르면 됩니다.
|
|
211
|
+
|
|
212
|
+
```sh
|
|
213
|
+
npx tauri-plugin-live-activity setup --font fonts/Pacifico-Regular.ttf --asset art/paw@3x.png
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
styles: { title: { fontFamily: 'Pacifico-Regular', size: 22 } }, // 글꼴을 부르는 이름은 setup이 알려 줍니다
|
|
218
|
+
lockScreen: hstack([image('paw'), bound('title', { style: 'title' })]),
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
앱이 캔버스나 Rust로 직접 그린 그림은 App Group을 거칩니다(`setup --app-group`). PNG를 쓴 다음 시작하거나
|
|
222
|
+
갱신하면 위젯이 그 그림을 그립니다.
|
|
223
|
+
|
|
224
|
+
```ts
|
|
225
|
+
await writeImage('badge.png', png); // Rust: app.live_activity().write_image("badge.png", &png)
|
|
226
|
+
lockScreen: image({ file: 'badge.png' }, { resizable: true }),
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
직접 만든 뷰가 필요하면 `gen/apple/LiveActivityWidget/LiveActivityCustomViews.swift`에 SwiftUI로 쓰고 `custom`으로
|
|
230
|
+
놓습니다. 이 파일은 `setup`이 한 번 만들고 다시는 덮어쓰지 않습니다.
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
custom('ring', { props: { level: bind('done'), width: 4 } }),
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
```swift
|
|
237
|
+
"ring": ActivityKitCustomView { props in Ring(level: props.number("level") ?? 0) },
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
뷰가 없는 이름은 아무것도 그리지 않고 `degradedFeatures`에 `layout.custom.ring`으로 남습니다. 마지막 수단은
|
|
241
|
+
복사된 `LiveActivityWidget.swift`(activitykit의 위젯 템플릿)를 직접 고치는 것입니다. 그러면 `setup`은 그 파일을
|
|
242
|
+
그대로 두고, 템플릿이 바뀐 부분은 직접 합쳐야 합니다.
|
|
243
|
+
|
|
244
|
+
제한: Live Activity는 네트워크를 쓸 수 없고 메모리도 적습니다. 그린 PNG는 1 MiB, 1224 × 480 픽셀까지이고,
|
|
245
|
+
이는 Apple의 가장 큰 잠금화면 크기를 @3x로 잰 값입니다. 글꼴은 확장 안에 있어야 합니다. 기기에서는 App
|
|
246
|
+
Group을 Apple 계정에 한 번 등록해야 하는데, 자동 서명이 대신 해 줍니다. 검증기는 커스텀 뷰의 이름과 props만
|
|
247
|
+
보고 뷰 자체는 보지 않습니다. Android는 이 가운데 아무것도 그리지 않고, 처음 나오는 그린 그림만 알림의 큰
|
|
248
|
+
아이콘이 됩니다. 레이아웃, 스타일, 값은 여전히 3584를 나눠 씁니다.
|
|
249
|
+
[자세히](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#beyond-the-built-in-parts)
|
|
250
|
+
|
|
251
|
+
## 제약
|
|
252
|
+
|
|
253
|
+
- iOS: iOS 16.2 이상의 iPhone 또는 iPadOS 17 이상의 iPad가 필요하고, 버튼은 iOS 17부터 동작합니다. 활동은 앱이
|
|
254
|
+
포그라운드에 있을 때만 시작되고(아니면 `NOT_FOREGROUND`), 시스템이 8시간 뒤에 끝냅니다.
|
|
255
|
+
- iOS는 활동마다 마지막 값을 앱의 Application Support에 평문으로 남깁니다. 플러그인 설정에
|
|
256
|
+
`"receipts": "redacted"`를 주면 값 대신 다이제스트만 남깁니다.
|
|
257
|
+
- 버튼을 누르면 Rust의 `on_action` 핸들러가 끝날 때까지 최대 4초 기다립니다. JavaScript 리스너는 기다리지 않습니다.
|
|
258
|
+
- `app.live_activity()`의 Rust 메서드는 응답이 올 때까지 스레드를 멈추므로 메인 스레드가 아닌 곳에서 호출하세요. iOS에서
|
|
259
|
+
메인 스레드에서 호출하면 바로 `NATIVE_ERROR`를 돌려줍니다. JavaScript의 명령은 멈추지 않습니다.
|
|
260
|
+
- 푸시 갱신은 없습니다. Android는 진행 중 알림으로 보여 주고, 시스템이 허용하면 Live Update로 올립니다.
|
|
101
261
|
|
|
102
262
|
## Samsung Now Bar
|
|
103
263
|
|
package/README.md
CHANGED
|
@@ -23,8 +23,11 @@ an ongoing notification on Android. You describe the layout in TypeScript; the p
|
|
|
23
23
|
</table>
|
|
24
24
|
|
|
25
25
|
All four come from the [demo app](https://github.com/1eedaegon/tauri-plugin-live-activity/tree/main/examples/demo),
|
|
26
|
-
which follows a cat named Mochi. The plugin runs on iOS 16.
|
|
27
|
-
activity commands return `UNSUPPORTED_PLATFORM`.
|
|
26
|
+
which follows a cat named Mochi. The plugin runs on iOS 16.2+ and Android 8+; on desktop, its
|
|
27
|
+
activity commands return `UNSUPPORTED_PLATFORM`. On iOS it is built on the
|
|
28
|
+
[activitykit](https://github.com/1eedaegon/activitykit-rs) crate and has no Swift of its own. On Android every activity runs
|
|
29
|
+
its lifecycle in Rust, on the [liveupdate](https://github.com/1eedaegon/liveupdate-rs) crate, which draws templates
|
|
30
|
+
and layouts as Android's notification styles; the plugin's Kotlin only answers the permission commands. Before 1.0, a minor version may change the API.
|
|
28
31
|
|
|
29
32
|
## Install
|
|
30
33
|
|
|
@@ -43,9 +46,10 @@ Then add one line to the builder in `src-tauri/src/lib.rs`:
|
|
|
43
46
|
```
|
|
44
47
|
|
|
45
48
|
`setup` grants the plugin's permissions, raises the Android minimum to API 26 and, on a Mac,
|
|
46
|
-
adds the widget extension that draws the activity to the Xcode project
|
|
47
|
-
`tauri ios init`, and again if `src-tauri/gen/apple` is ever made from
|
|
48
|
-
|
|
49
|
+
adds the widget extension that draws the activity to the Xcode project, on activitykit's Swift
|
|
50
|
+
package. Run it after `tauri ios init`, and again if `src-tauri/gen/apple` is ever made from
|
|
51
|
+
scratch. On an app that 0.3 set up, run it again: it moves the widget and your custom views to
|
|
52
|
+
activitykit. `--dry-run` shows what it would change.
|
|
49
53
|
|
|
50
54
|
## Use
|
|
51
55
|
|
|
@@ -69,35 +73,190 @@ await endLayout({ id: snack.id, policy: { kind: 'immediate' } });
|
|
|
69
73
|
|
|
70
74
|
The layout stays as it started. Each update sends every value again, with a higher revision.
|
|
71
75
|
|
|
76
|
+
## Changing styles
|
|
77
|
+
|
|
78
|
+
The tree is fixed at start, but a few style members can name a value. An update then changes them:
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const { bind } = layout;
|
|
82
|
+
// styles: { status: { color: bind('tone'), weight: bind('weight') } }, values: { tone: 'green', weight: 'regular', … }
|
|
83
|
+
await updateLayout({ id, snapshot: { revision: 2, values: { ...values, tone: 'red', weight: 'bold' } } });
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
```rust
|
|
87
|
+
let status = Style { color: Some(Bound::key("tone").into()), ..Style::default() };
|
|
88
|
+
// Later: every value again, with the new color.
|
|
89
|
+
values.insert("tone".into(), Value::Text("red".into()));
|
|
90
|
+
app.live_activity().update_layout(LayoutUpdateInput { id, snapshot: LayoutSnapshot { revision: 2, values, stale_at: None, timestamp: None } })?;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Only `color`, `background`, `tint`, `opacity`, `size`, `weight`, `cornerRadius` and the layout's
|
|
94
|
+
`background` and `keyline` can be bound. A bound color is a name or a hex color, not a light and
|
|
95
|
+
dark pair. Everything else stays as started; end the activity and start it again to change it.
|
|
96
|
+
Each update sends all values again, and layout, styles and values share the weight limit of 3584.
|
|
97
|
+
Android draws no styles. A 0.2.x crate rejects bindings, so keep the npm package and the crate on
|
|
98
|
+
the same minor version. [More](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#changing-styles)
|
|
99
|
+
|
|
72
100
|
## What a layout can hold
|
|
73
101
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
102
|
+
Layouts are built from `text`/`bound`, `path` (SVG path data) and `vstack`, `hstack`, `zstack`,
|
|
103
|
+
`spacer`, `divider`, plus the six below. Each picture is the iOS Lock Screen. The snippets take
|
|
104
|
+
the builders from `layout` (`const { vstack, hstack, text, bound, symbol, image, gauge, progress, timerText, button } = layout;`).
|
|
105
|
+
The same layouts can be written in TSX, and a React hook keeps an activity in step with a component
|
|
106
|
+
([TSX and React](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#tsx-and-react)).
|
|
107
|
+
|
|
108
|
+
### Symbols
|
|
109
|
+
|
|
110
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-symbols.png" width="400" alt="A cat, a multicolor heart and a speaker filled to 35%">
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
hstack([
|
|
114
|
+
symbol('cat.fill'),
|
|
115
|
+
symbol('heart.fill', { rendering: 'multicolor' }),
|
|
116
|
+
symbol('speaker.wave.3.fill', { variableBind: 'purr' }), // purr: 0.35
|
|
117
|
+
])
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
SF Symbols. `variableBind` fills a variable symbol from a value between 0 and 1. iOS only.
|
|
121
|
+
|
|
122
|
+
### Image
|
|
123
|
+
|
|
124
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-image.png" width="400" alt="Mochi's portrait from the widget's asset catalog">
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
hstack([image('mochi', { resizable: true, style: 'portrait' }), bound('title')])
|
|
128
|
+
// styles: { portrait: { frame: { width: 56, height: 56 } } }
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
A picture from the widget extension's asset catalog. iOS only.
|
|
132
|
+
|
|
133
|
+
### Gauge
|
|
134
|
+
|
|
135
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-gauge.png" width="400" alt="A circular and a linear gauge at 80 of 100">
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
hstack([gauge('bowl', { max: 100, kind: 'circular' }), gauge('bowl', { max: 100 })]) // bowl: 80
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
A number between `min` and `max` as a ring or a bar. iOS only.
|
|
142
|
+
|
|
143
|
+
### Progress
|
|
144
|
+
|
|
145
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-progress.png" width="400" alt="A ring and a bar at 65%">
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
vstack([bound('title'), progress('done', { kind: 'circular' }), progress('done')]) // done: 0.65
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
A number from 0 to 1. On Android the first one becomes the notification's bar.
|
|
152
|
+
|
|
153
|
+
### Timer
|
|
154
|
+
|
|
155
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-timer.png" width="400" alt="A countdown at 4:50 under Mochi's nap">
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
vstack([bound('title'), timerText('start', 'end')]) // end: Date.now() + 5 * 60_000
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
The system counts it, down to `end` or up from `start` (`countsDown: false`). On Android it is the notification's chronometer.
|
|
162
|
+
|
|
163
|
+
### Buttons
|
|
164
|
+
|
|
165
|
+
<img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-buttons-after.png" width="400" alt="Pet Mochi and All done buttons after one pet">
|
|
166
|
+
|
|
167
|
+
```ts
|
|
168
|
+
hstack([button('pet', text('Pet Mochi')), button('done', text('All done'))])
|
|
169
|
+
|
|
170
|
+
await onAction(async ({ actionId, activityId }) => {
|
|
171
|
+
if (actionId === 'done') await endLayout({ id: activityId, policy: { kind: 'immediate' } });
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
A tap reaches `onAction`, or `on_action` in Rust, which also runs when the app was not open. iOS 17+; Android shows up to three as notification actions.
|
|
176
|
+
|
|
177
|
+
### Dynamic Island
|
|
83
178
|
|
|
84
179
|
<table>
|
|
85
|
-
<tr><th>
|
|
180
|
+
<tr><th>Compact</th><th>Minimal</th><th>Expanded</th></tr>
|
|
86
181
|
<tr>
|
|
87
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-
|
|
88
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-
|
|
89
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-
|
|
90
|
-
</tr>
|
|
91
|
-
<tr><th>Progress</th><th>Timer</th><th>Buttons</th></tr>
|
|
92
|
-
<tr>
|
|
93
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-progress.png" width="260" alt="A ring and a bar at 65%"></td>
|
|
94
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-timer.png" width="260" alt="A countdown at 4:50 under Mochi's nap"></td>
|
|
95
|
-
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-layout-buttons-after.png" width="260" alt="Pet Mochi and All done buttons after one pet"></td>
|
|
182
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-compact.png" width="270" alt="A paw and 9 min in the compact Dynamic Island"></td>
|
|
183
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-minimal.png" width="180" alt="A progress ring in the minimal Dynamic Island"></td>
|
|
184
|
+
<td><img src="https://raw.githubusercontent.com/1eedaegon/tauri-plugin-live-activity/main/docs/images/ios-island-expanded.png" width="265" alt="Portrait, title, time, status and bar in the expanded Dynamic Island"></td>
|
|
96
185
|
</tr>
|
|
97
186
|
</table>
|
|
98
187
|
|
|
99
|
-
|
|
100
|
-
|
|
188
|
+
```ts
|
|
189
|
+
island: {
|
|
190
|
+
expanded: {
|
|
191
|
+
leading: image('mochi', { resizable: true, style: 'portrait' }),
|
|
192
|
+
center: bound('title'),
|
|
193
|
+
trailing: bound('eta'),
|
|
194
|
+
bottom: vstack([bound('status'), progress('done')]),
|
|
195
|
+
},
|
|
196
|
+
compactLeading: symbol('pawprint.fill'),
|
|
197
|
+
compactTrailing: bound('eta'),
|
|
198
|
+
minimal: progress('done', { kind: 'circular' }),
|
|
199
|
+
},
|
|
200
|
+
keyline: '#A3D9C2', // the island's edge color
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Put `island` next to `lockScreen` in the layout. A part you leave out shows the lock screen tree (expanded) or its first symbol (compact leading, minimal).
|
|
204
|
+
|
|
205
|
+
Android shows a layout as a notification: the first two texts as title and body, the first progress bar and timer, and up to three buttons. `degradedFeatures` names what it left out.
|
|
206
|
+
|
|
207
|
+
## Beyond the built-in parts
|
|
208
|
+
|
|
209
|
+
Most customizing needs no Swift. Bundle your fonts and pictures in the widget extension, and name them:
|
|
210
|
+
|
|
211
|
+
```sh
|
|
212
|
+
npx tauri-plugin-live-activity setup --font fonts/Pacifico-Regular.ttf --asset art/paw@3x.png
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
styles: { title: { fontFamily: 'Pacifico-Regular', size: 22 } }, // setup prints the names a font answers to
|
|
217
|
+
lockScreen: hstack([image('paw'), bound('title', { style: 'title' })]),
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Pictures the app draws, on a canvas or in Rust, go through an App Group (`setup --app-group`). Write the PNG,
|
|
221
|
+
then start or update, and the widget draws it:
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
await writeImage('badge.png', png); // Rust: app.live_activity().write_image("badge.png", &png)
|
|
225
|
+
lockScreen: image({ file: 'badge.png' }, { resizable: true }),
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
For a view of your own, write it in SwiftUI in `gen/apple/LiveActivityWidget/LiveActivityCustomViews.swift`, which
|
|
229
|
+
`setup` creates once and never overwrites, and place it with `custom`:
|
|
230
|
+
|
|
231
|
+
```ts
|
|
232
|
+
custom('ring', { props: { level: bind('done'), width: 4 } }),
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
```swift
|
|
236
|
+
"ring": ActivityKitCustomView { props in Ring(level: props.number("level") ?? 0) },
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
A name without a view draws nothing and is reported in `degradedFeatures` as `layout.custom.ring`. The last
|
|
240
|
+
resort is to edit the copied `LiveActivityWidget.swift`, activitykit's widget template; `setup` then keeps your copy,
|
|
241
|
+
and template updates are yours to merge.
|
|
242
|
+
|
|
243
|
+
Limits: a Live Activity has no network and little memory. A drawn PNG is at most 1 MiB and 1224 × 480 pixels,
|
|
244
|
+
Apple's largest Lock Screen presentation at @3x. Fonts must be in the extension. On a device the App Group is
|
|
245
|
+
registered with your Apple account once; automatic signing does that. The validators check a custom view's name
|
|
246
|
+
and props, not the view. Android draws none of these, except that the first drawn image becomes the
|
|
247
|
+
notification's large icon. Layout, styles and values still share 3584.
|
|
248
|
+
[More](https://github.com/1eedaegon/tauri-plugin-live-activity/blob/main/docs/usage.md#beyond-the-built-in-parts)
|
|
249
|
+
|
|
250
|
+
## Limits
|
|
251
|
+
|
|
252
|
+
- iOS: an iPhone with iOS 16.2 or an iPad with iPadOS 17; buttons need iOS 17. An activity starts only while the
|
|
253
|
+
app is in the foreground (`NOT_FOREGROUND` otherwise), and the system ends it after 8 hours.
|
|
254
|
+
- iOS keeps each activity's last values in plain text in the app's Application Support, unless the plugin
|
|
255
|
+
configuration sets `"receipts": "redacted"`.
|
|
256
|
+
- A button's tap waits for your Rust `on_action` handlers, at most 4 seconds; JavaScript listeners are not awaited.
|
|
257
|
+
- The Rust methods of `app.live_activity()` block until the answer: call them off the main thread. On iOS a call on
|
|
258
|
+
the main thread answers `NATIVE_ERROR` at once. The commands from JavaScript never block.
|
|
259
|
+
- No push updates. Android shows an ongoing notification, promoted to a Live Update where the system allows it.
|
|
101
260
|
|
|
102
261
|
## Samsung Now Bar
|
|
103
262
|
|