one 2.13.9 → 2.14.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.
Files changed (66) hide show
  1. package/android/src/main/java/dev/onejs/one/OneKotlinHostView.kt +53 -14
  2. package/android/src/main/java/dev/onejs/one/OneNativeSourceKeyedState.kt +23 -0
  3. package/android/src/main/java/dev/onejs/one/OneNativeSourceViewDispatch.kt +16 -3
  4. package/dist/cjs/metro-config/getViteMetroPluginOptions.cjs +4 -10
  5. package/dist/cjs/metro-config/getViteMetroPluginOptions.native.cjs +4 -10
  6. package/dist/cjs/metro-config/getViteMetroPluginOptions.native.js +4 -10
  7. package/dist/cjs/metro-config/getViteMetroPluginOptions.native.js.map +1 -1
  8. package/dist/cjs/platform/native-source/view.native.cjs +4 -4
  9. package/dist/cjs/platform/native-source/view.native.js +4 -4
  10. package/dist/cjs/platform/native-source/view.native.js.map +1 -1
  11. package/dist/cjs/platform/native-source/wire.native.cjs +152 -49
  12. package/dist/cjs/platform/native-source/wire.native.js +152 -49
  13. package/dist/cjs/platform/native-source/wire.native.js.map +1 -1
  14. package/dist/cjs/platform/native-source/wireProps.native.cjs +138 -0
  15. package/dist/cjs/platform/native-source/wireProps.native.js +140 -0
  16. package/dist/cjs/platform/native-source/wireProps.native.js.map +1 -0
  17. package/dist/cjs/platform/swift/index.native.cjs +12 -8
  18. package/dist/cjs/platform/swift/index.native.js +12 -8
  19. package/dist/cjs/platform/swift/index.native.js.map +1 -1
  20. package/dist/cjs/router/useScreens.cjs +1 -1
  21. package/dist/cjs/router/useScreens.native.cjs +2 -1
  22. package/dist/cjs/router/useScreens.native.js +2 -1
  23. package/dist/cjs/router/useScreens.native.js.map +1 -1
  24. package/dist/esm/metro-config/getViteMetroPluginOptions.mjs +4 -10
  25. package/dist/esm/metro-config/getViteMetroPluginOptions.mjs.map +1 -1
  26. package/dist/esm/metro-config/getViteMetroPluginOptions.native.js +4 -10
  27. package/dist/esm/metro-config/getViteMetroPluginOptions.native.js.map +1 -1
  28. package/dist/esm/platform/native-source/view.native.js +5 -5
  29. package/dist/esm/platform/native-source/view.native.js.map +1 -1
  30. package/dist/esm/platform/native-source/wire.native.js +149 -49
  31. package/dist/esm/platform/native-source/wire.native.js.map +1 -1
  32. package/dist/esm/platform/native-source/wireProps.native.js +113 -0
  33. package/dist/esm/platform/native-source/wireProps.native.js.map +1 -0
  34. package/dist/esm/platform/swift/index.native.js +13 -9
  35. package/dist/esm/platform/swift/index.native.js.map +1 -1
  36. package/dist/esm/router/useScreens.mjs +1 -1
  37. package/dist/esm/router/useScreens.mjs.map +1 -1
  38. package/dist/esm/router/useScreens.native.js +2 -1
  39. package/dist/esm/router/useScreens.native.js.map +1 -1
  40. package/ios/Generated/OneNativeTabViewView.swift +2 -1
  41. package/ios/OneNativeComposition.swift +1 -0
  42. package/ios/OneNativeHostingController.swift +113 -0
  43. package/ios/OneSwiftHostComponentView.mm +28 -4
  44. package/ios/OneSwiftHostView.swift +63 -9
  45. package/ios/OneSwiftPackage.swift +6 -1
  46. package/package.json +13 -13
  47. package/src/metro-config/getViteMetroPluginOptions.integration.test.ts +33 -3
  48. package/src/metro-config/getViteMetroPluginOptions.ts +5 -11
  49. package/src/native/packedClosure.test.ts +59 -22
  50. package/src/platform/native-source/view.native.tsx +4 -5
  51. package/src/platform/native-source/wire.native.ts +108 -26
  52. package/src/platform/native-source/wireProps.native.test.ts +57 -0
  53. package/src/platform/native-source/wireProps.native.ts +124 -0
  54. package/src/platform/swift/index.native.tsx +9 -7
  55. package/src/platform/swift/types.ts +4 -2
  56. package/src/router/useScreens.tsx +1 -1
  57. package/types/metro-config/getViteMetroPluginOptions.d.ts +1 -1
  58. package/types/metro-config/getViteMetroPluginOptions.d.ts.map +1 -1
  59. package/types/platform/native-source/view.native.d.ts.map +1 -1
  60. package/types/platform/native-source/wire.native.d.ts +3 -0
  61. package/types/platform/native-source/wire.native.d.ts.map +1 -1
  62. package/types/platform/native-source/wireProps.native.d.ts +15 -0
  63. package/types/platform/native-source/wireProps.native.d.ts.map +1 -0
  64. package/types/platform/swift/index.native.d.ts.map +1 -1
  65. package/types/platform/swift/types.d.ts +4 -1
  66. package/types/platform/swift/types.d.ts.map +1 -1
@@ -69,28 +69,52 @@ function isRecord(value: unknown): value is Record<string, unknown> {
69
69
  return typeof value === 'object' && value !== null && !Array.isArray(value)
70
70
  }
71
71
 
72
- function encodeValue(
73
- value: unknown,
74
- wire: NativeSourceWire,
75
- structs: NativeSourceStructs,
76
- path: string
77
- ): unknown {
72
+ // the path to the value being encoded, kept as a stack so a large array costs
73
+ // no string per element; only an error turns it into text.
74
+ const trail: (string | number)[] = []
75
+
76
+ function trailText(): string {
77
+ let text = String(trail[0])
78
+ for (let i = 1; i < trail.length; i++) {
79
+ text += typeof trail[i] === 'number' ? `[${trail[i]}]` : `.${trail[i]}`
80
+ }
81
+ return text
82
+ }
83
+
84
+ // a struct with no wired fields is already json-shaped, so it passes through
85
+ const plainStructs = new WeakMap<object, boolean>()
86
+
87
+ function encodeValue(value: unknown, wire: NativeSourceWire, structs: NativeSourceStructs): unknown {
78
88
  switch (wire.kind) {
79
89
  case 'date':
80
- if (!(value instanceof Date)) throw new TypeError(`${path}: expected Date`)
90
+ if (!(value instanceof Date)) throw new TypeError(`${trailText()}: expected Date`)
81
91
  return value
82
92
  case 'data':
83
- if (!(value instanceof Uint8Array)) throw new TypeError(`${path}: expected Uint8Array`)
93
+ if (!(value instanceof Uint8Array)) throw new TypeError(`${trailText()}: expected Uint8Array`)
84
94
  return base64Encode(value)
85
95
  case 'enum':
86
96
  if (typeof value !== 'string' && typeof value !== 'number') {
87
- throw new TypeError(`${path}: expected an enum value`)
97
+ throw new TypeError(`${trailText()}: expected an enum value`)
88
98
  }
89
99
  return value
90
100
  case 'struct': {
91
- if (!isRecord(value)) throw new TypeError(`${path}: expected ${wire.name}`)
101
+ if (!isRecord(value)) throw new TypeError(`${trailText()}: expected ${wire.name}`)
92
102
  const table = structs[wire.name]
93
- if (!table) throw new TypeError(`${path}: unknown struct ${wire.name}`)
103
+ if (!table) throw new TypeError(`${trailText()}: unknown struct ${wire.name}`)
104
+ let plain = plainStructs.get(table)
105
+ if (plain === undefined) {
106
+ plain = table.fields.every((field) => field.wire === undefined)
107
+ plainStructs.set(table, plain)
108
+ }
109
+ if (plain) {
110
+ for (const field of table.fields) {
111
+ if (value[field.name] === undefined && !field.optional) {
112
+ trail.push(field.name)
113
+ throw new TypeError(`${trailText()}: required`)
114
+ }
115
+ }
116
+ return value
117
+ }
94
118
  const out: Record<string, unknown> = {}
95
119
  for (const key of Object.keys(value)) {
96
120
  if (!table.fields.some((field) => field.name === key)) out[key] = value[key]
@@ -98,31 +122,46 @@ function encodeValue(
98
122
  for (const field of table.fields) {
99
123
  const present = value[field.name] !== undefined
100
124
  if (!present) {
101
- if (!field.optional) throw new TypeError(`${path}.${field.name}: required`)
125
+ if (!field.optional) {
126
+ trail.push(field.name)
127
+ throw new TypeError(`${trailText()}: required`)
128
+ }
102
129
  continue
103
130
  }
104
- out[field.name] =
105
- field.wire === undefined
106
- ? value[field.name]
107
- : encodeValue(value[field.name], field.wire, structs, `${path}.${field.name}`)
131
+ if (field.wire === undefined) {
132
+ out[field.name] = value[field.name]
133
+ continue
134
+ }
135
+ trail.push(field.name)
136
+ out[field.name] = encodeValue(value[field.name], field.wire, structs)
137
+ trail.pop()
108
138
  }
109
139
  return out
110
140
  }
111
- case 'array':
112
- if (!Array.isArray(value)) throw new TypeError(`${path}: expected an array`)
113
- return value.map((item, index) => encodeValue(item, wire.element, structs, `${path}[${index}]`))
141
+ case 'array': {
142
+ if (!Array.isArray(value)) throw new TypeError(`${trailText()}: expected an array`)
143
+ const out = new Array(value.length)
144
+ trail.push(0)
145
+ const at = trail.length - 1
146
+ for (let index = 0; index < value.length; index++) {
147
+ trail[at] = index
148
+ out[index] = encodeValue(value[index], wire.element, structs)
149
+ }
150
+ trail.pop()
151
+ return out
152
+ }
114
153
  case 'map': {
115
- if (!isRecord(value)) throw new TypeError(`${path}: expected an object`)
154
+ if (!isRecord(value)) throw new TypeError(`${trailText()}: expected an object`)
116
155
  const out: Record<string, unknown> = {}
117
156
  for (const key of Object.keys(value)) {
118
- out[key] = encodeValue(value[key], wire.value, structs, `${path}.${key}`)
157
+ trail.push(key)
158
+ out[key] = encodeValue(value[key], wire.value, structs)
159
+ trail.pop()
119
160
  }
120
161
  return out
121
162
  }
122
163
  case 'nullable':
123
- return value === null || value === undefined
124
- ? null
125
- : encodeValue(value, wire.inner, structs, path)
164
+ return value === null || value === undefined ? null : encodeValue(value, wire.inner, structs)
126
165
  }
127
166
  }
128
167
 
@@ -195,6 +234,17 @@ function decodeValue(
195
234
  }
196
235
  }
197
236
 
237
+ function encodeAt(
238
+ path: (string | number)[],
239
+ value: unknown,
240
+ wire: NativeSourceWire,
241
+ structs: NativeSourceStructs
242
+ ): unknown {
243
+ trail.length = 0
244
+ trail.push(...path)
245
+ return encodeValue(value, wire, structs)
246
+ }
247
+
198
248
  export function encodeNativeSourceArgs(
199
249
  args: unknown[],
200
250
  wires: (NativeSourceWire | null | undefined)[],
@@ -204,7 +254,7 @@ export function encodeNativeSourceArgs(
204
254
  const wire = wires[index]
205
255
  return wire === undefined || wire === null
206
256
  ? arg
207
- : encodeValue(arg, wire, structs, `args[${index}]`)
257
+ : encodeAt(['args', index], arg, wire, structs)
208
258
  })
209
259
  }
210
260
 
@@ -224,11 +274,43 @@ export function encodeNativeSourceProps(
224
274
  const out: Record<string, unknown> = { ...props }
225
275
  for (const name of Object.keys(wires)) {
226
276
  if (out[name] === undefined) continue
227
- out[name] = encodeValue(out[name], wires[name], structs, `props.${name}`)
277
+ out[name] = encodeAt(['props', name], out[name], wires[name], structs)
228
278
  }
229
279
  return out
230
280
  }
231
281
 
282
+ export function encodeNativeSourceProp(
283
+ name: string,
284
+ value: unknown,
285
+ wires: NativeSourceViewWires | undefined
286
+ ): unknown {
287
+ const wire = wires?.props[name]
288
+ return wire === undefined ? value : encodeAt(['props', name], value, wire, wires!.structs)
289
+ }
290
+
291
+ export function encodeNativeSourceListItem(
292
+ name: string,
293
+ index: number,
294
+ item: unknown,
295
+ element: NativeSourceWire,
296
+ structs: NativeSourceStructs
297
+ ): unknown {
298
+ return encodeAt(['props', name, index], item, element, structs)
299
+ }
300
+
301
+ // a view's props as the json text its native host decodes: wired values
302
+ // encoded, and true for each callback the element passed
303
+ export function stringifyNativeSourceProps(
304
+ props: Record<string, unknown>,
305
+ wires: NativeSourceViewWires | undefined
306
+ ): string {
307
+ const out = wires ? encodeNativeSourceProps(props, wires.props, wires.structs) : { ...props }
308
+ for (const key of Object.keys(out)) {
309
+ if (typeof out[key] === 'function') out[key] = true
310
+ }
311
+ return JSON.stringify(out)
312
+ }
313
+
232
314
  export function decodeNativeSourceCallback(
233
315
  args: unknown[],
234
316
  wires: (NativeSourceWire | null | undefined)[],
@@ -0,0 +1,57 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { nextDocument } from './wireProps.native'
3
+
4
+ const rows = (n: number) => Array.from({ length: n }, (_, i) => ({ id: i }))
5
+
6
+ describe('nextDocument', () => {
7
+ it('sends every prop first, with a seq', () => {
8
+ const doc = nextDocument({ title: 'a', rows: rows(3), onTap: () => {} }, undefined, null, false)!
9
+ expect(JSON.parse(doc.text)).toEqual({ $seq: 1, title: 'a', rows: [{ id: 0 }, { id: 1 }, { id: 2 }], onTap: true })
10
+ })
11
+
12
+ it('sends only changed props, based on the last seq', () => {
13
+ const first = nextDocument({ title: 'a', count: 1 }, undefined, null, false)!
14
+ expect(nextDocument({ title: 'a', count: 1 }, undefined, first, false)).toBeNull()
15
+ const second = nextDocument({ title: 'b', count: 1 }, undefined, first, false)!
16
+ expect(JSON.parse(second.text)).toEqual({ $seq: 2, $base: 1, title: 'b' })
17
+ })
18
+
19
+ it('sends null for a removed prop', () => {
20
+ const first = nextDocument({ title: 'a', count: 1 }, undefined, null, false)!
21
+ const second = nextDocument({ title: 'a' }, undefined, first, false)!
22
+ expect(JSON.parse(second.text)).toEqual({ $seq: 2, $base: 1, count: null })
23
+ })
24
+
25
+ it('sends a long array as indexed changes by element identity', () => {
26
+ const list = rows(100)
27
+ const first = nextDocument({ rows: list }, undefined, null, false)!
28
+ const next = list.slice()
29
+ next[5] = { id: 500 }
30
+ next.push({ id: 100 })
31
+ const second = nextDocument({ rows: next }, undefined, first, false)!
32
+ expect(JSON.parse(second.text)).toEqual({
33
+ $seq: 2,
34
+ $base: 1,
35
+ $lists: { rows: { length: 101, set: [[5, { id: 500 }], [100, { id: 100 }]] } },
36
+ })
37
+ })
38
+
39
+ it('sends a shrunk array as a length', () => {
40
+ const list = rows(100)
41
+ const first = nextDocument({ rows: list }, undefined, null, false)!
42
+ const second = nextDocument({ rows: list.slice(0, 90) }, undefined, first, false)!
43
+ expect(JSON.parse(second.text).$lists).toEqual({ rows: { length: 90, set: [] } })
44
+ })
45
+
46
+ it('sends the whole array when half of it changed', () => {
47
+ const first = nextDocument({ rows: rows(100) }, undefined, null, false)!
48
+ const second = nextDocument({ rows: rows(100) }, undefined, first, false)!
49
+ expect(JSON.parse(second.text).rows).toHaveLength(100)
50
+ })
51
+
52
+ it('sends everything again when asked', () => {
53
+ const first = nextDocument({ title: 'a' }, undefined, null, false)!
54
+ const second = nextDocument({ title: 'a' }, undefined, first, true)!
55
+ expect(JSON.parse(second.text)).toEqual({ $seq: 2, title: 'a' })
56
+ })
57
+ })
@@ -0,0 +1,124 @@
1
+ // the props string of a typed native view host, as keyed changes. the first
2
+ // document of a host instance carries every prop. a later one carries the props
3
+ // that changed, and for a long array prop only the elements whose identity
4
+ // changed. the host holds the decoded props and the `$seq` of the last
5
+ // document it applied; a change whose `$base` is not that seq cannot be applied,
6
+ // so the host answers `$resync` and the next render sends everything again.
7
+ //
8
+ // full: {"$seq":N, ...props}
9
+ // change: {"$seq":N, "$base":M, ...changed props, "$lists":{"rows":{"length":L,"set":[[i,element],...]}}}
10
+ //
11
+ // a changed prop replaces the held value whole, an absent prop keeps it, and a
12
+ // prop removed from the element is sent as null. `$lists` resizes the held array
13
+ // to `length` and replaces the `set` indices; an index past the held length
14
+ // appends and must arrive in order.
15
+ import { useLayoutEffect, useRef, useState } from 'react'
16
+ import {
17
+ encodeNativeSourceListItem,
18
+ encodeNativeSourceProp,
19
+ stringifyNativeSourceProps,
20
+ type NativeSourceViewWires,
21
+ type NativeSourceWire,
22
+ } from './wire.native'
23
+
24
+ // shorter arrays are cheaper to send whole than to diff
25
+ const MIN_LIST = 32
26
+
27
+ export const RESYNC_EVENT = '$resync'
28
+
29
+ interface Sent {
30
+ seq: number
31
+ text: string
32
+ // the arrays last sent, by identity, to diff the next one against
33
+ lists: Record<string, unknown[]>
34
+ // the json of every other prop, to send only what changed
35
+ texts: Record<string, string>
36
+ }
37
+
38
+ // the element wire of an array prop (undefined when elements are plain json),
39
+ // or null when the prop is not an array on the wire
40
+ function listElement(wire: NativeSourceWire | undefined): NativeSourceWire | undefined | null {
41
+ if (wire === undefined) return undefined
42
+ if (wire.kind === 'array') return wire.element
43
+ if (wire.kind === 'nullable') return listElement(wire.inner)
44
+ return null
45
+ }
46
+
47
+ export function nextDocument(
48
+ props: Record<string, unknown>,
49
+ wires: NativeSourceViewWires | undefined,
50
+ prev: Sent | null,
51
+ full: boolean
52
+ ): Sent | null {
53
+ const whole = full || prev === null
54
+ const seq = (prev?.seq ?? 0) + 1
55
+ const lists: Record<string, unknown[]> = {}
56
+ const texts: Record<string, string> = {}
57
+ const entries: string[] = []
58
+ const patches: Record<string, { length: number; set: [number, unknown][] }> = {}
59
+ for (const name of Object.keys(props)) {
60
+ const value = props[name]
61
+ if (value === undefined) continue
62
+ const element = listElement(wires?.props[name])
63
+ if (Array.isArray(value) && value.length >= MIN_LIST && element !== null) {
64
+ lists[name] = value
65
+ const before = prev?.lists[name]
66
+ if (!whole && before) {
67
+ const indices: number[] = []
68
+ for (let i = 0; i < value.length; i++) {
69
+ if (i >= before.length || before[i] !== value[i]) indices.push(i)
70
+ }
71
+ if (indices.length === 0 && before.length === value.length) continue
72
+ if (indices.length * 2 < value.length) {
73
+ patches[name] = {
74
+ length: value.length,
75
+ set: indices.map((i) => [
76
+ i,
77
+ element === undefined ? value[i] : encodeNativeSourceListItem(name, i, value[i], element, wires!.structs),
78
+ ]),
79
+ }
80
+ continue
81
+ }
82
+ }
83
+ entries.push(`${JSON.stringify(name)}:${JSON.stringify(encodeNativeSourceProp(name, value, wires))}`)
84
+ continue
85
+ }
86
+ const text = typeof value === 'function' ? 'true' : JSON.stringify(encodeNativeSourceProp(name, value, wires))
87
+ texts[name] = text
88
+ if (!whole && prev.texts[name] === text) continue
89
+ entries.push(`${JSON.stringify(name)}:${text}`)
90
+ }
91
+ if (!whole) {
92
+ for (const name of [...Object.keys(prev.texts), ...Object.keys(prev.lists)]) {
93
+ if (!(name in texts) && !(name in lists)) entries.push(`${JSON.stringify(name)}:null`)
94
+ }
95
+ if (entries.length === 0 && Object.keys(patches).length === 0) return null
96
+ if (Object.keys(patches).length > 0) entries.push(`"$lists":${JSON.stringify(patches)}`)
97
+ }
98
+ const head = whole ? `"$seq":${seq}` : `"$seq":${seq},"$base":${prev.seq}`
99
+ return { seq, text: `{${[head, ...entries].join(',')}}`, lists, texts }
100
+ }
101
+
102
+ export function useNativeSourceProps(
103
+ props: Record<string, unknown>,
104
+ wires: NativeSourceViewWires | undefined,
105
+ keyed: boolean
106
+ ): { text: string; resync: () => void } {
107
+ const sent = useRef<Sent | null>(null)
108
+ const needFull = useRef(false)
109
+ const [, rerender] = useState(0)
110
+ const next = keyed ? nextDocument(props, wires, sent.current, needFull.current) : null
111
+ // render stays pure: the document counts as sent once this render commits
112
+ useLayoutEffect(() => {
113
+ if (next) {
114
+ sent.current = next
115
+ needFull.current = false
116
+ }
117
+ })
118
+ const resync = () => {
119
+ needFull.current = true
120
+ rerender((n) => n + 1)
121
+ }
122
+ if (!keyed) return { text: stringifyNativeSourceProps(props, wires), resync }
123
+ return { text: (next ?? sent.current!).text, resync }
124
+ }
@@ -1,11 +1,12 @@
1
1
  // the component a device build answers a `.swift` import with: the swift
2
2
  // package compiled into the app, rendered by its registered view or by one of
3
3
  // its typed views.
4
+ import { StyleSheet } from 'react-native'
4
5
  import NativeSwiftHost from '../specs/OneSwiftHostNativeComponent'
5
6
  import {
6
7
  decodeNativeSourceCallback,
7
- encodeNativeSourceProps,
8
8
  } from '../native-source/wire.native'
9
+ import { RESYNC_EVENT, useNativeSourceProps } from '../native-source/wireProps.native'
9
10
  import type { SwiftPackageViewProps } from './types'
10
11
 
11
12
  export type { SwiftPackageViewProps } from './types'
@@ -18,18 +19,19 @@ export function SwiftPackageView({
18
19
  fill,
19
20
  wires,
20
21
  }: SwiftPackageViewProps) {
21
- const encoded = wires ? encodeNativeSourceProps(props, wires.props, wires.structs) : props
22
+ const keyed = useNativeSourceProps(props, wires, view !== '')
23
+ const style = StyleSheet.flatten(props.style)
24
+ const fills = fill || (style?.flex ?? 0) > 0 || (style?.flexGrow ?? 0) > 0
22
25
  return (
23
26
  <NativeSwiftHost
24
27
  packageName={packageName}
25
28
  view={view}
26
29
  contractHash={contractHash}
27
30
  // a typed view's host learns which callbacks the element passed
28
- props={JSON.stringify(encoded, (_key, value) =>
29
- typeof value === 'function' ? true : value
30
- )}
31
- fill={fill}
31
+ props={keyed.text}
32
+ fill={fills}
32
33
  onHostEvent={(event) => {
34
+ if (event.nativeEvent.name === RESYNC_EVENT) return keyed.resync()
33
35
  const callback = props[event.nativeEvent.name]
34
36
  if (typeof callback === 'function') {
35
37
  const args = JSON.parse(event.nativeEvent.args) as unknown[]
@@ -41,7 +43,7 @@ export function SwiftPackageView({
41
43
  )
42
44
  }
43
45
  }}
44
- style={fill ? { flex: 1 } : undefined}
46
+ style={fill ? { flex: 1 } : style}
45
47
  />
46
48
  )
47
49
  }
@@ -1,3 +1,4 @@
1
+ import type { StyleProp, ViewStyle } from 'react-native'
1
2
  import type { NativeSourceViewWires } from '../native-source/wire.native'
2
3
 
3
4
  export interface SwiftPackageViewProps {
@@ -9,8 +10,9 @@ export interface SwiftPackageViewProps {
9
10
  contractHash: string
10
11
  // the importing element's props: a typed view's stored properties, or the
11
12
  // json the @main view's view(props:) reads
12
- props: Record<string, unknown>
13
- // the imported file's @main is an App: the root fills its parent
13
+ props: Record<string, unknown> & { style?: StyleProp<ViewStyle> }
14
+ // the imported file's @main is an App: the root fills its parent. a typed
15
+ // view also fills when its element style sets flex or flexGrow
14
16
  fill: boolean
15
17
  // wire formats for props and callback arguments carrying Date, Data or
16
18
  // struct payloads; absent when every prop crosses as plain json
@@ -642,8 +642,8 @@ function routeToScreen(
642
642
  return (
643
643
  <Screen
644
644
  // Users can override the screen getId function.
645
- getId={createGetIdForRoute(route)}
646
645
  {...props}
646
+ getId={props.getId ?? createGetIdForRoute(route)}
647
647
  name={navigationRouteName}
648
648
  key={navigationRouteName}
649
649
  options={(args) => {
@@ -10,5 +10,5 @@ export declare function getViteMetroPluginOptions({ projectRoot, relativeRouterR
10
10
  ios?: string;
11
11
  android?: string;
12
12
  };
13
- }): Parameters<typeof metroPlugin>[0];
13
+ }): NonNullable<Parameters<typeof metroPlugin>[0]>;
14
14
  //# sourceMappingURL=getViteMetroPluginOptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getViteMetroPluginOptions.d.ts","sourceRoot":"","sources":["../../src/metro-config/getViteMetroPluginOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAK1D,wBAAgB,yBAAyB,CAAC,EACxC,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,OAAO,EACP,0BAA0B,EAC1B,SAAS,GACV,EAAE;IACD,WAAW,EAAE,MAAM,CAAA;IACnB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,iBAAiB,CAAC,EAAE,KAAK,CAAC,OAAO,MAAM,EAAE,CAAC,CAAA;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,0BAA0B,CAAC,EAAE,WAAW,CACtC,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAClC,CAAC,wBAAwB,CAAC,CAAA;IAC3B,SAAS,CAAC,EAAE,MAAM,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACzE,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CA0CpC"}
1
+ {"version":3,"file":"getViteMetroPluginOptions.d.ts","sourceRoot":"","sources":["../../src/metro-config/getViteMetroPluginOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAK1D,wBAAgB,yBAAyB,CAAC,EACxC,WAAW,EACX,kBAAkB,EAClB,iBAAiB,EACjB,OAAO,EACP,0BAA0B,EAC1B,SAAS,GACV,EAAE;IACD,WAAW,EAAE,MAAM,CAAA;IACnB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,iBAAiB,CAAC,EAAE,KAAK,CAAC,OAAO,MAAM,EAAE,CAAC,CAAA;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,0BAA0B,CAAC,EAAE,WAAW,CACtC,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAClC,CAAC,wBAAwB,CAAC,CAAA;IAC3B,SAAS,CAAC,EAAE,MAAM,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAA;CACzE,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAoCjD"}
@@ -1 +1 @@
1
- {"version":3,"file":"view.native.d.ts","sourceRoot":"","sources":["../../../src/platform/native-source/view.native.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAMxD,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD,wBAAgB,gBAAgB,CAAC,EAC/B,MAAM,EACN,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,KAAK,GACN,EAAE,qBAAqB,+BAoCvB"}
1
+ {"version":3,"file":"view.native.d.ts","sourceRoot":"","sources":["../../../src/platform/native-source/view.native.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAMxD,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAExD,wBAAgB,gBAAgB,CAAC,EAC/B,MAAM,EACN,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,KAAK,GACN,EAAE,qBAAqB,+BAmCvB"}
@@ -36,5 +36,8 @@ export declare function base64Decode(text: string): Uint8Array;
36
36
  export declare function encodeNativeSourceArgs(args: unknown[], wires: (NativeSourceWire | null | undefined)[], structs: NativeSourceStructs): unknown[];
37
37
  export declare function decodeNativeSourceResult(value: unknown, wire: NativeSourceWire | null | undefined, structs: NativeSourceStructs): unknown;
38
38
  export declare function encodeNativeSourceProps(props: Record<string, unknown>, wires: Record<string, NativeSourceWire>, structs: NativeSourceStructs): Record<string, unknown>;
39
+ export declare function encodeNativeSourceProp(name: string, value: unknown, wires: NativeSourceViewWires | undefined): unknown;
40
+ export declare function encodeNativeSourceListItem(name: string, index: number, item: unknown, element: NativeSourceWire, structs: NativeSourceStructs): unknown;
41
+ export declare function stringifyNativeSourceProps(props: Record<string, unknown>, wires: NativeSourceViewWires | undefined): string;
39
42
  export declare function decodeNativeSourceCallback(args: unknown[], wires: (NativeSourceWire | null | undefined)[], structs: NativeSourceStructs, event: string): unknown[];
40
43
  //# sourceMappingURL=wire.native.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wire.native.d.ts","sourceRoot":"","sources":["../../../src/platform/native-source/wire.native.ts"],"names":[],"m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ACb,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAET;AAID,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,KAAK,EAAE,qBAAqB,GAAG,SAAS,GACvC,MAAM,CAMR;AAED,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,OAAO,EAAE,EACf,KAAK,EAAE,CAAC,gBAAgB,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,EAC9C,OAAO,EAAE,mBAAmB,EAC5B,KAAK,EAAE,MAAM,GACZ,OAAO,EAAE,CAOX"}
@@ -0,0 +1,15 @@
1
+ import { type NativeSourceViewWires } from './wire.native';
2
+ export declare const RESYNC_EVENT = "$resync";
3
+ interface Sent {
4
+ seq: number;
5
+ text: string;
6
+ lists: Record<string, unknown[]>;
7
+ texts: Record<string, string>;
8
+ }
9
+ export declare function nextDocument(props: Record<string, unknown>, wires: NativeSourceViewWires | undefined, prev: Sent | null, full: boolean): Sent | null;
10
+ export declare function useNativeSourceProps(props: Record<string, unknown>, wires: NativeSourceViewWires | undefined, keyed: boolean): {
11
+ text: string;
12
+ resync: () => void;
13
+ };
14
+ export {};
15
+ //# sourceMappingURL=wireProps.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wireProps.native.d.ts","sourceRoot":"","sources":["../../../src/platform/native-source/wireProps.native.ts"],"names":[],"mappings":"AAeA,OAAO,EAIL,KAAK,qBAAqB,EAE3B,MAAM,eAAe,CAAA;AAKtB,eAAO,MAAM,YAAY,YAAY,CAAA;AAErC,UAAU,IAAI;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;IAEZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAA;IAEhC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC9B;AAWD,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,KAAK,EAAE,qBAAqB,GAAG,SAAS,EACxC,IAAI,EAAE,IAAI,GAAG,IAAI,EACjB,IAAI,EAAE,OAAO,GACZ,IAAI,GAAG,IAAI,CAgDb;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,KAAK,EAAE,qBAAqB,GAAG,SAAS,EACxC,KAAK,EAAE,OAAO,GACb;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAkBtC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../../../src/platform/swift/index.native.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,wBAAgB,gBAAgB,CAAC,EAC/B,WAAW,EACX,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,IAAI,EACJ,KAAK,GACN,EAAE,qBAAqB,+BA2BvB"}
1
+ {"version":3,"file":"index.native.d.ts","sourceRoot":"","sources":["../../../src/platform/swift/index.native.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,wBAAgB,gBAAgB,CAAC,EAC/B,WAAW,EACX,IAAI,EACJ,YAAY,EACZ,KAAK,EACL,IAAI,EACJ,KAAK,GACN,EAAE,qBAAqB,+BA4BvB"}
@@ -1,9 +1,12 @@
1
+ import type { StyleProp, ViewStyle } from 'react-native';
1
2
  import type { NativeSourceViewWires } from '../native-source/wire.native';
2
3
  export interface SwiftPackageViewProps {
3
4
  packageName: string;
4
5
  view: string;
5
6
  contractHash: string;
6
- props: Record<string, unknown>;
7
+ props: Record<string, unknown> & {
8
+ style?: StyleProp<ViewStyle>;
9
+ };
7
10
  fill: boolean;
8
11
  wires?: NativeSourceViewWires;
9
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/platform/swift/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AAEzE,MAAM,WAAW,qBAAqB;IAEpC,WAAW,EAAE,MAAM,CAAA;IAEnB,IAAI,EAAE,MAAM,CAAA;IAEZ,YAAY,EAAE,MAAM,CAAA;IAGpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAE9B,IAAI,EAAE,OAAO,CAAA;IAGb,KAAK,CAAC,EAAE,qBAAqB,CAAA;CAC9B"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/platform/swift/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAA;AAEzE,MAAM,WAAW,qBAAqB;IAEpC,WAAW,EAAE,MAAM,CAAA;IAEnB,IAAI,EAAE,MAAM,CAAA;IAEZ,YAAY,EAAE,MAAM,CAAA;IAGpB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;QAAE,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;KAAE,CAAA;IAGjE,IAAI,EAAE,OAAO,CAAA;IAGb,KAAK,CAAC,EAAE,qBAAqB,CAAA;CAC9B"}