@hzblj/kara-components 0.9.0 → 0.10.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 (142) hide show
  1. package/CHANGELOG.md +45 -28
  2. package/README.md +8 -8
  3. package/lib/module/atoms/color-picker/color-picker.android.js +32 -5
  4. package/lib/module/atoms/color-picker/color-picker.android.js.map +1 -1
  5. package/lib/module/atoms/icon-button/icon-button.ios.js +17 -4
  6. package/lib/module/atoms/icon-button/icon-button.ios.js.map +1 -1
  7. package/lib/module/atoms/pressable/pressable.js +45 -22
  8. package/lib/module/atoms/pressable/pressable.js.map +1 -1
  9. package/lib/typescript/atoms/activity-indicator/activity-indicator.types.d.ts +1 -1
  10. package/lib/typescript/atoms/avatar/avatar.types.d.ts +2 -2
  11. package/lib/typescript/atoms/badge/badge.types.d.ts +1 -1
  12. package/lib/typescript/atoms/blur-view/blur-view.types.d.ts +6 -6
  13. package/lib/typescript/atoms/button/button.types.d.ts +7 -7
  14. package/lib/typescript/atoms/card/card.types.d.ts +1 -1
  15. package/lib/typescript/atoms/checkbox/checkbox.types.d.ts +2 -2
  16. package/lib/typescript/atoms/chip/chip.types.d.ts +1 -1
  17. package/lib/typescript/atoms/color-picker/color-picker.types.d.ts +4 -3
  18. package/lib/typescript/atoms/date-picker/date-picker.types.d.ts +4 -4
  19. package/lib/typescript/atoms/divider/divider.types.d.ts +2 -2
  20. package/lib/typescript/atoms/fab/fab.types.d.ts +2 -2
  21. package/lib/typescript/atoms/glass-view/glass-view.types.d.ts +5 -5
  22. package/lib/typescript/atoms/h-stack/h-stack.types.d.ts +3 -3
  23. package/lib/typescript/atoms/icon/icon.types.d.ts +4 -4
  24. package/lib/typescript/atoms/icon-button/icon-button.types.d.ts +7 -3
  25. package/lib/typescript/atoms/island/island.types.d.ts +4 -4
  26. package/lib/typescript/atoms/list/list.types.d.ts +5 -5
  27. package/lib/typescript/atoms/picker/picker.types.d.ts +1 -1
  28. package/lib/typescript/atoms/pressable/pressable.types.d.ts +21 -5
  29. package/lib/typescript/atoms/progress/progress.types.d.ts +1 -1
  30. package/lib/typescript/atoms/rn-flat-list/rn-flat-list.types.d.ts +2 -2
  31. package/lib/typescript/atoms/rn-icon/rn-icon.types.d.ts +1 -1
  32. package/lib/typescript/atoms/rn-scroll-view/rn-scroll-view.types.d.ts +2 -2
  33. package/lib/typescript/atoms/rn-section-list/rn-section-list.types.d.ts +2 -2
  34. package/lib/typescript/atoms/rn-text/rn-text.types.d.ts +2 -2
  35. package/lib/typescript/atoms/rn-view/rn-view.types.d.ts +3 -3
  36. package/lib/typescript/atoms/scroll-view/scroll-view.types.d.ts +3 -3
  37. package/lib/typescript/atoms/segmented-control/segmented-control.types.d.ts +3 -3
  38. package/lib/typescript/atoms/skeleton/skeleton.types.d.ts +2 -2
  39. package/lib/typescript/atoms/spacer/spacer.types.d.ts +1 -1
  40. package/lib/typescript/atoms/surface/surface.types.d.ts +1 -1
  41. package/lib/typescript/atoms/switch/switch.types.d.ts +1 -1
  42. package/lib/typescript/atoms/text/text.types.d.ts +1 -1
  43. package/lib/typescript/atoms/text-field/text-field.types.d.ts +4 -4
  44. package/lib/typescript/atoms/v-stack/v-stack.types.d.ts +1 -1
  45. package/lib/typescript/atoms/z-stack/z-stack.types.d.ts +1 -1
  46. package/lib/typescript/glyph/glyph-button.types.d.ts +1 -1
  47. package/lib/typescript/glyph/glyph.types.d.ts +1 -1
  48. package/lib/typescript/molecules/collapsible/collapsible.types.d.ts +1 -1
  49. package/lib/typescript/molecules/empty-state/empty-state.types.d.ts +1 -1
  50. package/lib/typescript/molecules/label/label.types.d.ts +1 -1
  51. package/lib/typescript/molecules/labeled-content/labeled-content.types.d.ts +2 -2
  52. package/lib/typescript/molecules/list-item/list-item.types.d.ts +2 -2
  53. package/lib/typescript/molecules/navigation-bar/navigation-bar.types.d.ts +8 -8
  54. package/lib/typescript/molecules/pager/pager.types.d.ts +2 -2
  55. package/lib/typescript/molecules/radio-group/radio-group.types.d.ts +2 -2
  56. package/lib/typescript/molecules/rn-list-item/rn-list-item.types.d.ts +1 -1
  57. package/lib/typescript/molecules/rn-tooltip/rn-tooltip.types.d.ts +7 -7
  58. package/lib/typescript/molecules/scroll-edge-container/scroll-edge-container.types.d.ts +3 -3
  59. package/lib/typescript/molecules/search-bar/search-bar.types.d.ts +2 -2
  60. package/lib/typescript/molecules/stepper/stepper.types.d.ts +2 -2
  61. package/lib/typescript/molecules/tooltip/tooltip.types.d.ts +6 -6
  62. package/lib/typescript/organisms/action-sheet/action-sheet.types.d.ts +3 -3
  63. package/lib/typescript/organisms/alert/alert.types.d.ts +3 -3
  64. package/lib/typescript/organisms/context-menu/context-menu.types.d.ts +9 -9
  65. package/lib/typescript/organisms/fab-menu/fab-menu.types.d.ts +5 -5
  66. package/lib/typescript/organisms/form/form.types.d.ts +1 -1
  67. package/lib/typescript/organisms/menu/menu.types.d.ts +2 -2
  68. package/lib/typescript/organisms/sheet/sheet.types.d.ts +12 -12
  69. package/lib/typescript/organisms/snackbar/snackbar.types.d.ts +1 -1
  70. package/lib/typescript/organisms/swipe-actions/swipe-actions.types.d.ts +5 -5
  71. package/lib/typescript/templates/screen/screen.types.d.ts +2 -2
  72. package/package.json +4 -4
  73. package/src/atoms/activity-indicator/activity-indicator.types.ts +1 -1
  74. package/src/atoms/avatar/avatar.types.ts +2 -2
  75. package/src/atoms/badge/badge.types.ts +1 -1
  76. package/src/atoms/blur-view/blur-view.types.ts +6 -6
  77. package/src/atoms/button/button.types.ts +7 -7
  78. package/src/atoms/card/card.types.ts +1 -1
  79. package/src/atoms/checkbox/checkbox.types.ts +2 -2
  80. package/src/atoms/chip/chip.types.ts +1 -1
  81. package/src/atoms/color-picker/color-picker.android.tsx +26 -6
  82. package/src/atoms/color-picker/color-picker.types.ts +4 -3
  83. package/src/atoms/date-picker/date-picker.types.ts +4 -4
  84. package/src/atoms/divider/divider.types.ts +2 -2
  85. package/src/atoms/fab/fab.types.ts +2 -2
  86. package/src/atoms/glass-view/glass-view.types.ts +5 -5
  87. package/src/atoms/h-stack/h-stack.types.ts +3 -3
  88. package/src/atoms/icon/icon.types.ts +4 -4
  89. package/src/atoms/icon-button/icon-button.ios.tsx +12 -2
  90. package/src/atoms/icon-button/icon-button.types.ts +7 -3
  91. package/src/atoms/island/island.types.ts +4 -4
  92. package/src/atoms/list/list.types.ts +5 -5
  93. package/src/atoms/picker/picker.types.ts +1 -1
  94. package/src/atoms/pressable/pressable.tsx +39 -18
  95. package/src/atoms/pressable/pressable.types.ts +22 -5
  96. package/src/atoms/progress/progress.types.ts +1 -1
  97. package/src/atoms/rn-flat-list/rn-flat-list.types.ts +2 -2
  98. package/src/atoms/rn-icon/rn-icon.types.ts +1 -1
  99. package/src/atoms/rn-scroll-view/rn-scroll-view.types.ts +2 -2
  100. package/src/atoms/rn-section-list/rn-section-list.types.ts +2 -2
  101. package/src/atoms/rn-text/rn-text.types.ts +2 -2
  102. package/src/atoms/rn-view/rn-view.types.ts +3 -3
  103. package/src/atoms/scroll-view/scroll-view.types.ts +3 -3
  104. package/src/atoms/segmented-control/segmented-control.types.ts +3 -3
  105. package/src/atoms/skeleton/skeleton.types.ts +2 -2
  106. package/src/atoms/spacer/spacer.types.ts +1 -1
  107. package/src/atoms/surface/surface.types.ts +1 -1
  108. package/src/atoms/switch/switch.types.ts +1 -1
  109. package/src/atoms/text/text.types.ts +1 -1
  110. package/src/atoms/text-field/text-field.types.ts +4 -4
  111. package/src/atoms/v-stack/v-stack.types.ts +1 -1
  112. package/src/atoms/z-stack/z-stack.types.ts +1 -1
  113. package/src/glyph/glyph-button.types.ts +1 -1
  114. package/src/glyph/glyph.types.ts +1 -1
  115. package/src/molecules/collapsible/collapsible.types.ts +1 -1
  116. package/src/molecules/empty-state/empty-state.types.ts +1 -1
  117. package/src/molecules/label/label.types.ts +1 -1
  118. package/src/molecules/labeled-content/labeled-content.types.ts +2 -2
  119. package/src/molecules/list-item/list-item.types.ts +2 -2
  120. package/src/molecules/navigation-bar/navigation-bar.types.ts +8 -8
  121. package/src/molecules/pager/pager.types.ts +2 -2
  122. package/src/molecules/radio-group/radio-group.types.ts +2 -2
  123. package/src/molecules/rn-list-item/rn-list-item.types.ts +1 -1
  124. package/src/molecules/rn-tooltip/rn-tooltip.types.ts +7 -7
  125. package/src/molecules/scroll-edge-container/scroll-edge-container.types.ts +3 -3
  126. package/src/molecules/search-bar/search-bar.types.ts +2 -2
  127. package/src/molecules/stepper/stepper.types.ts +2 -2
  128. package/src/molecules/tooltip/tooltip.types.ts +6 -6
  129. package/src/organisms/action-sheet/action-sheet.types.ts +3 -3
  130. package/src/organisms/alert/alert.types.ts +3 -3
  131. package/src/organisms/context-menu/context-menu.types.ts +9 -9
  132. package/src/organisms/fab-menu/fab-menu.types.ts +5 -5
  133. package/src/organisms/form/form.types.ts +1 -1
  134. package/src/organisms/menu/menu.types.ts +2 -2
  135. package/src/organisms/sheet/sheet.types.ts +12 -12
  136. package/src/organisms/snackbar/snackbar.types.ts +1 -1
  137. package/src/organisms/swipe-actions/swipe-actions.types.ts +5 -5
  138. package/src/templates/screen/screen.types.ts +2 -2
  139. package/lib/module/platform-support.js +0 -19
  140. package/lib/module/platform-support.js.map +0 -1
  141. package/lib/typescript/platform-support.d.ts +0 -8
  142. package/src/platform-support.ts +0 -20
@@ -5,16 +5,16 @@ import type {ReactNode} from 'react'
5
5
  export type {BlurMaterial, BlurVibrancy} from '@hzblj/kara-native/swift-ui'
6
6
 
7
7
  /**
8
- * One of the system's materials behind React Native content — what sheets, bars, menus and HUDs are made of, in
8
+ * One of the system's materials (what sheets, bars, menus and HUDs are made of) behind React Native content, in
9
9
  * SwiftUI's five thicknesses. iOS: UIKit's `system*Material` blur, with optional vibrancy for the content. Android:
10
- * what lies behind, blurred and saturated (Android 12+), under a Material tonal surface as thick as the material —
11
- * `surface` at `ultraThin` up to `surfaceContainerHighest` at `ultraThick`; below Android 12 the surface alone. The
10
+ * what lies behind, blurred and saturated (Android 12+), under a Material tonal surface as thick as the material
11
+ * (`surface` at `ultraThin` up to `surfaceContainerHighest` at `ultraThick`); below Android 12 the surface alone. The
12
12
  * React Native tier: it needs no host, so it suits a list cell. Shape it with `borderRadius`; it clips its children.
13
13
  */
14
14
  export type BlurViewProps = ResponsiveViewSx & {
15
15
  /**
16
- * Pins the material to light or dark whatever the app's appearance — a dark HUD over a light screen. Unset, it follows
17
- * the app theme. Android draws the opposite appearance with Material's inverse surface.
16
+ * Pins the material to light or dark whatever the app's appearance (a dark HUD over a light screen). Unset, it
17
+ * follows the app theme. Android draws the opposite appearance with Material's inverse surface.
18
18
  */
19
19
  appearance?: 'dark' | 'light'
20
20
  /** React Native content, over the material. */
@@ -24,7 +24,7 @@ export type BlurViewProps = ResponsiveViewSx & {
24
24
  /** Test identifier, forwarded to the view. */
25
25
  testID?: string
26
26
  /**
27
- * iOS: draws the children vibrant at this level, the way iOS draws its own labels and fills on a material — their
27
+ * iOS: draws the children vibrant at this level, the way iOS draws its own labels and fills on a material. Their
28
28
  * colour becomes the material's vibrant one and their alpha the mask. Android has no vibrancy: the children keep
29
29
  * their colours there.
30
30
  */
@@ -4,7 +4,7 @@ import type {ReactNode} from 'react'
4
4
  export type ButtonVariant = 'accent' | 'destructive' | 'glass' | 'secondary'
5
5
 
6
6
  /**
7
- * SwiftUI `ButtonStyle`. iOS only — Compose has no equivalent, so Android ignores it and keeps
7
+ * SwiftUI `ButtonStyle`. iOS only: Compose has no equivalent, so Android ignores it and keeps
8
8
  * rendering the variant's tokens.
9
9
  */
10
10
  export type ButtonStyleName =
@@ -17,19 +17,19 @@ export type ButtonStyleName =
17
17
  | 'plain'
18
18
 
19
19
  /**
20
- * SwiftUI `ControlSize`. iOS only, and it has no `automatic` member — leave it unset to inherit
20
+ * SwiftUI `ControlSize`. iOS only, and it has no `automatic` member: leave it unset to inherit
21
21
  * whatever the surrounding SwiftUI environment provides.
22
22
  */
23
23
  export type ButtonControlSize = 'extraLarge' | 'large' | 'mini' | 'regular' | 'small'
24
24
 
25
- /** A text button — SwiftUI `Button` on iOS, Material's filled button (outlined for `glass`) on Android. */
25
+ /** A text button: SwiftUI `Button` on iOS, Material's filled button (outlined for `glass`) on Android. */
26
26
  export type ButtonProps = {
27
27
  /**
28
- * Replaces the style the variant picks — `borderedProminent` for `accent` and `destructive`, `bordered` for
29
- * `secondary`, `glass` for `glass`. iOS only — Android ignores it.
28
+ * Replaces the style the variant picks: `borderedProminent` for `accent` and `destructive`, `bordered` for
29
+ * `secondary`, `glass` for `glass`. iOS only. Android ignores it.
30
30
  */
31
31
  buttonStyle?: ButtonStyleName
32
- /** SwiftUI's control size. `large` by default. iOS only — Android ignores it. */
32
+ /** SwiftUI's control size. `large` by default. iOS only. Android ignores it. */
33
33
  controlSize?: ButtonControlSize
34
34
  /** Draws the button in its disabled colours and stops it responding to presses. */
35
35
  disabled?: boolean
@@ -42,7 +42,7 @@ export type ButtonProps = {
42
42
  /**
43
43
  * Overrides the variant's own tint. A prominent style takes it as the fill and picks a contrasting
44
44
  * label. `glass` has to reach the material through `glassEffect` instead, so tinting one costs it
45
- * the stock `.glass` style — see the iOS implementation.
45
+ * the stock `.glass` style (see the iOS implementation).
46
46
  */
47
47
  tint?: ColorToken
48
48
  /** The look. `accent` by default. Material has no glass, so on Android `glass` is an outlined button. */
@@ -2,7 +2,7 @@ import type {ResponsiveSx} from '@hzblj/kara-sx'
2
2
  import type {ReactNode} from 'react'
3
3
 
4
4
  /**
5
- * A raised container — SwiftUI `VStack` / Compose `Column` on `surface.primary`, with a large radius, `s16` padding and
5
+ * A raised container: SwiftUI `VStack` / Compose `Column` on `surface.primary`, with a large radius, `s16` padding and
6
6
  * the `card` shadow. Any `sx` prop overrides its default.
7
7
  */
8
8
  export type CardProps = ResponsiveSx & {
@@ -1,6 +1,6 @@
1
1
  import type {ReactNode} from 'react'
2
2
 
3
- /** Material's `Checkbox` on Android. iOS has none, so there it is a SwiftUI `Toggle` — the same switch as `Switch`. */
3
+ /** Material's `Checkbox` on Android. iOS has none, so there it is a SwiftUI `Toggle`, the same switch as `Switch`. */
4
4
  export type CheckboxProps = {
5
5
  /** Dims the control and ignores taps. */
6
6
  disabled?: boolean
@@ -8,7 +8,7 @@ export type CheckboxProps = {
8
8
  label?: string
9
9
  /** Called with the new value when the user toggles it. */
10
10
  onValueChange?: (value: boolean) => void
11
- /** Whether it is checked. Controlled — update it from `onValueChange`. */
11
+ /** Whether it is checked. Controlled: update it from `onValueChange`. */
12
12
  value: boolean
13
13
  }
14
14
 
@@ -1,6 +1,6 @@
1
1
  import type {ReactNode} from 'react'
2
2
 
3
- /** A filter pill on a `Pressable`, not a native control — the React Native tier, so it needs no host. */
3
+ /** A filter pill on a `Pressable`, not a native control. It belongs to the React Native tier, so it needs no host. */
4
4
  export type ChipProps = {
5
5
  /** The text in the pill. */
6
6
  label: string
@@ -1,9 +1,29 @@
1
- import {warnUnsupported} from '../../platform-support'
2
- import type {ColorPickerComponent} from './color-picker.types'
1
+ import {ColorWell} from '@hzblj/kara-native/jetpack-compose'
3
2
 
4
- /** Compose has no colour picker, and there is nothing sane to degrade a colour wheel into. */
5
- export const ColorPicker: ColorPickerComponent = () => {
6
- warnUnsupported('ColorPicker', 'Android')
3
+ import {useHostGuard} from '../../host-context'
4
+ import {HStack} from '../h-stack'
5
+ import {Spacer} from '../spacer'
6
+ import {Text} from '../text'
7
+ import type {ColorPickerComponent, ColorPickerProps} from './color-picker.types'
7
8
 
8
- return null
9
+ /**
10
+ * The row SwiftUI's `ColorPicker` lays out on iOS, the label leading and the well trailing, around kara's own Compose
11
+ * well: Compose ships no colour picker, so the sheet behind it draws the iOS picker's grid, spectrum and sliders.
12
+ */
13
+ export const ColorPicker: ColorPickerComponent = ({
14
+ label,
15
+ onValueChange,
16
+ supportsOpacity = false,
17
+ testID,
18
+ value,
19
+ }: ColorPickerProps) => {
20
+ useHostGuard('ColorPicker')
21
+
22
+ return (
23
+ <HStack align="center" spacing="s12" testID={testID} wide>
24
+ {label ? <Text>{label}</Text> : null}
25
+ <Spacer />
26
+ <ColorWell onValueChange={onValueChange} supportsOpacity={supportsOpacity} title={label} value={value} />
27
+ </HStack>
28
+ )
9
29
  }
@@ -1,11 +1,12 @@
1
1
  import type {ReactNode} from 'react'
2
2
 
3
3
  /**
4
- * The system colour picker. iOS only — Compose ships no equivalent, so on Android this
5
- * renders nothing and says so in dev. Branch on `Platform.OS` if the screen needs a fallback.
4
+ * A row with a label and a colour well that opens a picker: SwiftUI's `ColorPicker` on iOS. Compose ships none, so on
5
+ * Android it is kara's own, in the same shape: a well with a rainbow ring, and a sheet with a grid of swatches, a
6
+ * spectrum and RGB sliders.
6
7
  */
7
8
  export type ColorPickerProps = {
8
- /** Text beside the colour well. */
9
+ /** Text beside the colour well, and the Android sheet's title. */
9
10
  label?: string
10
11
  /** Called with the colour the user picks. */
11
12
  onValueChange?: (color: string) => void
@@ -3,7 +3,7 @@ import type {ReactNode} from 'react'
3
3
  export type DatePickerMode = 'date' | 'datetime' | 'time'
4
4
 
5
5
  /**
6
- * A date or time picker — SwiftUI's compact `DatePicker` on iOS, a field that opens Material's picker dialog on a tap
6
+ * A date or time picker: SwiftUI's compact `DatePicker` on iOS, a field that opens Material's picker dialog on a tap
7
7
  * on Android. The React Native tier: it brings its own host and sizes itself to the value, so it sits in a row beside
8
8
  * its label like a `Text`.
9
9
  */
@@ -17,11 +17,11 @@ export type DatePickerProps = {
17
17
  * `value`'s time of day.
18
18
  */
19
19
  mode?: DatePickerMode
20
- /** Called with the new date — on iOS as it changes, on Android when the dialog is confirmed. */
20
+ /** Called with the new date: on iOS as it changes, on Android when the dialog is confirmed. */
21
21
  onValueChange?: (date: Date) => void
22
- /** Test identifier — on the native picker on iOS, on the tappable field on Android. */
22
+ /** Test identifier, on the native picker on iOS and on the tappable field on Android. */
23
23
  testID?: string
24
- /** The selected date. Controlled — update it from `onValueChange`. */
24
+ /** The selected date. Controlled: update it from `onValueChange`. */
25
25
  value: Date
26
26
  }
27
27
 
@@ -1,11 +1,11 @@
1
1
  import type {ColorToken} from '@hzblj/kara-theme'
2
2
  import type {ReactNode} from 'react'
3
3
 
4
- /** A horizontal hairline — SwiftUI `Divider` / Compose `HorizontalDivider`. */
4
+ /** A horizontal hairline: SwiftUI `Divider` / Compose `HorizontalDivider`. */
5
5
  export type DividerProps = {
6
6
  /** The line's colour. `border.tertiary` by default. */
7
7
  color?: ColorToken
8
- /** Test identifier, forwarded to the native view on iOS — Android ignores it. */
8
+ /** Test identifier, forwarded to the native view on iOS. Android ignores it. */
9
9
  testID?: string
10
10
  }
11
11
 
@@ -3,7 +3,7 @@ import type {ReactNode} from 'react'
3
3
  import type {IconName} from '../icon'
4
4
 
5
5
  /**
6
- * A floating action button — Material's `FloatingActionButton` on Android, a 56pt accent circle (a plain SwiftUI
6
+ * A floating action button: Material's `FloatingActionButton` on Android, a 56pt accent circle (a plain SwiftUI
7
7
  * `Button`) on iOS. It renders inline; pinning it to a corner is up to the screen.
8
8
  */
9
9
  export type FabProps = {
@@ -11,7 +11,7 @@ export type FabProps = {
11
11
  name: IconName
12
12
  /** Called when the button is pressed. */
13
13
  onPress?: () => void
14
- /** Test identifier, forwarded to the native view on iOS — Android ignores it. */
14
+ /** Test identifier, forwarded to the native view on iOS. Android ignores it. */
15
15
  testID?: string
16
16
  }
17
17
 
@@ -3,13 +3,13 @@ import type {ColorToken} from '@hzblj/kara-theme'
3
3
  import type {ReactNode} from 'react'
4
4
 
5
5
  /**
6
- * Glass around a React Native subtree, shaped as a capsule — the React Native tier, so it needs no host. iOS 26:
7
- * Liquid Glass. Android: frosted glass — what lies behind, blurred on Android 12+, under a translucent tonal surface
8
- * (or `tint`) and a hairline. iOS before 26 has no Liquid Glass and draws a capsule of `tint` instead, or of the glass
9
- * buttons' translucent fill (`btn.bg.glass.base`) when there is none.
6
+ * Glass around a React Native subtree, shaped as a capsule. It belongs to the React Native tier, so it needs no host.
7
+ * iOS 26: Liquid Glass. Android: frosted glass, made of what lies behind, blurred on Android 12+, under a translucent
8
+ * tonal surface (or `tint`) and a hairline. iOS before 26 has no Liquid Glass and draws a capsule of `tint` instead, or
9
+ * of the glass buttons' translucent fill (`btn.bg.glass.base`) when there is none.
10
10
  *
11
11
  * On Android each glass re-records what lies behind it before every frame: a few buttons cost nothing, but keep it out
12
- * of the cells of a long list — a plain `tint` reads as well there.
12
+ * of the cells of a long list. A plain `tint` reads as well there.
13
13
  */
14
14
  export type GlassViewProps = ResponsiveViewSx & {
15
15
  /** React Native views. Give them `pointerEvents="none"` when `interactive`, so the press reaches the `Pressable`. */
@@ -4,13 +4,13 @@ import type {ReactNode} from 'react'
4
4
 
5
5
  export type HStackAlign = 'center' | 'end' | 'start'
6
6
 
7
- /** A horizontal stack — SwiftUI `HStack` / Compose `Row`. */
7
+ /** A horizontal stack: SwiftUI `HStack` / Compose `Row`. */
8
8
  export type HStackProps = ResponsiveSx & {
9
- /** How the children line up vertically — `start` is the top, `end` the bottom. `start` by default. */
9
+ /** How the children line up vertically: `start` is the top, `end` the bottom. `start` by default. */
10
10
  align?: HStackAlign
11
11
  /** Native views, laid out from the leading edge. */
12
12
  children?: ReactNode
13
- /** Makes the stack pressable — a tap gesture on iOS, a `clickable` with Material's ripple on Android. */
13
+ /** Makes the stack pressable: a tap gesture on iOS, a `clickable` with Material's ripple on Android. */
14
14
  onPress?: () => void
15
15
  /** The gap between children. Unset, SwiftUI puts its default spacing between them and Compose none. */
16
16
  spacing?: SpaceSize
@@ -13,13 +13,13 @@ declare global {
13
13
  type DeclaredIconName = keyof KaraIcons & string
14
14
 
15
15
  /**
16
- * One of the app's icons. Once the plugin has written `kara-icons.d.ts` only those names type-check — an icon removed
16
+ * One of the app's icons. Once the plugin has written `kara-icons.d.ts` only those names type-check: an icon removed
17
17
  * from the folder fails at every call site. Before that, any string, so a project can adopt icons gradually.
18
18
  */
19
19
  export type IconName = [DeclaredIconName] extends [never] ? string : DeclaredIconName
20
20
 
21
21
  /**
22
- * One of the app's icons, in a host — SwiftUI `Image` from the asset catalog on iOS, Material's `Icon` with the vector
22
+ * One of the app's icons, in a host: SwiftUI `Image` from the asset catalog on iOS, Material's `Icon` with the vector
23
23
  * drawable on Android. `RnIcon` draws the same asset outside one.
24
24
  */
25
25
  export type IconProps = {
@@ -27,11 +27,11 @@ export type IconProps = {
27
27
  accessibilityLabel?: string
28
28
  /** The icon's tint. `content.primary` by default. */
29
29
  color?: ColorToken
30
- /** Which of the app's icons — a key of `KaraIcons`. */
30
+ /** Which of the app's icons, a key of `KaraIcons`. */
31
31
  name: IconName
32
32
  /** Its width and height, a spacing token. `s24` by default. */
33
33
  size?: SpaceSize
34
- /** Test identifier, forwarded to the native view on iOS — Android ignores it. */
34
+ /** Test identifier, forwarded to the native view on iOS. Android ignores it. */
35
35
  testID?: string
36
36
  }
37
37
 
@@ -1,11 +1,18 @@
1
1
  import {Button} from '@expo/ui/swift-ui'
2
- import {buttonStyle, disabled as disabledModifier} from '@expo/ui/swift-ui/modifiers'
2
+ import {buttonStyle, contentShape, disabled as disabledModifier, shapes} from '@expo/ui/swift-ui/modifiers'
3
3
  import {useMemo} from 'react'
4
4
 
5
5
  import {useHostGuard} from '../../host-context'
6
6
  import {Icon} from '../icon'
7
+ import {ZStack} from '../z-stack'
7
8
  import type {IconButtonComponent, IconButtonProps} from './icon-button.types'
8
9
 
10
+ /** Apple's least tap target. Android's `IconButton` is Material's 48dp; this is the same idea in points. */
11
+ const TARGET = 44
12
+
13
+ /** The whole square takes the tap, not only the glyph's own pixels. */
14
+ const WHOLE_TARGET = {modifiers: [contentShape(shapes.circle())]}
15
+
9
16
  export const IconButton: IconButtonComponent = ({disabled = false, name, onPress, testID}: IconButtonProps) => {
10
17
  useHostGuard('IconButton')
11
18
 
@@ -21,7 +28,10 @@ export const IconButton: IconButtonComponent = ({disabled = false, name, onPress
21
28
 
22
29
  return (
23
30
  <Button modifiers={modifiers} onPress={onPress} testID={testID}>
24
- <Icon color={disabled ? 'btn.content.disabled' : 'content.primary'} name={name} />
31
+ <ZStack h={TARGET} ios={WHOLE_TARGET} w={TARGET}>
32
+ {/* SwiftUI dims a disabled button's label itself; a disabled colour on top of that dimmed it twice. */}
33
+ <Icon color="content.primary" name={name} />
34
+ </ZStack>
25
35
  </Button>
26
36
  )
27
37
  }
@@ -2,15 +2,19 @@ import type {ReactNode} from 'react'
2
2
 
3
3
  import type {IconName} from '../icon'
4
4
 
5
- /** A button that is just an icon — a plain SwiftUI `Button` on iOS, Material's `IconButton` on Android. */
5
+ /**
6
+ * A button that is just an icon: a plain SwiftUI `Button` on iOS, Material's `IconButton` on Android. The icon sits
7
+ * centred in a tap target the size each platform asks for, 44pt on iOS and 48dp on Android, so a row of them spaces
8
+ * itself the same way on both.
9
+ */
6
10
  export type IconButtonProps = {
7
- /** Draws the icon in `btn.content.disabled` and stops the button responding to presses. */
11
+ /** Dims the icon (iOS's own disabled look, `btn.content.disabled` on Android) and stops the button responding. */
8
12
  disabled?: boolean
9
13
  /** The icon, one of the app's. */
10
14
  name: IconName
11
15
  /** Called when the button is pressed. */
12
16
  onPress?: () => void
13
- /** Test identifier, forwarded to the native view on iOS — Android ignores it. */
17
+ /** Test identifier, forwarded to the native view on iOS. Android ignores it. */
14
18
  testID?: string
15
19
  }
16
20
 
@@ -3,7 +3,7 @@ import type {ReactNode} from 'react'
3
3
  import type {StyleProp, ViewStyle} from 'react-native'
4
4
 
5
5
  /**
6
- * A host for native atoms in a React Native layout — the SwiftUI / Compose `Host` an `@expo/ui` tree mounts into. It
6
+ * A host for native atoms in a React Native layout: the SwiftUI / Compose `Host` an `@expo/ui` tree mounts into. It
7
7
  * sits in that layout like a `Box`, and takes `Box`'s `sx` props for it: `h`, `flex`, margins.
8
8
  */
9
9
  export type IslandProps = ResponsiveViewSx & {
@@ -15,15 +15,15 @@ export type IslandProps = ResponsiveViewSx & {
15
15
  * width maps to `fixedSize(horizontal: true)`, so the native side ignores the proposed width and
16
16
  * resolves a `wide` stack's ideal width as unbounded.
17
17
  *
18
- * Turn it off — and give the island an explicit height, `h` — when the subtree contains an
18
+ * Turn it off (and give the island an explicit height, `h`) when the subtree contains an
19
19
  * `RnView`: that host drives its SwiftUI frame from the child's Yoga-laid-out bounds while this one
20
20
  * writes its measured size back into the Yoga style, and the two together spin a layout loop that
21
21
  * hangs the main thread as soon as the views lay out on screen.
22
22
  */
23
23
  matchContents?: boolean
24
- /** A React Native style for the host view, merged over the `sx` props — for what they cannot say. */
24
+ /** A React Native style for the host view, merged over the `sx` props, for what they cannot say. */
25
25
  style?: StyleProp<ViewStyle>
26
- /** Test identifier, forwarded to the host view on iOS — Android ignores it. */
26
+ /** Test identifier, forwarded to the host view on iOS. Android ignores it. */
27
27
  testID?: string
28
28
  }
29
29
 
@@ -1,23 +1,23 @@
1
1
  import type {ReactNode} from 'react'
2
2
 
3
3
  /**
4
- * A scrolling list — SwiftUI `List`, Compose `LazyColumn`. It has no height of its own, so it needs one from outside:
4
+ * A scrolling list: SwiftUI `List`, Compose `LazyColumn`. It has no height of its own, so it needs one from outside:
5
5
  * a `Screen`, or an `Island` with `matchContents={false}` and a height. In an island that sizes itself to its content
6
6
  * Compose measures it against an infinite height and throws ("Vertically scrollable component was measured with an
7
7
  * infinity maximum height"); SwiftUI shows nothing. For a handful of rows that should not scroll, use a `VStack`.
8
8
  *
9
- * Rows are separated for you — SwiftUI's own separators, a `Divider` between rows on Android — so a `Divider` among
9
+ * Rows are separated for you (SwiftUI's own separators, a `Divider` between rows on Android), so a `Divider` among
10
10
  * the children is one too many: on iOS it becomes an empty row of its own.
11
11
  */
12
12
  export type ListProps = {
13
- /** The rows — native views, one row each. */
13
+ /** The rows: native views, one row each. */
14
14
  children: ReactNode
15
15
  /**
16
- * Enables pull-to-refresh. Async on purpose — see `ScrollViewProps.onRefresh`: the spinner runs
16
+ * Enables pull-to-refresh. Async on purpose (see `ScrollViewProps.onRefresh`): the spinner runs
17
17
  * until the promise settles, so neither platform needs a `refreshing` flag kept in sync by hand.
18
18
  */
19
19
  onRefresh?: () => Promise<void>
20
- /** Test identifier, forwarded to the native view on iOS — Android ignores it. */
20
+ /** Test identifier, forwarded to the native view on iOS. Android ignores it. */
21
21
  testID?: string
22
22
  }
23
23
 
@@ -9,7 +9,7 @@ export type PickerOption = {
9
9
  }
10
10
 
11
11
  /**
12
- * A single choice from a list — a SwiftUI wheel picker on iOS, Material's exposed dropdown on Android. It brings its
12
+ * A single choice from a list: a SwiftUI wheel picker on iOS, Material's exposed dropdown on Android. It brings its
13
13
  * own host, so it renders outside `Screen` and `Island` as well.
14
14
  */
15
15
  export type PickerProps = {
@@ -1,8 +1,8 @@
1
1
  import {useSplitSx} from '@hzblj/kara-sx'
2
- import {useAppTheme, withOpacity} from '@hzblj/kara-theme'
2
+ import {duration, opacity, useAppTheme, withOpacity} from '@hzblj/kara-theme'
3
3
  import {useCallback, useMemo} from 'react'
4
- import {Platform, Pressable as RNPressable, View, type ViewStyle} from 'react-native'
5
- import Animated, {useAnimatedStyle, useSharedValue, withSpring} from 'react-native-reanimated'
4
+ import {Platform, Pressable as RNPressable, type ViewStyle} from 'react-native'
5
+ import Animated, {useAnimatedStyle, useSharedValue, withSpring, withTiming} from 'react-native-reanimated'
6
6
 
7
7
  import {haptics} from '../../haptics'
8
8
  import {splitForRipple} from '../../ripple-clip'
@@ -10,6 +10,12 @@ import type {PressableComponent, PressableProps} from './pressable.types'
10
10
 
11
11
  const SPRING = {damping: 20, stiffness: 400}
12
12
 
13
+ /** A dim comes in quickly and leaves a little slower, as UIKit's own highlight does. */
14
+ const DIM_IN = {duration: duration.d100}
15
+ const DIM_OUT = {duration: duration.d200}
16
+
17
+ const PLATFORM_EFFECT = Platform.OS === 'ios' ? 'scale' : 'none'
18
+
13
19
  const AnimatedPressable = Animated.createAnimatedComponent(RNPressable)
14
20
 
15
21
  export const Pressable: PressableComponent = ({
@@ -17,24 +23,38 @@ export const Pressable: PressableComponent = ({
17
23
  disabled = false,
18
24
  haptic = false,
19
25
  onPress,
26
+ pressEffect = PLATFORM_EFFECT,
27
+ pressedOpacity = 'o60',
28
+ pressedScale = 0.96,
29
+ ripple: withRipple = true,
20
30
  testID,
21
31
  ...props
22
32
  }: PressableProps) => {
23
33
  const [resolved, rest] = useSplitSx(props)
24
- const scale = useSharedValue(1)
34
+ // 0 at rest, 1 held: one value drives whichever effect is picked, so a change of effect needs no second animation.
35
+ const pressed = useSharedValue(0)
25
36
  const feedback = haptic === true ? 'light' : haptic || undefined
37
+ const dimmed = opacity[pressedOpacity]
26
38
 
27
39
  const theme = useAppTheme()
28
40
  const isAndroid = Platform.OS === 'android'
29
41
 
30
- const rStyle = useAnimatedStyle(() => ({transform: [{scale: scale.value}]}), [])
42
+ const rStyle = useAnimatedStyle(() => {
43
+ if (pressEffect === 'scale') {
44
+ return {transform: [{scale: 1 - (1 - pressedScale) * pressed.value}]}
45
+ }
31
46
 
32
- // Android's press is Material's: a ripple over the content — the pressed state layer, `onSurface` at 10 % — clipped to
33
- // the shape by an outer view (`splitForRipple`), and nothing moves. iOS springs down.
47
+ return pressEffect === 'opacity' ? {opacity: 1 - (1 - dimmed) * pressed.value} : {}
48
+ }, [dimmed, pressEffect, pressedScale])
49
+
50
+ // Android's press is Material's: a ripple over the content (the pressed state layer, `onSurface` at 10 %) clipped to
51
+ // the shape by an outer view (`splitForRipple`). The effect, when there is one, moves that outer view, ripple and all.
34
52
  const ripple = useMemo(
35
53
  () =>
36
- isAndroid ? {color: withOpacity(String(theme.color('content.primary')), 'o10'), foreground: true} : undefined,
37
- [isAndroid, theme]
54
+ isAndroid && withRipple
55
+ ? {color: withOpacity(String(theme.color('content.primary')), 'o10'), foreground: true}
56
+ : undefined,
57
+ [isAndroid, theme, withRipple]
38
58
  )
39
59
  const androidStyle = useMemo(
40
60
  () => (isAndroid ? splitForRipple(resolved as ViewStyle) : undefined),
@@ -43,20 +63,20 @@ export const Pressable: PressableComponent = ({
43
63
 
44
64
  // The finger is down: the Taptic Engine has until the release to wake, so the haptic lands with the press.
45
65
  const onPressIn = useCallback(() => {
46
- if (!isAndroid) {
47
- scale.value = withSpring(0.96, SPRING)
66
+ if (pressEffect === 'scale') {
67
+ pressed.value = withSpring(1, SPRING)
68
+ } else if (pressEffect === 'opacity') {
69
+ pressed.value = withTiming(1, DIM_IN)
48
70
  }
49
71
 
50
72
  if (feedback) {
51
73
  haptics.prepare(feedback)
52
74
  }
53
- }, [feedback, isAndroid, scale])
75
+ }, [feedback, pressEffect, pressed])
54
76
 
55
77
  const onPressOut = useCallback(() => {
56
- if (!isAndroid) {
57
- scale.value = withSpring(1, SPRING)
58
- }
59
- }, [isAndroid, scale])
78
+ pressed.value = pressEffect === 'scale' ? withSpring(0, SPRING) : withTiming(0, DIM_OUT)
79
+ }, [pressEffect, pressed])
60
80
 
61
81
  const onPressWithHaptic = useCallback(() => {
62
82
  if (feedback) {
@@ -68,20 +88,21 @@ export const Pressable: PressableComponent = ({
68
88
 
69
89
  if (androidStyle) {
70
90
  return (
71
- <View style={androidStyle.outer}>
91
+ <Animated.View style={[androidStyle.outer, rStyle]}>
72
92
  <RNPressable
73
93
  android_ripple={ripple}
74
94
  disabled={disabled}
75
95
  hitSlop={8}
76
96
  onPress={onPressWithHaptic}
77
97
  onPressIn={onPressIn}
98
+ onPressOut={onPressOut}
78
99
  style={androidStyle.inner}
79
100
  testID={testID}
80
101
  {...rest}
81
102
  >
82
103
  {children}
83
104
  </RNPressable>
84
- </View>
105
+ </Animated.View>
85
106
  )
86
107
  }
87
108
 
@@ -1,23 +1,40 @@
1
1
  import type {ResponsiveViewSx} from '@hzblj/kara-sx'
2
+ import type {OpacitySize} from '@hzblj/kara-theme'
2
3
  import type {ReactNode} from 'react'
3
4
 
4
5
  import type {Haptic} from '../../haptics'
5
6
 
7
+ /** How the content answers a press: it springs down, it dims, or it stays still. */
8
+ export type PressEffect = 'none' | 'opacity' | 'scale'
9
+
6
10
  /**
7
- * React Native's `Pressable`, styled through `sx` like a `Box`, taking touches 8 points past its edges. The press is
8
- * each platform's own: iOS springs it down to 96%; Android draws Material's ripple over the content, clipped to the
9
- * pressable's shape — give it the `borderRadius` of what it wraps (`full` around a `GlassView`). The React Native
10
- * tier — it needs no host.
11
+ * React Native's `Pressable`, styled through `sx` like a `Box`, taking touches 8 points past its edges. Each platform
12
+ * presses its own way by default: iOS springs the content down to 96%, Android draws Material's ripple over it,
13
+ * clipped to the pressable's shape. `pressEffect` picks the same answer on both, and Android keeps its ripple on top
14
+ * unless `ripple` is off. Give it the `borderRadius` of what it wraps (`full` around a `GlassView`). The React Native
15
+ * tier: it needs no host.
11
16
  */
12
17
  export type PressableProps = ResponsiveViewSx & {
13
18
  /** The pressable content. */
14
19
  children?: ReactNode
15
- /** Ignores presses — no `onPress`, no haptic, no spring or ripple. */
20
+ /** Ignores presses: no `onPress`, no haptic, no press effect or ripple. */
16
21
  disabled?: boolean
17
22
  /** Played on press. `true` is a `light` impact; a name picks the haptic, e.g. `selection` for a choice. */
18
23
  haptic?: boolean | Haptic
19
24
  /** Called when the press is released, after the `haptic` plays. */
20
25
  onPress?: () => void
26
+ /**
27
+ * How the content answers while it is held. `scale` springs it down to `pressedScale`, `opacity` dims it to
28
+ * `pressedOpacity`, `none` leaves it still. `scale` on iOS and `none` on Android by default, where the ripple is the
29
+ * press.
30
+ */
31
+ pressEffect?: PressEffect
32
+ /** What `opacity` dims to, an opacity token. `o60` by default. */
33
+ pressedOpacity?: OpacitySize
34
+ /** What `scale` springs down to. `0.96` by default. */
35
+ pressedScale?: number
36
+ /** Android's ripple: Material's pressed state layer over the content, clipped to the shape. On by default. iOS has none. */
37
+ ripple?: boolean
21
38
  /** Test identifier, forwarded to the view. */
22
39
  testID?: string
23
40
  }
@@ -1,7 +1,7 @@
1
1
  import type {ReactNode} from 'react'
2
2
 
3
3
  /**
4
- * A progress bar or ring, tinted `fill.accent.primary` — SwiftUI `ProgressView` (a capacity `Gauge` for a ring with a
4
+ * A progress bar or ring, tinted `fill.accent.primary`: SwiftUI `ProgressView` (a capacity `Gauge` for a ring with a
5
5
  * value, which `ProgressView` cannot draw on iOS) / Compose's `LinearProgressIndicator` and `CircularProgressIndicator`.
6
6
  */
7
7
  export type ProgressProps = {
@@ -3,11 +3,11 @@ import type {FlatListProps as RNFlatListProps} from 'react-native'
3
3
 
4
4
  /**
5
5
  * Top-level `sx` styles the viewport; `content` styles the scrolling content container, so padding and
6
- * gap belong there — the same split as `RnScrollView`. `removeClippedSubviews` is off unless you turn it on:
6
+ * gap belong there (the same split as `RnScrollView`). `removeClippedSubviews` is off unless you turn it on:
7
7
  * Android's default would detach a row's host before it has measured itself, and the row would stay empty.
8
8
  */
9
9
  export type RnFlatListProps<TItem> = ResponsiveViewSx &
10
10
  Omit<RNFlatListProps<TItem>, 'contentContainerStyle' | 'style'> & {
11
- /** Styles the scrolling content container — padding and gap belong here. */
11
+ /** Styles the scrolling content container; padding and gap belong here. */
12
12
  content?: ResponsiveViewSx
13
13
  }
@@ -2,7 +2,7 @@ import type {ReactNode} from 'react'
2
2
 
3
3
  import type {IconProps} from '../icon'
4
4
 
5
- /** The same contract as `Icon`, for the React Native tier — anywhere, no `Screen` or `Island` needed. */
5
+ /** The same contract as `Icon`, for the React Native tier: anywhere, no `Screen` or `Island` needed. */
6
6
  export type RnIconProps = IconProps
7
7
 
8
8
  export type RnIconComponent = (props: RnIconProps) => ReactNode