Skip to content

Commit c28164d

Browse files
committed
refactor: widgets and live activities
1 parent de54753 commit c28164d

21 files changed

Lines changed: 352 additions & 295 deletions

src/__tests__/element-deduplication.node.test.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React from 'react'
22

3-
import { renderVoltraToJson } from '../renderer/renderer'
4-
import { Voltra } from '../server'
3+
import { renderLiveActivityToJson } from '../live-activity/renderer.js'
4+
import { Voltra } from '../server.js'
55

66
describe('Element Deduplication', () => {
77
it('should deduplicate the same element used multiple times', () => {
88
// Create a single element that we'll reuse
99
const sharedText = <Voltra.Text>Shared content</Voltra.Text>
1010

11-
const result = renderVoltraToJson({
11+
const result = renderLiveActivityToJson({
1212
lockScreen: (
1313
<Voltra.VStack>
1414
{sharedText}
@@ -31,7 +31,7 @@ describe('Element Deduplication', () => {
3131
})
3232

3333
it('should not deduplicate elements that appear only once', () => {
34-
const result = renderVoltraToJson({
34+
const result = renderLiveActivityToJson({
3535
lockScreen: (
3636
<Voltra.VStack>
3737
<Voltra.Text>First</Voltra.Text>
@@ -56,7 +56,7 @@ describe('Element Deduplication', () => {
5656
it('should deduplicate elements across different variants', () => {
5757
const sharedText = <Voltra.Text>Shared across variants</Voltra.Text>
5858

59-
const result = renderVoltraToJson({
59+
const result = renderLiveActivityToJson({
6060
lockScreen: sharedText,
6161
island: {
6262
minimal: sharedText,
@@ -82,7 +82,7 @@ describe('Element Deduplication', () => {
8282
</Voltra.VStack>
8383
)
8484

85-
const result = renderVoltraToJson({
85+
const result = renderLiveActivityToJson({
8686
lockScreen: (
8787
<Voltra.HStack>
8888
{sharedContainer}
@@ -102,7 +102,7 @@ describe('Element Deduplication', () => {
102102
it('should handle deeply nested duplicate elements', () => {
103103
const leaf = <Voltra.Text>Leaf</Voltra.Text>
104104

105-
const result = renderVoltraToJson({
105+
const result = renderLiveActivityToJson({
106106
lockScreen: (
107107
<Voltra.VStack>
108108
<Voltra.HStack>
@@ -123,7 +123,7 @@ describe('Element Deduplication', () => {
123123
it('should work with complex components', () => {
124124
const sharedImage = <Voltra.Symbol name="star.fill" />
125125

126-
const result = renderVoltraToJson({
126+
const result = renderLiveActivityToJson({
127127
lockScreen: (
128128
<Voltra.HStack>
129129
{sharedImage}
@@ -153,7 +153,7 @@ describe('Element Deduplication', () => {
153153
)
154154

155155
// Payload with deduplication
156-
const withDedup = renderVoltraToJson({
156+
const withDedup = renderLiveActivityToJson({
157157
lockScreen: (
158158
<Voltra.HStack>
159159
{sharedElement}
@@ -164,7 +164,7 @@ describe('Element Deduplication', () => {
164164
})
165165

166166
// Create equivalent payload without deduplication (different element instances)
167-
const withoutDedup = renderVoltraToJson({
167+
const withoutDedup = renderLiveActivityToJson({
168168
lockScreen: (
169169
<Voltra.HStack>
170170
<Voltra.VStack>
@@ -191,7 +191,7 @@ describe('Element Deduplication', () => {
191191
})
192192

193193
it('should preserve payload version', () => {
194-
const result = renderVoltraToJson({
194+
const result = renderLiveActivityToJson({
195195
lockScreen: <Voltra.Text>Hello</Voltra.Text>,
196196
})
197197

src/__tests__/payload-budget.node.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { randomBytes } from 'node:crypto'
22

33
import React from 'react'
44

5-
import { renderVoltraToString, Voltra } from '../server'
5+
import { renderLiveActivityToString, Voltra } from '../server.js'
66

77
/**
88
* Payload Budget Tests
@@ -30,7 +30,7 @@ describe('Payload budget validation', () => {
3030
),
3131
}
3232

33-
await expect(renderVoltraToString(variants)).rejects.toThrow(/exceeds safe budget/)
33+
await expect(renderLiveActivityToString(variants)).rejects.toThrow(/exceeds safe budget/)
3434
})
3535

3636
it('accepts payloads within budget', async () => {
@@ -43,6 +43,6 @@ describe('Payload budget validation', () => {
4343
),
4444
}
4545

46-
await expect(renderVoltraToString(variants)).resolves.toBeDefined()
46+
await expect(renderLiveActivityToString(variants)).resolves.toBeDefined()
4747
})
4848
})

src/__tests__/payload-size.node.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react'
22

3-
import { BasicLiveActivityUI } from '../../example/components/live-activities/BasicLiveActivityUI'
4-
import { MusicPlayerLiveActivityUI } from '../../example/components/live-activities/MusicPlayerLiveActivityUI'
5-
import { renderVoltraToString } from '../server'
3+
import { BasicLiveActivityUI } from '../../example/components/live-activities/BasicLiveActivityUI.js'
4+
import { MusicPlayerLiveActivityUI } from '../../example/components/live-activities/MusicPlayerLiveActivityUI.js'
5+
import { renderLiveActivityToString } from '../server.js'
66

77
/**
88
* Payload Size Regression Tests
@@ -14,8 +14,8 @@ import { renderVoltraToString } from '../server'
1414
* - Size increased? Investigate before updating - is the increase justified?
1515
*/
1616

17-
const getPayloadSize = async (variants: Parameters<typeof renderVoltraToString>[0]): Promise<number> => {
18-
const compressedPayload = await renderVoltraToString(variants)
17+
const getPayloadSize = async (variants: Parameters<typeof renderLiveActivityToString>[0]): Promise<number> => {
18+
const compressedPayload = await renderLiveActivityToString(variants)
1919
return compressedPayload.length
2020
}
2121

src/__tests__/renderVoltraToString.node.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { ElementType, Suspense } from 'react'
22

3-
import { renderVoltraVariantToJson } from '../renderer/renderer'
4-
import { Voltra } from '../server'
3+
import { renderVoltraVariantToJson } from '../renderer/renderer.js'
4+
import { Voltra } from '../server.js'
55

66
describe('renderVoltraVariantToJson', () => {
77
it('should render a simple text component', () => {

src/__tests__/stylesheet-deduplication.node.test.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22

3-
import { renderVoltraToJson } from '../renderer/renderer'
4-
import { Voltra } from '../server'
3+
import { renderLiveActivityToJson } from '../live-activity/renderer.js'
4+
import { Voltra } from '../server.js'
55

66
describe('Stylesheet Deduplication', () => {
77
describe('Basic Stylesheet Functionality', () => {
@@ -12,7 +12,7 @@ describe('Stylesheet Deduplication', () => {
1212
fontWeight: 'bold',
1313
} as const
1414

15-
const result = renderVoltraToJson({
15+
const result = renderLiveActivityToJson({
1616
lockScreen: (
1717
<Voltra.VStack>
1818
<Voltra.Text style={sharedStyle}>Text 1</Voltra.Text>
@@ -38,7 +38,7 @@ describe('Stylesheet Deduplication', () => {
3838
padding: 10,
3939
}
4040

41-
const result = renderVoltraToJson({
41+
const result = renderLiveActivityToJson({
4242
lockScreen: (
4343
<Voltra.VStack>
4444
<Voltra.Text style={sharedStyle}>Text 1</Voltra.Text>
@@ -64,7 +64,7 @@ describe('Stylesheet Deduplication', () => {
6464
const style2 = { color: '#00FF00', fontSize: 18 }
6565
const style3 = { color: '#0000FF', fontSize: 20 }
6666

67-
const result = renderVoltraToJson({
67+
const result = renderLiveActivityToJson({
6868
lockScreen: (
6969
<Voltra.VStack>
7070
<Voltra.Text style={style1}>Text 1</Voltra.Text>
@@ -87,7 +87,7 @@ describe('Stylesheet Deduplication', () => {
8787
it('should handle mixed styled and unstyled elements', () => {
8888
const sharedStyle = { fontSize: 14, color: '#333333' }
8989

90-
const result = renderVoltraToJson({
90+
const result = renderLiveActivityToJson({
9191
lockScreen: (
9292
<Voltra.VStack>
9393
<Voltra.Text>Unstyled Text</Voltra.Text>
@@ -123,7 +123,7 @@ describe('Stylesheet Deduplication', () => {
123123
shadowRadius: 4,
124124
}
125125

126-
const result = renderVoltraToJson({
126+
const result = renderLiveActivityToJson({
127127
lockScreen: <Voltra.Text style={complexStyle}>Complex Style</Voltra.Text>,
128128
})
129129

@@ -149,7 +149,7 @@ describe('Stylesheet Deduplication', () => {
149149
it('should share stylesheet between all variants', () => {
150150
const sharedStyle = { color: '#FF0000' }
151151

152-
const result = renderVoltraToJson({
152+
const result = renderLiveActivityToJson({
153153
lockScreen: <Voltra.Text style={sharedStyle}>LockScreen</Voltra.Text>,
154154
island: {
155155
expanded: {
@@ -177,7 +177,7 @@ describe('Stylesheet Deduplication', () => {
177177
const style1 = { color: '#FF0000', fontSize: 16 }
178178
const style2 = { color: '#00FF00', fontSize: 18 }
179179

180-
const result = renderVoltraToJson({
180+
const result = renderLiveActivityToJson({
181181
lockScreen: (
182182
<Voltra.VStack>
183183
<Voltra.Text style={style1}>Text 1</Voltra.Text>
@@ -212,7 +212,7 @@ describe('Stylesheet Deduplication', () => {
212212
const style2 = { color: '#00FF00' }
213213
const style3 = { color: '#0000FF' }
214214

215-
const result = renderVoltraToJson({
215+
const result = renderLiveActivityToJson({
216216
island: {
217217
expanded: {
218218
center: <Voltra.Text style={style1}>Center</Voltra.Text>,
@@ -260,7 +260,7 @@ describe('Stylesheet Deduplication', () => {
260260
</Voltra.VStack>
261261
)
262262

263-
const result = renderVoltraToJson({
263+
const result = renderLiveActivityToJson({
264264
lockScreen: componentWithRepeatedStyles,
265265
})
266266

@@ -281,7 +281,7 @@ describe('Stylesheet Deduplication', () => {
281281
})
282282

283283
it('should not create stylesheet when no styles are used', () => {
284-
const result = renderVoltraToJson({
284+
const result = renderLiveActivityToJson({
285285
lockScreen: (
286286
<Voltra.VStack>
287287
<Voltra.Text>Plain Text 1</Voltra.Text>
@@ -294,7 +294,7 @@ describe('Stylesheet Deduplication', () => {
294294
})
295295

296296
it('should handle empty stylesheet gracefully', () => {
297-
const result = renderVoltraToJson({
297+
const result = renderLiveActivityToJson({
298298
lockScreen: <Voltra.Text>No Style</Voltra.Text>,
299299
})
300300

@@ -307,7 +307,7 @@ describe('Stylesheet Deduplication', () => {
307307
const sharedStyle = { backgroundColor: '#FFFFFF', borderRadius: 8 }
308308
const contentStyle = { height: 8, borderRadius: 8 }
309309

310-
const result = renderVoltraToJson({
310+
const result = renderLiveActivityToJson({
311311
lockScreen: (
312312
<Voltra.Mask
313313
maskElement={
@@ -344,7 +344,7 @@ describe('Stylesheet Deduplication', () => {
344344
it('should deduplicate styles across main content and component props', () => {
345345
const sharedStyle = { backgroundColor: '#FF0000', borderRadius: 8 }
346346

347-
const result = renderVoltraToJson({
347+
const result = renderLiveActivityToJson({
348348
lockScreen: (
349349
<Voltra.Mask
350350
maskElement={
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react'
22

3-
import { Voltra } from '../index'
4-
import { renderVoltraToJson } from '../renderer'
3+
import { Voltra } from '../index.js'
4+
import { renderLiveActivityToJson } from '../live-activity/renderer.js'
55

6-
describe('renderVoltraToJson variants', () => {
6+
describe('renderLiveActivityToJson variants', () => {
77
it('renders all Dynamic Island regions', async () => {
8-
const result = await renderVoltraToJson({
8+
const result = await renderLiveActivityToJson({
99
lockScreen: <Voltra.Text>Lock</Voltra.Text>,
1010
island: {
1111
expanded: {

src/__tests__/verify-optimization.node.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from 'react'
22

3-
import { renderVoltraToJson } from '../renderer/renderer'
4-
import { Voltra } from '../server'
3+
import { renderLiveActivityToJson } from '../live-activity/renderer.js'
4+
import { Voltra } from '../server.js'
55

66
test('verifies empty p and c are omitted', () => {
7-
const result = renderVoltraToJson({
7+
const result = renderLiveActivityToJson({
88
lockScreen: (
99
<Voltra.VStack>
1010
<Voltra.Text>Hello</Voltra.Text>

src/client.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ export { VoltraView, type VoltraViewProps } from './components/VoltraView.js'
1313
export { VoltraWidgetPreview, type VoltraWidgetPreviewProps } from './components/VoltraWidgetPreview.js'
1414

1515
// Renderer API
16-
export type { VoltraVariants } from './renderer/index.js'
17-
export type { VoltraElementJson, VoltraJson, VoltraNodeJson, VoltraVariantsJson } from './types.js'
16+
export type { VoltraElementJson, VoltraNodeJson } from './types.js'
1817

1918
// Preload API
2019
export {
@@ -39,15 +38,15 @@ export {
3938
useLiveActivity,
4039
type UseLiveActivityOptions,
4140
type UseLiveActivityResult,
42-
} from './liveactivity-api.js'
41+
} from './live-activity/api.js'
42+
export type { DismissalPolicy, LiveActivityVariants } from './live-activity/types.js'
4343

4444
// Widget API
45+
export type { WidgetFamily, WidgetVariants } from './widgets/types.js'
4546
export {
4647
clearAllWidgets,
4748
clearWidget,
4849
reloadWidgets,
4950
updateWidget,
5051
type UpdateWidgetOptions,
51-
type WidgetFamily,
52-
type WidgetVariants,
53-
} from './widget-api.js'
52+
} from './widgets/widget-api.js'

src/components/VoltraWidgetPreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import { StyleProp, ViewStyle } from 'react-native'
33

4-
import { WidgetFamily } from '../widget-api.js'
4+
import { WidgetFamily } from '../widgets/types.js'
55
import { VoltraView, VoltraViewProps } from './VoltraView.js'
66

77
/**

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * as Voltra from './jsx/primitives.js'
2-
export type { VoltraVariants, WidgetFamily, WidgetVariants } from './renderer/index.js'
2+
export type { LiveActivityVariants } from './live-activity/types.js'
3+
export type { WidgetVariants } from './widgets/types.js'

0 commit comments

Comments
 (0)