react-native-tinyui 0.5.0 → 1.0.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 (140) hide show
  1. package/README.md +351 -22
  2. package/ios/ConcentricView/TinyuiConcentricView.h +12 -0
  3. package/ios/ConcentricView/TinyuiConcentricView.mm +60 -0
  4. package/ios/Core/Tinyui.mm +54 -0
  5. package/ios/Core/TinyuiComponentClasses.mm +44 -0
  6. package/ios/Menu/TinyuiMenuBuilder.swift +238 -0
  7. package/ios/Menu/TinyuiMenuProvider.swift +51 -85
  8. package/ios/Menu/TinyuiMenuView.mm +12 -35
  9. package/ios/Popover/TinyuiPopoverProvider.swift +198 -44
  10. package/ios/Popover/TinyuiPopoverView.mm +26 -1
  11. package/ios/SFSymbol/TinyuiSFSymbolEffects.h +9 -0
  12. package/ios/SFSymbol/TinyuiSFSymbolEffects.mm +180 -0
  13. package/ios/SFSymbol/TinyuiSFSymbolImage.h +8 -0
  14. package/ios/SFSymbol/TinyuiSFSymbolImage.mm +141 -0
  15. package/ios/SFSymbol/TinyuiSFSymbolShadowNode.h +31 -0
  16. package/ios/SFSymbol/TinyuiSFSymbolShadowNode.mm +30 -0
  17. package/ios/SFSymbol/TinyuiSFSymbolView.h +4 -0
  18. package/ios/SFSymbol/TinyuiSFSymbolView.mm +173 -0
  19. package/ios/Stepper/TinyuiStepperShadowNode.h +32 -0
  20. package/ios/Stepper/TinyuiStepperShadowNode.mm +28 -0
  21. package/ios/Stepper/TinyuiStepperView.h +12 -0
  22. package/ios/Stepper/TinyuiStepperView.mm +128 -0
  23. package/ios/TipKit/TinyuiTip.swift +31 -0
  24. package/ios/TipKit/TinyuiTipPopoverProvider.swift +276 -0
  25. package/ios/TipKit/TinyuiTipPopoverView.h +8 -0
  26. package/ios/TipKit/TinyuiTipPopoverView.mm +114 -0
  27. package/ios/TipKit/TinyuiTipsRuntime.swift +148 -0
  28. package/lib/module/ConcentricView/ConcentricViewNativeComponent.ts +14 -0
  29. package/lib/module/ConcentricView/index.js +29 -0
  30. package/lib/module/ConcentricView/index.js.map +1 -0
  31. package/lib/module/ConcentricView/types.js +4 -0
  32. package/lib/module/ConcentricView/types.js.map +1 -0
  33. package/lib/module/Menu/MenuNativeComponent.ts +1 -3
  34. package/lib/module/Menu/index.js +4 -9
  35. package/lib/module/Menu/index.js.map +1 -1
  36. package/lib/module/Menu/options.js +4 -12
  37. package/lib/module/Menu/options.js.map +1 -1
  38. package/lib/module/NativeTinyui.js.map +1 -1
  39. package/lib/module/Popover/index.js +4 -2
  40. package/lib/module/Popover/index.js.map +1 -1
  41. package/lib/module/SFSymbol/SFSymbolNativeComponent.ts +20 -0
  42. package/lib/module/SFSymbol/index.js +73 -0
  43. package/lib/module/SFSymbol/index.js.map +1 -0
  44. package/lib/module/SFSymbol/options.js +79 -0
  45. package/lib/module/SFSymbol/options.js.map +1 -0
  46. package/lib/module/SFSymbol/types.js +4 -0
  47. package/lib/module/SFSymbol/types.js.map +1 -0
  48. package/lib/module/Stepper/StepperNativeComponent.ts +29 -0
  49. package/lib/module/Stepper/index.js +75 -0
  50. package/lib/module/Stepper/index.js.map +1 -0
  51. package/lib/module/Stepper/types.js +4 -0
  52. package/lib/module/Stepper/types.js.map +1 -0
  53. package/lib/module/TipKit/Popover.js +89 -0
  54. package/lib/module/TipKit/Popover.js.map +1 -0
  55. package/lib/module/TipKit/TipPopoverNativeComponent.ts +37 -0
  56. package/lib/module/TipKit/index.js +28 -0
  57. package/lib/module/TipKit/index.js.map +1 -0
  58. package/lib/module/TipKit/types.js +4 -0
  59. package/lib/module/TipKit/types.js.map +1 -0
  60. package/lib/module/TipKit/validation.js +24 -0
  61. package/lib/module/TipKit/validation.js.map +1 -0
  62. package/lib/module/index.js +4 -0
  63. package/lib/module/index.js.map +1 -1
  64. package/lib/module/utils/getNativeTinyui.js.map +1 -1
  65. package/lib/typescript/src/ConcentricView/ConcentricViewNativeComponent.d.ts +7 -0
  66. package/lib/typescript/src/ConcentricView/ConcentricViewNativeComponent.d.ts.map +1 -0
  67. package/lib/typescript/src/ConcentricView/index.d.ts +4 -0
  68. package/lib/typescript/src/ConcentricView/index.d.ts.map +1 -0
  69. package/lib/typescript/src/ConcentricView/types.d.ts +6 -0
  70. package/lib/typescript/src/ConcentricView/types.d.ts.map +1 -0
  71. package/lib/typescript/src/Menu/MenuNativeComponent.d.ts +2 -3
  72. package/lib/typescript/src/Menu/MenuNativeComponent.d.ts.map +1 -1
  73. package/lib/typescript/src/Menu/index.d.ts +1 -1
  74. package/lib/typescript/src/Menu/index.d.ts.map +1 -1
  75. package/lib/typescript/src/Menu/options.d.ts +1 -5
  76. package/lib/typescript/src/Menu/options.d.ts.map +1 -1
  77. package/lib/typescript/src/Menu/types.d.ts +16 -4
  78. package/lib/typescript/src/Menu/types.d.ts.map +1 -1
  79. package/lib/typescript/src/NativeTinyui.d.ts +2 -0
  80. package/lib/typescript/src/NativeTinyui.d.ts.map +1 -1
  81. package/lib/typescript/src/Popover/index.d.ts.map +1 -1
  82. package/lib/typescript/src/Popover/types.d.ts +2 -0
  83. package/lib/typescript/src/Popover/types.d.ts.map +1 -1
  84. package/lib/typescript/src/SFSymbol/SFSymbolNativeComponent.d.ts +11 -0
  85. package/lib/typescript/src/SFSymbol/SFSymbolNativeComponent.d.ts.map +1 -0
  86. package/lib/typescript/src/SFSymbol/index.d.ts +4 -0
  87. package/lib/typescript/src/SFSymbol/index.d.ts.map +1 -0
  88. package/lib/typescript/src/SFSymbol/options.d.ts +86 -0
  89. package/lib/typescript/src/SFSymbol/options.d.ts.map +1 -0
  90. package/lib/typescript/src/SFSymbol/types.d.ts +113 -0
  91. package/lib/typescript/src/SFSymbol/types.d.ts.map +1 -0
  92. package/lib/typescript/src/Stepper/StepperNativeComponent.d.ts +21 -0
  93. package/lib/typescript/src/Stepper/StepperNativeComponent.d.ts.map +1 -0
  94. package/lib/typescript/src/Stepper/index.d.ts +4 -0
  95. package/lib/typescript/src/Stepper/index.d.ts.map +1 -0
  96. package/lib/typescript/src/Stepper/types.d.ts +24 -0
  97. package/lib/typescript/src/Stepper/types.d.ts.map +1 -0
  98. package/lib/typescript/src/TipKit/Popover.d.ts +3 -0
  99. package/lib/typescript/src/TipKit/Popover.d.ts.map +1 -0
  100. package/lib/typescript/src/TipKit/TipPopoverNativeComponent.d.ts +38 -0
  101. package/lib/typescript/src/TipKit/TipPopoverNativeComponent.d.ts.map +1 -0
  102. package/lib/typescript/src/TipKit/index.d.ts +10 -0
  103. package/lib/typescript/src/TipKit/index.d.ts.map +1 -0
  104. package/lib/typescript/src/TipKit/types.d.ts +46 -0
  105. package/lib/typescript/src/TipKit/types.d.ts.map +1 -0
  106. package/lib/typescript/src/TipKit/validation.d.ts +4 -0
  107. package/lib/typescript/src/TipKit/validation.d.ts.map +1 -0
  108. package/lib/typescript/src/index.d.ts +9 -1
  109. package/lib/typescript/src/index.d.ts.map +1 -1
  110. package/lib/typescript/src/utils/getNativeTinyui.d.ts +1 -1
  111. package/lib/typescript/src/utils/getNativeTinyui.d.ts.map +1 -1
  112. package/package.json +37 -2
  113. package/{Tinyui.podspec → react-native-tinyui.podspec} +23 -2
  114. package/src/ConcentricView/ConcentricViewNativeComponent.ts +14 -0
  115. package/src/ConcentricView/index.tsx +34 -0
  116. package/src/ConcentricView/types.ts +6 -0
  117. package/src/Menu/MenuNativeComponent.ts +1 -3
  118. package/src/Menu/index.tsx +6 -6
  119. package/src/Menu/options.ts +2 -20
  120. package/src/Menu/types.ts +18 -4
  121. package/src/NativeTinyui.ts +2 -0
  122. package/src/Popover/index.tsx +8 -3
  123. package/src/Popover/types.ts +2 -0
  124. package/src/SFSymbol/SFSymbolNativeComponent.ts +20 -0
  125. package/src/SFSymbol/index.tsx +89 -0
  126. package/src/SFSymbol/options.ts +116 -0
  127. package/src/SFSymbol/types.ts +158 -0
  128. package/src/Stepper/StepperNativeComponent.ts +29 -0
  129. package/src/Stepper/index.tsx +91 -0
  130. package/src/Stepper/types.ts +24 -0
  131. package/src/TipKit/Popover.tsx +87 -0
  132. package/src/TipKit/TipPopoverNativeComponent.ts +37 -0
  133. package/src/TipKit/index.ts +47 -0
  134. package/src/TipKit/types.ts +57 -0
  135. package/src/TipKit/validation.ts +39 -0
  136. package/src/index.tsx +30 -0
  137. package/src/utils/getNativeTinyui.ts +8 -1
  138. package/ios/Core/TinyuiHostingHelpers.swift +0 -74
  139. package/ios/Menu/TinyuiMenuViewSwift.swift +0 -326
  140. package/ios/Popover/TinyuiPopoverViewSwift.swift +0 -88
@@ -0,0 +1,116 @@
1
+ import { processColor } from 'react-native';
2
+
3
+ import type { SFSymbolEffect, SFSymbolProps } from './types';
4
+
5
+ function finite(name: string, value: number | undefined, minimum: number) {
6
+ if (value !== undefined && (!Number.isFinite(value) || value < minimum)) {
7
+ throw new RangeError(
8
+ `[TinyUI] SFSymbol ${name} must be finite and >= ${minimum}.`
9
+ );
10
+ }
11
+ }
12
+
13
+ function positive(name: string, value: number | undefined) {
14
+ finite(name, value, 0);
15
+ if (value === 0) {
16
+ throw new RangeError(`[TinyUI] SFSymbol ${name} must be greater than 0.`);
17
+ }
18
+ }
19
+
20
+ export function serializeSFSymbol(props: SFSymbolProps, fontScale: number) {
21
+ positive('size', props.size);
22
+ finite('variableValue', props.variableValue, 0);
23
+ if (props.variableValue !== undefined && props.variableValue > 1) {
24
+ throw new RangeError('[TinyUI] SFSymbol variableValue must be <= 1.');
25
+ }
26
+ if (props.maxFontSizeMultiplier !== 0) {
27
+ finite('maxFontSizeMultiplier', props.maxFontSizeMultiplier, 1);
28
+ }
29
+ if (
30
+ props.paletteColors &&
31
+ (props.paletteColors.length < 1 ||
32
+ props.paletteColors.length > 3 ||
33
+ props.paletteColors.some((color) => color === undefined))
34
+ ) {
35
+ throw new RangeError(
36
+ '[TinyUI] SFSymbol paletteColors needs 1 to 3 colors.'
37
+ );
38
+ }
39
+
40
+ const effects: readonly SFSymbolEffect[] = props.effect
41
+ ? Array.isArray(props.effect)
42
+ ? props.effect
43
+ : [props.effect as SFSymbolEffect]
44
+ : [];
45
+ const types = new Set<string>();
46
+ for (const effect of effects) {
47
+ if (types.has(effect.type)) {
48
+ throw new Error(
49
+ `[TinyUI] SFSymbol has duplicate ${effect.type} effects.`
50
+ );
51
+ }
52
+ types.add(effect.type);
53
+ positive('effect.options.speed', effect.options?.speed);
54
+ finite('effect.options.repeatDelay', effect.options?.repeatDelay, 0);
55
+ const repeat = effect.options?.repeat;
56
+ if (typeof repeat === 'number') {
57
+ positive('effect.options.repeat', repeat);
58
+ if (!Number.isSafeInteger(repeat)) {
59
+ throw new RangeError(
60
+ '[TinyUI] SFSymbol repeat must be a safe integer.'
61
+ );
62
+ }
63
+ }
64
+ if (
65
+ effect.options?.repeatBehavior === 'continuous' &&
66
+ ((repeat !== undefined && repeat !== 'forever') ||
67
+ effect.options.repeatDelay !== undefined)
68
+ ) {
69
+ throw new Error(
70
+ '[TinyUI] SFSymbol continuous repetition cannot have a count or delay.'
71
+ );
72
+ }
73
+ if (
74
+ effect.type === 'wiggle' &&
75
+ effect.angle !== undefined &&
76
+ !Number.isFinite(effect.angle)
77
+ ) {
78
+ throw new RangeError('[TinyUI] SFSymbol wiggle angle must be finite.');
79
+ }
80
+ if (
81
+ typeof effect.trigger === 'number' &&
82
+ !Number.isFinite(effect.trigger)
83
+ ) {
84
+ throw new RangeError('[TinyUI] SFSymbol effect trigger must be finite.');
85
+ }
86
+ }
87
+ positive('contentTransition.speed', props.contentTransition?.speed);
88
+
89
+ return {
90
+ configuration: {
91
+ name: props.name,
92
+ source: props.source ?? 'system',
93
+ size: props.size ?? 17,
94
+ weight: props.weight ?? 'unspecified',
95
+ scale: props.scale ?? 'default',
96
+ textStyle: props.textStyle,
97
+ fontFamily: props.fontFamily,
98
+ fontScale:
99
+ props.allowFontScaling === false
100
+ ? 1
101
+ : Math.min(fontScale, props.maxFontSizeMultiplier || Infinity),
102
+ renderingMode: props.renderingMode ?? 'automatic',
103
+ color: props.color === undefined ? undefined : processColor(props.color),
104
+ paletteColors: props.paletteColors?.map((color) => processColor(color)),
105
+ variableValue: props.variableValue,
106
+ variableValueMode: props.variableValueMode ?? 'automatic',
107
+ colorRenderingMode: props.colorRenderingMode ?? 'automatic',
108
+ },
109
+ effects: effects.map((effect) => ({
110
+ ...effect,
111
+ active: effect.active ?? true,
112
+ animated: effect.animated ?? true,
113
+ })),
114
+ contentTransition: props.contentTransition ?? {},
115
+ };
116
+ }
@@ -0,0 +1,158 @@
1
+ import type { ColorValue, ViewProps } from 'react-native';
2
+
3
+ export type SFSymbolWeight =
4
+ | 'unspecified'
5
+ | 'ultraLight'
6
+ | 'thin'
7
+ | 'light'
8
+ | 'regular'
9
+ | 'medium'
10
+ | 'semibold'
11
+ | 'bold'
12
+ | 'heavy'
13
+ | 'black';
14
+
15
+ export type SFSymbolScale =
16
+ 'default' | 'unspecified' | 'small' | 'medium' | 'large';
17
+ export type SFSymbolRenderingMode =
18
+ 'automatic' | 'monochrome' | 'hierarchical' | 'palette' | 'multicolor';
19
+ export type SFSymbolTextStyle =
20
+ | 'extraLargeTitle'
21
+ | 'extraLargeTitle2'
22
+ | 'largeTitle'
23
+ | 'title1'
24
+ | 'title2'
25
+ | 'title3'
26
+ | 'headline'
27
+ | 'subheadline'
28
+ | 'body'
29
+ | 'callout'
30
+ | 'footnote'
31
+ | 'caption1'
32
+ | 'caption2';
33
+
34
+ export interface SFSymbolEffectOptions {
35
+ /** Positive speed multiplier. Defaults to the system speed (1). */
36
+ speed?: number;
37
+ /** Play count, forever, or false for one play. Omit for the system default. */
38
+ repeat?: number | 'forever' | false;
39
+ /** iOS 18+. Continuous repeats forever; periodic supports count and delay. */
40
+ repeatBehavior?: 'periodic' | 'continuous';
41
+ /** Seconds between periodic repetitions (iOS 18+). */
42
+ repeatDelay?: number;
43
+ }
44
+
45
+ interface EffectPlayback {
46
+ /** Whether this effect is applied. Defaults to true. */
47
+ active?: boolean;
48
+ /** Change this value to replay the same effect. Stable values do not replay. */
49
+ trigger?: string | number;
50
+ /** Animate applying/removing the effect. Defaults to true. */
51
+ animated?: boolean;
52
+ options?: SFSymbolEffectOptions;
53
+ }
54
+
55
+ type LayerBehavior = 'byLayer' | 'wholeSymbol';
56
+ type VerticalDirection = 'up' | 'down';
57
+
58
+ /** Only modifiers supported by each Apple preset are accepted. */
59
+ export type SFSymbolEffect = EffectPlayback &
60
+ (
61
+ | { type: 'pulse'; scope?: LayerBehavior }
62
+ | {
63
+ type: 'bounce' | 'scale' | 'appear' | 'disappear';
64
+ direction?: VerticalDirection;
65
+ scope?: LayerBehavior;
66
+ }
67
+ | {
68
+ type: 'variableColor';
69
+ iteration?: 'iterative' | 'cumulative';
70
+ reversing?: boolean;
71
+ inactiveLayers?: 'hide' | 'dim';
72
+ }
73
+ | {
74
+ /** iOS 18+. */
75
+ type: 'wiggle';
76
+ direction?:
77
+ | VerticalDirection
78
+ | 'left'
79
+ | 'right'
80
+ | 'forward'
81
+ | 'backward'
82
+ | 'clockwise'
83
+ | 'counterClockwise';
84
+ /** Custom angle in degrees, clockwise from +x; overrides direction. */
85
+ angle?: number;
86
+ scope?: LayerBehavior;
87
+ }
88
+ | {
89
+ /** iOS 18+. */
90
+ type: 'rotate';
91
+ direction?: 'clockwise' | 'counterClockwise';
92
+ scope?: LayerBehavior;
93
+ }
94
+ | {
95
+ /** iOS 18+. */
96
+ type: 'breathe';
97
+ style?: 'plain' | 'pulse';
98
+ scope?: LayerBehavior;
99
+ }
100
+ | {
101
+ /** iOS 26+. */
102
+ type: 'drawOn';
103
+ scope?: LayerBehavior | 'individually';
104
+ }
105
+ | {
106
+ /** iOS 26+. */
107
+ type: 'drawOff';
108
+ scope?: LayerBehavior | 'individually';
109
+ reversed?: boolean;
110
+ }
111
+ );
112
+
113
+ export interface SFSymbolContentTransition {
114
+ /** Magic Replace requires iOS 18; earlier versions use the configured replace. */
115
+ type: 'automatic' | 'replace' | 'magicReplace';
116
+ /** Replace style, also used as the Magic Replace fallback. */
117
+ direction?: 'downUp' | 'upUp' | 'offUp';
118
+ scope?: LayerBehavior;
119
+ /** Positive transition speed multiplier. Defaults to 1. */
120
+ speed?: number;
121
+ }
122
+
123
+ export interface SFSymbolProps extends Omit<ViewProps, 'children'> {
124
+ /** Full SF Symbol name, including variants such as .circle.fill. */
125
+ name: string;
126
+ /** Load a system symbol (default) or a custom symbol in the app asset catalog. */
127
+ source?: 'system' | 'asset';
128
+ /** Point size before font scaling. Defaults to 17. textStyle takes precedence. */
129
+ size?: number;
130
+ weight?: SFSymbolWeight;
131
+ scale?: SFSymbolScale;
132
+ textStyle?: SFSymbolTextStyle;
133
+ /** Font/PostScript name used to derive the symbol's font metrics. */
134
+ fontFamily?: string;
135
+ /** Apply React Native's fontScale to the point size. Defaults to true. */
136
+ allowFontScaling?: boolean;
137
+ /** Maximum font scale, >= 1. Zero/undefined means no limit. */
138
+ maxFontSizeMultiplier?: number;
139
+ renderingMode?: SFSymbolRenderingMode;
140
+ /** Tint / primary hierarchical color. Defaults to the semantic label color. */
141
+ color?: ColorValue;
142
+ /** One to three colors for palette rendering, in primary-to-tertiary order. */
143
+ paletteColors?: readonly [ColorValue, ColorValue?, ColorValue?];
144
+ /** Variable color/draw progress, from 0 to 1. Omit for the symbol default. */
145
+ variableValue?: number;
146
+ /** iOS 26+. Earlier versions retain the system's variable color behavior. */
147
+ variableValueMode?: 'automatic' | 'color' | 'draw';
148
+ /** iOS 26+. Earlier versions use flat colors. */
149
+ colorRenderingMode?: 'automatic' | 'flat' | 'gradient';
150
+ /** Native image fitting within an explicitly sized frame. Defaults to center. */
151
+ resizeMode?: 'center' | 'contain' | 'cover' | 'stretch';
152
+ /** One preset or multiple distinct presets. Unsupported OS presets are ignored. */
153
+ effect?: SFSymbolEffect | readonly SFSymbolEffect[];
154
+ /** Animate changes to the name or image configuration. Omit to update instantly. */
155
+ contentTransition?: SFSymbolContentTransition;
156
+ /** Honor the system Reduce Motion setting. Defaults to true. */
157
+ respectReduceMotion?: boolean;
158
+ }
@@ -0,0 +1,29 @@
1
+ import {
2
+ codegenNativeComponent,
3
+ type CodegenTypes,
4
+ type ViewProps,
5
+ } from 'react-native';
6
+
7
+ type StepperChangeEvent = Readonly<{
8
+ value: CodegenTypes.Double;
9
+ eventCount: CodegenTypes.Int32;
10
+ }>;
11
+
12
+ export interface NativeStepperProps extends ViewProps {
13
+ value?: CodegenTypes.WithDefault<CodegenTypes.Double, 0>;
14
+ minimumValue?: CodegenTypes.WithDefault<CodegenTypes.Double, 0>;
15
+ maximumValue?: CodegenTypes.WithDefault<CodegenTypes.Double, 100>;
16
+ stepValue?: CodegenTypes.WithDefault<CodegenTypes.Double, 1>;
17
+ isContinuous?: CodegenTypes.WithDefault<boolean, true>;
18
+ autorepeat?: CodegenTypes.WithDefault<boolean, true>;
19
+ wraps?: CodegenTypes.WithDefault<boolean, false>;
20
+ disabled?: CodegenTypes.WithDefault<boolean, false>;
21
+ controlled?: CodegenTypes.WithDefault<boolean, false>;
22
+ mostRecentEventCount?: CodegenTypes.WithDefault<CodegenTypes.Int32, 0>;
23
+ // Match the bubbling topChange event inherited from React Native's base view.
24
+ onChange?: CodegenTypes.BubblingEventHandler<StepperChangeEvent>;
25
+ }
26
+
27
+ export default codegenNativeComponent<NativeStepperProps>('TinyuiStepperView', {
28
+ excludedPlatforms: ['android'],
29
+ });
@@ -0,0 +1,91 @@
1
+ import { forwardRef, useState, type ComponentRef } from 'react';
2
+ import { StyleSheet, type View } from 'react-native';
3
+
4
+ import { assertComponentEnabled } from '../utils';
5
+ import NativeStepperView from './StepperNativeComponent';
6
+ import type { StepperProps } from './types';
7
+
8
+ export const Stepper = forwardRef<ComponentRef<typeof View>, StepperProps>(
9
+ function StepperRoot(
10
+ {
11
+ value,
12
+ defaultValue = 0,
13
+ minimumValue = 0,
14
+ maximumValue = 100,
15
+ stepValue = 1,
16
+ isContinuous = true,
17
+ autorepeat = true,
18
+ wraps = false,
19
+ disabled,
20
+ onValueChange,
21
+ style,
22
+ accessibilityState,
23
+ ...viewProps
24
+ },
25
+ ref
26
+ ) {
27
+ assertComponentEnabled('Stepper');
28
+
29
+ const [initialValue] = useState(defaultValue);
30
+ const [mostRecentEventCount, setMostRecentEventCount] = useState(0);
31
+ const resolvedValue = value ?? initialValue;
32
+ const resolvedDisabled = disabled ?? accessibilityState?.disabled ?? false;
33
+
34
+ for (const [name, number] of Object.entries({
35
+ value: resolvedValue,
36
+ minimumValue,
37
+ maximumValue,
38
+ stepValue,
39
+ })) {
40
+ if (!Number.isFinite(number)) {
41
+ throw new RangeError(
42
+ `[TinyUI] Stepper ${name} must be a finite number.`
43
+ );
44
+ }
45
+ }
46
+ if (maximumValue < minimumValue) {
47
+ throw new RangeError(
48
+ '[TinyUI] Stepper maximumValue must be greater than or equal to minimumValue.'
49
+ );
50
+ }
51
+ if (stepValue <= 0) {
52
+ throw new RangeError(
53
+ '[TinyUI] Stepper stepValue must be greater than 0.'
54
+ );
55
+ }
56
+
57
+ return (
58
+ <NativeStepperView
59
+ {...viewProps}
60
+ ref={ref}
61
+ accessibilityState={{
62
+ ...accessibilityState,
63
+ disabled: resolvedDisabled,
64
+ }}
65
+ autorepeat={autorepeat}
66
+ isContinuous={isContinuous}
67
+ controlled={value !== undefined}
68
+ disabled={resolvedDisabled}
69
+ maximumValue={maximumValue}
70
+ minimumValue={minimumValue}
71
+ mostRecentEventCount={mostRecentEventCount}
72
+ onChange={(event) => {
73
+ // Acknowledge every event, even if the parent rejects a controlled
74
+ // change by keeping the same value. Native ignores stale replies.
75
+ setMostRecentEventCount(event.nativeEvent.eventCount);
76
+ onValueChange?.(event.nativeEvent.value);
77
+ }}
78
+ stepValue={stepValue}
79
+ style={[styles.stepper, style]}
80
+ value={Math.min(maximumValue, Math.max(minimumValue, resolvedValue))}
81
+ wraps={wraps}
82
+ />
83
+ );
84
+ }
85
+ );
86
+
87
+ const styles = StyleSheet.create({
88
+ stepper: { alignSelf: 'flex-start' },
89
+ });
90
+
91
+ export type { StepperProps } from './types';
@@ -0,0 +1,24 @@
1
+ import type { ViewProps } from 'react-native';
2
+
3
+ export interface StepperProps extends Omit<ViewProps, 'children'> {
4
+ /** Controlled value. Update it from onValueChange to accept user changes. */
5
+ value?: number;
6
+ /** Initial uncontrolled value. Defaults to 0. */
7
+ defaultValue?: number;
8
+ /** Lower bound. Defaults to 0. */
9
+ minimumValue?: number;
10
+ /** Upper bound, greater than or equal to minimumValue. Defaults to 100. */
11
+ maximumValue?: number;
12
+ /** Positive increment/decrement amount. Defaults to 1. */
13
+ stepValue?: number;
14
+ /** Emit changes while interacting, rather than only on release. Defaults to true. */
15
+ isContinuous?: boolean;
16
+ /** Repeatedly step while holding either button. Defaults to true. */
17
+ autorepeat?: boolean;
18
+ /** Wrap between the bounds instead of stopping at them. Defaults to false. */
19
+ wraps?: boolean;
20
+ /** Disable user interaction. Defaults to false. */
21
+ disabled?: boolean;
22
+ /** Called with the new value after a user interaction. */
23
+ onValueChange?: (value: number) => void;
24
+ }
@@ -0,0 +1,87 @@
1
+ import { forwardRef, type ComponentRef } from 'react';
2
+ import { View } from 'react-native';
3
+
4
+ import { assertComponentEnabled } from '../utils';
5
+ import NativeTipPopoverView from './TipPopoverNativeComponent';
6
+ import type { TipPopoverProps, TipStatus } from './types';
7
+ import { validateTip } from './validation';
8
+
9
+ export const Popover = forwardRef<ComponentRef<typeof View>, TipPopoverProps>(
10
+ function TipPopoverRoot(props, ref) {
11
+ assertComponentEnabled('TipKit');
12
+ validateTip(props);
13
+ const {
14
+ children,
15
+ tipId,
16
+ title,
17
+ message,
18
+ systemImage,
19
+ actions,
20
+ enabled = true,
21
+ maxDisplayCount,
22
+ ignoresDisplayFrequency = false,
23
+ arrowEdge = 'auto',
24
+ onStatusChange,
25
+ onVisibleChange,
26
+ onActionPress,
27
+ onError,
28
+ ...viewProps
29
+ } = props;
30
+
31
+ return (
32
+ <NativeTipPopoverView
33
+ {...viewProps}
34
+ ref={ref}
35
+ collapsable={false}
36
+ tipId={tipId}
37
+ title={title}
38
+ message={message}
39
+ systemImage={systemImage}
40
+ actions={actions}
41
+ enabled={enabled}
42
+ maxDisplayCount={maxDisplayCount ?? 0}
43
+ ignoresDisplayFrequency={ignoresDisplayFrequency}
44
+ arrowEdge={arrowEdge}
45
+ onTipStatusChange={({ nativeEvent }) => {
46
+ if (nativeEvent.tipId !== tipId) return;
47
+ if (nativeEvent.status === 'invalidated') {
48
+ onStatusChange?.({
49
+ status: 'invalidated',
50
+ reason: nativeEvent.reason,
51
+ } as TipStatus);
52
+ } else if (
53
+ nativeEvent.status === 'pending' ||
54
+ nativeEvent.status === 'available'
55
+ ) {
56
+ onStatusChange?.({ status: nativeEvent.status });
57
+ }
58
+ }}
59
+ onTipVisibleChange={({ nativeEvent }) => {
60
+ if (nativeEvent.tipId === tipId)
61
+ onVisibleChange?.(nativeEvent.visible);
62
+ }}
63
+ onTipAction={({ nativeEvent }) => {
64
+ if (nativeEvent.tipId === tipId) {
65
+ onActionPress?.({ id: nativeEvent.id, title: nativeEvent.title });
66
+ }
67
+ }}
68
+ onTipError={({ nativeEvent }) => {
69
+ if (nativeEvent.tipId !== tipId) return;
70
+ const error = {
71
+ code: nativeEvent.code,
72
+ message: nativeEvent.message,
73
+ };
74
+ if (onError) onError(error);
75
+ else
76
+ console.warn(
77
+ `[TinyUI] TipKit.Popover ${error.code}: ${error.message}`
78
+ );
79
+ }}
80
+ >
81
+ <View collapsable={false}>{children}</View>
82
+ </NativeTipPopoverView>
83
+ );
84
+ }
85
+ );
86
+
87
+ Popover.displayName = 'TipKit.Popover';
@@ -0,0 +1,37 @@
1
+ import {
2
+ codegenNativeComponent,
3
+ type CodegenTypes,
4
+ type ViewProps,
5
+ } from 'react-native';
6
+ import type { DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
7
+
8
+ export interface NativeTipPopoverProps extends ViewProps {
9
+ tipId: string;
10
+ title: string;
11
+ message?: string;
12
+ systemImage?: string;
13
+ actions?: ReadonlyArray<Readonly<{ id: string; title: string }>>;
14
+ enabled?: boolean;
15
+ maxDisplayCount?: CodegenTypes.Int32;
16
+ ignoresDisplayFrequency?: boolean;
17
+ arrowEdge?: string;
18
+ onTipStatusChange?: DirectEventHandler<
19
+ Readonly<{ tipId: string; status: string; reason: string }>
20
+ >;
21
+ onTipVisibleChange?: DirectEventHandler<
22
+ Readonly<{ tipId: string; visible: boolean }>
23
+ >;
24
+ onTipAction?: DirectEventHandler<
25
+ Readonly<{ tipId: string; id: string; title: string }>
26
+ >;
27
+ onTipError?: DirectEventHandler<
28
+ Readonly<{ tipId: string; code: string; message: string }>
29
+ >;
30
+ }
31
+
32
+ export default codegenNativeComponent<NativeTipPopoverProps>(
33
+ 'TinyuiTipPopoverView',
34
+ {
35
+ excludedPlatforms: ['android'],
36
+ }
37
+ );
@@ -0,0 +1,47 @@
1
+ import { assertComponentEnabled, getNativeTinyui } from '../utils';
2
+ import type { TipInvalidationReason, TipKitConfiguration } from './types';
3
+ import { validateTipId } from './validation';
4
+ import { Popover } from './Popover';
5
+
6
+ export const TipKit = {
7
+ Popover,
8
+ /** Configure TipKit once before mounting tips. Repeating the same options is safe. */
9
+ async configure({
10
+ displayFrequency = 'daily',
11
+ }: TipKitConfiguration = {}): Promise<void> {
12
+ assertComponentEnabled('TipKit');
13
+ if (
14
+ !['immediate', 'hourly', 'daily', 'weekly', 'monthly'].includes(
15
+ displayFrequency
16
+ )
17
+ ) {
18
+ throw new Error(
19
+ '[TinyUI] TipKit.configure received an invalid displayFrequency.'
20
+ );
21
+ }
22
+ await getNativeTinyui().configureTips(displayFrequency);
23
+ },
24
+
25
+ /** Persistently invalidate a tip, including when its view is not mounted. */
26
+ async invalidate(
27
+ tipId: string,
28
+ reason: TipInvalidationReason = 'actionPerformed'
29
+ ): Promise<void> {
30
+ assertComponentEnabled('TipKit');
31
+ validateTipId(tipId);
32
+ if (reason !== 'actionPerformed' && reason !== 'tipClosed') {
33
+ throw new Error('[TinyUI] TipKit.invalidate received an invalid reason.');
34
+ }
35
+ await getNativeTinyui().invalidateTip(tipId, reason);
36
+ },
37
+ };
38
+
39
+ export type {
40
+ TipAction,
41
+ TipDisplayFrequency,
42
+ TipError,
43
+ TipInvalidationReason,
44
+ TipKitConfiguration,
45
+ TipPopoverProps,
46
+ TipStatus,
47
+ } from './types';
@@ -0,0 +1,57 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ViewProps } from 'react-native';
3
+
4
+ export type TipDisplayFrequency =
5
+ 'immediate' | 'hourly' | 'daily' | 'weekly' | 'monthly';
6
+
7
+ export interface TipKitConfiguration {
8
+ /** App-wide interval between new tips. Defaults to `daily`. */
9
+ displayFrequency?: TipDisplayFrequency;
10
+ }
11
+
12
+ export type TipInvalidationReason = 'actionPerformed' | 'tipClosed';
13
+
14
+ export type TipStatus =
15
+ | { status: 'pending' | 'available' }
16
+ | {
17
+ status: 'invalidated';
18
+ reason:
19
+ | TipInvalidationReason
20
+ | 'displayCountExceeded'
21
+ | 'displayDurationExceeded'
22
+ | 'unknown';
23
+ };
24
+
25
+ export interface TipAction {
26
+ id: string;
27
+ title: string;
28
+ }
29
+
30
+ export interface TipError {
31
+ code: string;
32
+ message: string;
33
+ }
34
+
35
+ export interface TipPopoverProps extends Omit<ViewProps, 'children'> {
36
+ /** Anchor content. Its existing touch handlers are preserved. */
37
+ children: ReactNode;
38
+ /** Stable identity used by TipKit to persist this tip's history. */
39
+ tipId: string;
40
+ title: string;
41
+ message?: string;
42
+ systemImage?: string;
43
+ actions?: readonly TipAction[];
44
+ /** Allows presentation when TipKit is also eligible. Defaults to true. */
45
+ enabled?: boolean;
46
+ /** Omit to leave the number of presentations unlimited. */
47
+ maxDisplayCount?: number;
48
+ ignoresDisplayFrequency?: boolean;
49
+ /** Preferred arrow edge on the bubble; UIKit may adapt to available space. */
50
+ arrowEdge?: 'top' | 'bottom' | 'leading' | 'trailing' | 'auto';
51
+ /** TipKit eligibility, independent of whether the bubble is on screen. */
52
+ onStatusChange?: (status: TipStatus) => void;
53
+ onVisibleChange?: (visible: boolean) => void;
54
+ /** Actions do not automatically invalidate the tip. */
55
+ onActionPress?: (action: TipAction) => void;
56
+ onError?: (error: TipError) => void;
57
+ }
@@ -0,0 +1,39 @@
1
+ import type { TipPopoverProps } from './types';
2
+
3
+ export function validateTipId(tipId: string): void {
4
+ if (typeof tipId !== 'string' || tipId.trim().length === 0) {
5
+ throw new Error('[TinyUI] TipKit tipId must be a nonempty string.');
6
+ }
7
+ }
8
+
9
+ export function validateTip(props: TipPopoverProps): void {
10
+ validateTipId(props.tipId);
11
+ if (typeof props.title !== 'string' || props.title.trim().length === 0) {
12
+ throw new Error('[TinyUI] TipKit.Popover title must be a nonempty string.');
13
+ }
14
+ if (
15
+ props.maxDisplayCount !== undefined &&
16
+ (!Number.isInteger(props.maxDisplayCount) ||
17
+ props.maxDisplayCount < 1 ||
18
+ props.maxDisplayCount > 2147483647)
19
+ ) {
20
+ throw new Error(
21
+ '[TinyUI] TipKit.Popover maxDisplayCount must be a positive 32-bit integer.'
22
+ );
23
+ }
24
+ const ids = new Set<string>();
25
+ for (const action of props.actions ?? []) {
26
+ if (
27
+ typeof action.id !== 'string' ||
28
+ action.id.trim().length === 0 ||
29
+ typeof action.title !== 'string' ||
30
+ action.title.trim().length === 0 ||
31
+ ids.has(action.id)
32
+ ) {
33
+ throw new Error(
34
+ '[TinyUI] TipKit.Popover actions need unique nonempty ids and nonempty titles.'
35
+ );
36
+ }
37
+ ids.add(action.id);
38
+ }
39
+ }