@use-voltra/android 2.3.2 → 2.4.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 (74) hide show
  1. package/build/commonjs/index.js +25 -0
  2. package/build/commonjs/index.js.map +1 -1
  3. package/build/commonjs/jsx/primitives.js +36 -0
  4. package/build/commonjs/jsx/primitives.js.map +1 -1
  5. package/build/commonjs/modifiers/createAndroidModifier.js +20 -0
  6. package/build/commonjs/modifiers/createAndroidModifier.js.map +1 -0
  7. package/build/commonjs/modifiers/index.js +188 -0
  8. package/build/commonjs/modifiers/index.js.map +1 -0
  9. package/build/commonjs/ongoing-notification/components.js +7 -1
  10. package/build/commonjs/ongoing-notification/components.js.map +1 -1
  11. package/build/commonjs/ongoing-notification/renderer.js +354 -18
  12. package/build/commonjs/ongoing-notification/renderer.js.map +1 -1
  13. package/build/commonjs/ongoing-notification/types.js +56 -0
  14. package/build/commonjs/ongoing-notification/types.js.map +1 -1
  15. package/build/commonjs/server.js.map +1 -1
  16. package/build/module/index.js +3 -1
  17. package/build/module/index.js.map +1 -1
  18. package/build/module/jsx/primitives.js +1 -0
  19. package/build/module/jsx/primitives.js.map +1 -1
  20. package/build/module/modifiers/createAndroidModifier.js +15 -0
  21. package/build/module/modifiers/createAndroidModifier.js.map +1 -0
  22. package/build/module/modifiers/index.js +169 -0
  23. package/build/module/modifiers/index.js.map +1 -0
  24. package/build/module/ongoing-notification/components.js +6 -0
  25. package/build/module/ongoing-notification/components.js.map +1 -1
  26. package/build/module/ongoing-notification/renderer.js +354 -18
  27. package/build/module/ongoing-notification/renderer.js.map +1 -1
  28. package/build/module/ongoing-notification/types.js +55 -1
  29. package/build/module/ongoing-notification/types.js.map +1 -1
  30. package/build/module/server.js.map +1 -1
  31. package/build/typescript/commonjs/index.d.ts +4 -3
  32. package/build/typescript/commonjs/index.d.ts.map +1 -1
  33. package/build/typescript/commonjs/jsx/baseProps.d.ts +8 -0
  34. package/build/typescript/commonjs/jsx/baseProps.d.ts.map +1 -1
  35. package/build/typescript/commonjs/jsx/primitives.d.ts +1 -0
  36. package/build/typescript/commonjs/jsx/primitives.d.ts.map +1 -1
  37. package/build/typescript/commonjs/modifiers/createAndroidModifier.d.ts +13 -0
  38. package/build/typescript/commonjs/modifiers/createAndroidModifier.d.ts.map +1 -0
  39. package/build/typescript/commonjs/modifiers/index.d.ts +171 -0
  40. package/build/typescript/commonjs/modifiers/index.d.ts.map +1 -0
  41. package/build/typescript/commonjs/ongoing-notification/components.d.ts +8 -2
  42. package/build/typescript/commonjs/ongoing-notification/components.d.ts.map +1 -1
  43. package/build/typescript/commonjs/ongoing-notification/renderer.d.ts.map +1 -1
  44. package/build/typescript/commonjs/ongoing-notification/types.d.ts +281 -3
  45. package/build/typescript/commonjs/ongoing-notification/types.d.ts.map +1 -1
  46. package/build/typescript/commonjs/server.d.ts +1 -1
  47. package/build/typescript/commonjs/server.d.ts.map +1 -1
  48. package/build/typescript/module/index.d.ts +4 -3
  49. package/build/typescript/module/index.d.ts.map +1 -1
  50. package/build/typescript/module/jsx/baseProps.d.ts +8 -0
  51. package/build/typescript/module/jsx/baseProps.d.ts.map +1 -1
  52. package/build/typescript/module/jsx/primitives.d.ts +1 -0
  53. package/build/typescript/module/jsx/primitives.d.ts.map +1 -1
  54. package/build/typescript/module/modifiers/createAndroidModifier.d.ts +13 -0
  55. package/build/typescript/module/modifiers/createAndroidModifier.d.ts.map +1 -0
  56. package/build/typescript/module/modifiers/index.d.ts +171 -0
  57. package/build/typescript/module/modifiers/index.d.ts.map +1 -0
  58. package/build/typescript/module/ongoing-notification/components.d.ts +8 -2
  59. package/build/typescript/module/ongoing-notification/components.d.ts.map +1 -1
  60. package/build/typescript/module/ongoing-notification/renderer.d.ts.map +1 -1
  61. package/build/typescript/module/ongoing-notification/types.d.ts +281 -3
  62. package/build/typescript/module/ongoing-notification/types.d.ts.map +1 -1
  63. package/build/typescript/module/server.d.ts +1 -1
  64. package/build/typescript/module/server.d.ts.map +1 -1
  65. package/package.json +2 -2
  66. package/src/index.ts +36 -2
  67. package/src/jsx/baseProps.tsx +8 -0
  68. package/src/jsx/primitives.ts +1 -0
  69. package/src/modifiers/createAndroidModifier.ts +21 -0
  70. package/src/modifiers/index.ts +166 -0
  71. package/src/ongoing-notification/components.tsx +22 -1
  72. package/src/ongoing-notification/renderer.ts +451 -18
  73. package/src/ongoing-notification/types.ts +298 -4
  74. package/src/server.ts +15 -0
package/src/index.ts CHANGED
@@ -64,28 +64,55 @@ export type {
64
64
  export type {
65
65
  AndroidOngoingNotificationActionPayload,
66
66
  AndroidOngoingNotificationActionProps,
67
+ AndroidOngoingNotificationBigPicturePayload,
68
+ AndroidOngoingNotificationBigPictureProps,
67
69
  AndroidOngoingNotificationBigTextPayload,
68
70
  AndroidOngoingNotificationBigTextProps,
69
71
  AndroidOngoingNotificationCapabilities,
72
+ AndroidOngoingNotificationCategory,
73
+ AndroidOngoingNotificationCheckPromotionResult,
74
+ AndroidOngoingNotificationChronometer,
70
75
  AndroidOngoingNotificationCommonDisplayProps,
71
76
  AndroidOngoingNotificationContent,
72
77
  AndroidOngoingNotificationFallbackBehavior,
78
+ AndroidOngoingNotificationInboxPayload,
79
+ AndroidOngoingNotificationInboxProps,
73
80
  AndroidOngoingNotificationInput,
81
+ AndroidOngoingNotificationMetricDescriptor,
82
+ AndroidOngoingNotificationMetricEntryPayload,
83
+ AndroidOngoingNotificationMetricPayload,
84
+ AndroidOngoingNotificationMetricProps,
85
+ AndroidOngoingNotificationMetricSemanticStyle,
86
+ AndroidOngoingNotificationMetricTimeFormat,
87
+ AndroidOngoingNotificationMetricValue,
88
+ AndroidOngoingNotificationMetricValuePayload,
74
89
  AndroidOngoingNotificationPayload,
90
+ AndroidOngoingNotificationPresentationOptions,
75
91
  AndroidOngoingNotificationProgressPayload,
76
92
  AndroidOngoingNotificationProgressPoint,
77
93
  AndroidOngoingNotificationProgressProps,
78
94
  AndroidOngoingNotificationProgressSegment,
95
+ AndroidOngoingNotificationPromotionInfo,
96
+ AndroidOngoingNotificationPromotionIssue,
97
+ AndroidOngoingNotificationPublicVersion,
79
98
  AndroidOngoingNotificationStartResult,
80
99
  AndroidOngoingNotificationStatus,
81
100
  AndroidOngoingNotificationStopResult,
101
+ AndroidOngoingNotificationStyleFallback,
82
102
  AndroidOngoingNotificationUpdateResult,
83
103
  AndroidOngoingNotificationUpsertResult,
104
+ AndroidOngoingNotificationVisibility,
105
+ CheckAndroidOngoingNotificationPromotionOptions,
84
106
  StartAndroidOngoingNotificationOptions,
85
107
  UpdateAndroidOngoingNotificationOptions,
108
+ UpsertAndroidOngoingNotificationOptions,
86
109
  UseAndroidOngoingNotificationOptions,
87
110
  UseAndroidOngoingNotificationResult,
88
111
  } from './ongoing-notification/types.js'
112
+ export {
113
+ ANDROID_ONGOING_NOTIFICATION_CATEGORIES,
114
+ ANDROID_ONGOING_NOTIFICATION_VISIBILITIES,
115
+ } from './ongoing-notification/types.js'
89
116
 
90
117
  // Component prop types
91
118
  export type { BoxProps } from './jsx/Box.js'
@@ -99,5 +126,12 @@ export type { LinearProgressIndicatorProps } from './jsx/LinearProgressIndicator
99
126
  export type { RowProps } from './jsx/Row.js'
100
127
  export type { SpacerProps } from './jsx/Spacer.js'
101
128
  export type { TextProps } from './jsx/Text.js'
102
- export { getFastRefreshHub, isAndroidEnv, isIosEnv, useUpdateOnHMR } from '@use-voltra/core'
103
- export type { FastRefreshHub, WidgetBuildEnvironment, WidgetEnvironment } from '@use-voltra/core'
129
+ export {
130
+ getFastRefreshHub,
131
+ isAndroidEnv,
132
+ isIosEnv,
133
+ pickLocalizedValue,
134
+ resolveLocale,
135
+ useUpdateOnHMR,
136
+ } from '@use-voltra/core'
137
+ export type { FastRefreshHub, LocaleEnvironment, WidgetBuildEnvironment, WidgetEnvironment } from '@use-voltra/core'
@@ -1,11 +1,19 @@
1
+ import type { NativeModifiersProp } from '@use-voltra/core'
1
2
  import { ReactNode } from 'react'
2
3
 
4
+ import type { AndroidModifier } from '../modifiers/createAndroidModifier.js'
3
5
  import type { VoltraAndroidStyleProp } from '../styles/types.js'
4
6
 
5
7
  export type VoltraAndroidBaseProps = {
6
8
  id?: string
7
9
  deepLinkUrl?: string
8
10
  style?: VoltraAndroidStyleProp
11
+ /**
12
+ * Jetpack Glance modifiers from `VoltraAndroid.modifiers`, applied after `style`. Glance
13
+ * ignores their order, except that repeated `padding` adds up. Falsy entries, such as
14
+ * `count && modifier` with `count = 0`, mean no modifier.
15
+ */
16
+ modifiers?: NativeModifiersProp<AndroidModifier>
9
17
  children?: ReactNode
10
18
  }
11
19
 
@@ -27,3 +27,4 @@ export * from './SquareIconButton.js'
27
27
  export * from './Switch.js'
28
28
  export * from './Text.js'
29
29
  export * from './TitleBar.js'
30
+ export * as modifiers from '../modifiers/index.js'
@@ -0,0 +1,21 @@
1
+ declare const ANDROID_MODIFIER_BRAND: unique symbol
2
+
3
+ /**
4
+ * A Jetpack Glance modifier descriptor produced by a `VoltraAndroid.modifiers` factory. The brand
5
+ * exists only in the type system, so an iOS modifier cannot be passed to a `VoltraAndroid`
6
+ * component.
7
+ */
8
+ export type AndroidModifier = {
9
+ readonly $type: string
10
+ readonly [ANDROID_MODIFIER_BRAND]: 'android'
11
+ }
12
+
13
+ export const createAndroidModifier = <Params extends Record<string, unknown>>(
14
+ type: string,
15
+ params?: Params
16
+ ): AndroidModifier & Readonly<Params> =>
17
+ // Omitted options stay out of the descriptor instead of appearing as `undefined` keys.
18
+ Object.freeze({
19
+ ...Object.fromEntries(Object.entries(params ?? {}).filter(([, value]) => value !== undefined)),
20
+ $type: type,
21
+ }) as unknown as AndroidModifier & Readonly<Params>
@@ -0,0 +1,166 @@
1
+ import type { AndroidColorValue, AndroidDynamicColorToken } from '../dynamic-colors.js'
2
+ import { createAndroidModifier } from './createAndroidModifier.js'
3
+
4
+ export type { AndroidModifier } from './createAndroidModifier.js'
5
+
6
+ export type PaddingValues = {
7
+ all?: number
8
+ horizontal?: number
9
+ vertical?: number
10
+ start?: number
11
+ top?: number
12
+ end?: number
13
+ bottom?: number
14
+ }
15
+
16
+ export type AbsolutePaddingValues = {
17
+ all?: number
18
+ horizontal?: number
19
+ vertical?: number
20
+ left?: number
21
+ top?: number
22
+ right?: number
23
+ bottom?: number
24
+ }
25
+
26
+ /**
27
+ * A static color string. Resolves to `never` for an `AndroidDynamicColors` token, so passing one
28
+ * where Glance needs a concrete color is a compile-time error.
29
+ */
30
+ export type StaticColor<Color extends string> = Color extends AndroidDynamicColorToken ? never : Color
31
+
32
+ export type DayNightColors<Day extends string = string, Night extends string = string> = {
33
+ /** Static color used in light mode. `AndroidDynamicColors` tokens are not accepted. */
34
+ day: StaticColor<Day>
35
+ /** Static color used in dark mode. `AndroidDynamicColors` tokens are not accepted. */
36
+ night: StaticColor<Night>
37
+ }
38
+
39
+ /** At least one of the two keys is required. */
40
+ export type SemanticsValues =
41
+ | {
42
+ /** Text read by accessibility services. */
43
+ contentDescription: string
44
+ /**
45
+ * Identifier for Glance's own test APIs. The widget on a device does not expose it, so UI
46
+ * tests cannot find it.
47
+ */
48
+ testTag?: string
49
+ }
50
+ | {
51
+ /** Text read by accessibility services. */
52
+ contentDescription?: string
53
+ /**
54
+ * Identifier for Glance's own test APIs. The widget on a device does not expose it, so UI
55
+ * tests cannot find it.
56
+ */
57
+ testTag: string
58
+ }
59
+
60
+ /**
61
+ * Adds padding in dp, mirrored in right-to-left layouts. The most specific edge wins (`start` over
62
+ * `horizontal` over `all`). Glance adds repeated padding together, including `style.padding`.
63
+ *
64
+ * @since Android 7.0
65
+ */
66
+ export const padding = (values: number | PaddingValues) => {
67
+ if (typeof values === 'number') {
68
+ return createAndroidModifier('padding', { all: values })
69
+ }
70
+ // Copy only the known edges so extra keys on a caller's object never reach the device.
71
+ const { all, horizontal, vertical, start, top, end, bottom } = values
72
+ return createAndroidModifier('padding', { all, horizontal, vertical, start, top, end, bottom })
73
+ }
74
+
75
+ /**
76
+ * Adds padding in dp that ignores the layout direction. Adds up with `padding` and `style.padding`.
77
+ *
78
+ * @since Android 7.0
79
+ */
80
+ export const absolutePadding = (values: number | AbsolutePaddingValues) => {
81
+ if (typeof values === 'number') {
82
+ return createAndroidModifier('absolutePadding', { all: values })
83
+ }
84
+ const { all, horizontal, vertical, left, top, right, bottom } = values
85
+ return createAndroidModifier('absolutePadding', { all, horizontal, vertical, left, top, right, bottom })
86
+ }
87
+
88
+ /**
89
+ * Sets a fixed width in dp.
90
+ *
91
+ * @since Android 7.0
92
+ */
93
+ export const width = (dp: number) => createAndroidModifier('width', { width: dp })
94
+
95
+ /**
96
+ * Sets a fixed height in dp.
97
+ *
98
+ * @since Android 7.0
99
+ */
100
+ export const height = (dp: number) => createAndroidModifier('height', { height: dp })
101
+
102
+ /**
103
+ * Sets a fixed size in dp. A single number sets both dimensions.
104
+ *
105
+ * @since Android 7.0
106
+ */
107
+ export const size = (value: number | { width: number; height: number }) =>
108
+ createAndroidModifier(
109
+ 'size',
110
+ typeof value === 'number' ? { width: value, height: value } : { width: value.width, height: value.height }
111
+ )
112
+
113
+ /** @since Android 7.0 */
114
+ export const fillMaxWidth = () => createAndroidModifier('fillMaxWidth')
115
+ /** @since Android 7.0 */
116
+ export const fillMaxHeight = () => createAndroidModifier('fillMaxHeight')
117
+ /** @since Android 7.0 */
118
+ export const fillMaxSize = () => createAndroidModifier('fillMaxSize')
119
+ /** @since Android 7.0 */
120
+ export const wrapContentWidth = () => createAndroidModifier('wrapContentWidth')
121
+ /** @since Android 7.0 */
122
+ export const wrapContentHeight = () => createAndroidModifier('wrapContentHeight')
123
+ /** @since Android 7.0 */
124
+ export const wrapContentSize = () => createAndroidModifier('wrapContentSize')
125
+
126
+ /**
127
+ * Fills the background with a color: a static color, an `AndroidDynamicColors` token, or a pair of
128
+ * static colors for light and dark mode.
129
+ *
130
+ * @since Android 7.0
131
+ */
132
+ export const background = <Day extends string, Night extends string>(
133
+ color: AndroidColorValue | DayNightColors<Day, Night>
134
+ ) => createAndroidModifier('background', typeof color === 'string' ? { color } : { day: color.day, night: color.night })
135
+
136
+ /**
137
+ * Rounds the corners in dp. Glance ignores it below Android 12 (API 31).
138
+ *
139
+ * @since Android 12
140
+ */
141
+ export const cornerRadius = (radius: number) => createAndroidModifier('cornerRadius', { radius })
142
+
143
+ /**
144
+ * Shows, hides (keeping its space), or removes the component from layout.
145
+ *
146
+ * @since Android 7.0
147
+ */
148
+ export const visibility = (value: 'visible' | 'invisible' | 'gone') =>
149
+ createAndroidModifier('visibility', { visibility: value })
150
+
151
+ /**
152
+ * Sets accessibility and test metadata.
153
+ *
154
+ * @since Android 7.0
155
+ */
156
+ export const semantics = (values: SemanticsValues) =>
157
+ createAndroidModifier('semantics', { contentDescription: values.contentDescription, testTag: values.testTag })
158
+
159
+ /**
160
+ * Marks the widget's background view so the launcher can animate it when the widget opens the app.
161
+ * Use it once per widget, on the outermost component. Only one component keeps it: the first that
162
+ * appears once in the widget, and none inside a widget with a `Scaffold`, which marks its own.
163
+ *
164
+ * @since Android 12
165
+ */
166
+ export const appWidgetBackground = () => createAndroidModifier('appWidgetBackground')
@@ -2,13 +2,16 @@ import type { ComponentType } from 'react'
2
2
 
3
3
  import type {
4
4
  AndroidOngoingNotificationActionProps,
5
+ AndroidOngoingNotificationBigPictureProps,
5
6
  AndroidOngoingNotificationBigTextProps,
7
+ AndroidOngoingNotificationInboxProps,
8
+ AndroidOngoingNotificationMetricProps,
6
9
  AndroidOngoingNotificationProgressProps,
7
10
  } from './types.js'
8
11
 
9
12
  export const ANDROID_ONGOING_NOTIFICATION_COMPONENT_TAG = Symbol.for('VOLTRA_ANDROID_ONGOING_NOTIFICATION_COMPONENT')
10
13
 
11
- type AndroidOngoingNotificationComponentKind = 'progress' | 'bigText' | 'action'
14
+ type AndroidOngoingNotificationComponentKind = 'progress' | 'bigText' | 'bigPicture' | 'inbox' | 'metric' | 'action'
12
15
 
13
16
  type AndroidOngoingNotificationComponent<TProps extends Record<string, unknown>> = ComponentType<TProps> & {
14
17
  displayName: string
@@ -37,6 +40,21 @@ export const BigText = createAndroidOngoingNotificationComponent<AndroidOngoingN
37
40
  'bigText'
38
41
  )
39
42
 
43
+ export const BigPicture = createAndroidOngoingNotificationComponent<AndroidOngoingNotificationBigPictureProps>(
44
+ 'AndroidOngoingNotification.BigPicture',
45
+ 'bigPicture'
46
+ )
47
+
48
+ export const Inbox = createAndroidOngoingNotificationComponent<AndroidOngoingNotificationInboxProps>(
49
+ 'AndroidOngoingNotification.Inbox',
50
+ 'inbox'
51
+ )
52
+
53
+ export const Metric = createAndroidOngoingNotificationComponent<AndroidOngoingNotificationMetricProps>(
54
+ 'AndroidOngoingNotification.Metric',
55
+ 'metric'
56
+ )
57
+
40
58
  export const Action = createAndroidOngoingNotificationComponent<AndroidOngoingNotificationActionProps>(
41
59
  'AndroidOngoingNotification.Action',
42
60
  'action'
@@ -45,5 +63,8 @@ export const Action = createAndroidOngoingNotificationComponent<AndroidOngoingNo
45
63
  export const AndroidOngoingNotification = {
46
64
  Progress,
47
65
  BigText,
66
+ BigPicture,
67
+ Inbox,
68
+ Metric,
48
69
  Action,
49
70
  } as const