@rocapine/react-native-onboarding 1.62.0 → 1.63.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.
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/infra/hooks/index.d.ts +1 -0
- package/dist/infra/hooks/index.d.ts.map +1 -1
- package/dist/infra/hooks/index.js +3 -1
- package/dist/infra/hooks/index.js.map +1 -1
- package/dist/infra/hooks/useProgressHeaderConfig.d.ts +14 -0
- package/dist/infra/hooks/useProgressHeaderConfig.d.ts.map +1 -0
- package/dist/infra/hooks/useProgressHeaderConfig.js +24 -0
- package/dist/infra/hooks/useProgressHeaderConfig.js.map +1 -0
- package/dist/infra/preload/extractAssetUrls.d.ts.map +1 -1
- package/dist/infra/preload/extractAssetUrls.js +67 -0
- package/dist/infra/preload/extractAssetUrls.js.map +1 -1
- package/dist/infra/provider/OnboardingProvider.d.ts.map +1 -1
- package/dist/infra/provider/OnboardingProvider.js +11 -0
- package/dist/infra/provider/OnboardingProvider.js.map +1 -1
- package/dist/onboarding-example.d.ts +1063 -60
- package/dist/onboarding-example.d.ts.map +1 -1
- package/dist/onboarding-example.js +140 -0
- package/dist/onboarding-example.js.map +1 -1
- package/dist/screens/elements/AnimatedTextElement.d.ts +7 -0
- package/dist/screens/elements/AnimatedTextElement.d.ts.map +1 -1
- package/dist/screens/elements/BaseBoxProps.d.ts +39 -0
- package/dist/screens/elements/BaseBoxProps.d.ts.map +1 -1
- package/dist/screens/elements/BaseBoxProps.js +9 -0
- package/dist/screens/elements/BaseBoxProps.js.map +1 -1
- package/dist/screens/elements/ButtonElement.d.ts +28 -0
- package/dist/screens/elements/ButtonElement.d.ts.map +1 -1
- package/dist/screens/elements/CarouselElement.d.ts +38 -0
- package/dist/screens/elements/CarouselElement.d.ts.map +1 -1
- package/dist/screens/elements/CarouselElement.js +1 -0
- package/dist/screens/elements/CarouselElement.js.map +1 -1
- package/dist/screens/elements/CheckboxGroupElement.d.ts +7 -0
- package/dist/screens/elements/CheckboxGroupElement.d.ts.map +1 -1
- package/dist/screens/elements/DatePickerElement.d.ts +7 -0
- package/dist/screens/elements/DatePickerElement.d.ts.map +1 -1
- package/dist/screens/elements/DrawingPadElement.d.ts +7 -0
- package/dist/screens/elements/DrawingPadElement.d.ts.map +1 -1
- package/dist/screens/elements/IconElement.d.ts +7 -0
- package/dist/screens/elements/IconElement.d.ts.map +1 -1
- package/dist/screens/elements/ImageElement.d.ts +26 -0
- package/dist/screens/elements/ImageElement.d.ts.map +1 -1
- package/dist/screens/elements/ImageElement.js +1 -0
- package/dist/screens/elements/ImageElement.js.map +1 -1
- package/dist/screens/elements/InputElement.d.ts +7 -0
- package/dist/screens/elements/InputElement.d.ts.map +1 -1
- package/dist/screens/elements/KeyboardAvoidingViewElement.d.ts +7 -0
- package/dist/screens/elements/KeyboardAvoidingViewElement.d.ts.map +1 -1
- package/dist/screens/elements/LottieElement.d.ts +7 -0
- package/dist/screens/elements/LottieElement.d.ts.map +1 -1
- package/dist/screens/elements/ProgressIndicatorElement.d.ts +7 -0
- package/dist/screens/elements/ProgressIndicatorElement.d.ts.map +1 -1
- package/dist/screens/elements/ProgressiveBlurImageElement.d.ts +7 -0
- package/dist/screens/elements/ProgressiveBlurImageElement.d.ts.map +1 -1
- package/dist/screens/elements/RadioGroupElement.d.ts +7 -0
- package/dist/screens/elements/RadioGroupElement.d.ts.map +1 -1
- package/dist/screens/elements/RepeatElement.d.ts +79 -0
- package/dist/screens/elements/RepeatElement.d.ts.map +1 -0
- package/dist/screens/elements/RepeatElement.js +10 -0
- package/dist/screens/elements/RepeatElement.js.map +1 -0
- package/dist/screens/elements/RichTextElement.d.ts +7 -0
- package/dist/screens/elements/RichTextElement.d.ts.map +1 -1
- package/dist/screens/elements/RiveElement.d.ts +7 -0
- package/dist/screens/elements/RiveElement.d.ts.map +1 -1
- package/dist/screens/elements/SafeAreaViewElement.d.ts +7 -0
- package/dist/screens/elements/SafeAreaViewElement.d.ts.map +1 -1
- package/dist/screens/elements/ScrollViewElement.d.ts +7 -0
- package/dist/screens/elements/ScrollViewElement.d.ts.map +1 -1
- package/dist/screens/elements/SliderElement.d.ts +7 -0
- package/dist/screens/elements/SliderElement.d.ts.map +1 -1
- package/dist/screens/elements/StackElement.d.ts +7 -0
- package/dist/screens/elements/StackElement.d.ts.map +1 -1
- package/dist/screens/elements/TextElement.d.ts +7 -0
- package/dist/screens/elements/TextElement.d.ts.map +1 -1
- package/dist/screens/elements/TypewriterTextElement.d.ts +26 -0
- package/dist/screens/elements/TypewriterTextElement.d.ts.map +1 -1
- package/dist/screens/elements/TypewriterTextElement.js +1 -0
- package/dist/screens/elements/TypewriterTextElement.js.map +1 -1
- package/dist/screens/elements/VideoElement.d.ts +7 -0
- package/dist/screens/elements/VideoElement.d.ts.map +1 -1
- package/dist/screens/elements/WheelPickerElement.d.ts +7 -0
- package/dist/screens/elements/WheelPickerElement.d.ts.map +1 -1
- package/dist/screens/elements/ZStackElement.d.ts +7 -0
- package/dist/screens/elements/ZStackElement.d.ts.map +1 -1
- package/dist/screens/types.d.ts +9 -0
- package/dist/screens/types.d.ts.map +1 -1
- package/dist/screens/types.js +9 -0
- package/dist/screens/types.js.map +1 -1
- package/dist/screens/unknownKeys.d.ts +67 -0
- package/dist/screens/unknownKeys.d.ts.map +1 -0
- package/dist/screens/unknownKeys.js +160 -0
- package/dist/screens/unknownKeys.js.map +1 -0
- package/dist/types.d.ts +73 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/extractAssetUrls.test.ts +104 -0
- package/src/__tests__/unknownKeys.test.ts +234 -0
- package/src/index.ts +8 -0
- package/src/infra/hooks/index.ts +1 -0
- package/src/infra/hooks/useProgressHeaderConfig.ts +21 -0
- package/src/infra/preload/extractAssetUrls.ts +72 -0
- package/src/infra/provider/OnboardingProvider.tsx +14 -0
- package/src/onboarding-example.ts +140 -0
- package/src/screens/elements/BaseBoxProps.ts +56 -0
- package/src/screens/elements/CarouselElement.ts +31 -0
- package/src/screens/elements/ImageElement.ts +16 -0
- package/src/screens/elements/RepeatElement.ts +80 -0
- package/src/screens/elements/TypewriterTextElement.ts +19 -0
- package/src/screens/types.ts +18 -0
- package/src/screens/unknownKeys.ts +211 -0
- package/src/types.ts +86 -0
|
@@ -36,13 +36,33 @@ const mediaTypeToKind = (type: unknown): AssetKind => {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
// An unresolved `{{var}}` placeholder. Such a url is a TEMPLATE, not an address:
|
|
40
|
+
// prefetching it would fire a request for a literal "https://cdn/{{sign}}.png"
|
|
41
|
+
// that always 404s, and the real url isn't knowable until the variable resolves.
|
|
42
|
+
const hasPlaceholder = (url: string): boolean => url.includes("{{");
|
|
43
|
+
|
|
39
44
|
// Push a url with kind, re-tagging SVG images so the runner HTTP-warms them.
|
|
40
45
|
const pushAsset = (out: AssetRef[], url: unknown, kind: AssetKind): void => {
|
|
41
46
|
if (typeof url !== "string" || url.length === 0) return;
|
|
47
|
+
// Skip templates. Reached by an `Image` with `mode: "expression"`, and by the
|
|
48
|
+
// template inside a `Repeat` (whose per-row urls are pushed separately, below,
|
|
49
|
+
// where the row data makes them resolvable).
|
|
50
|
+
if (hasPlaceholder(url)) return;
|
|
42
51
|
const finalKind: AssetKind = kind === "image" && isSvgUrl(url) ? "image-svg" : kind;
|
|
43
52
|
out.push({ url, kind: finalKind });
|
|
44
53
|
};
|
|
45
54
|
|
|
55
|
+
// Resolve `{{scope.field}}` against one Repeat row. Only the row scope is
|
|
56
|
+
// substituted — anything referencing a runtime variable stays a placeholder and
|
|
57
|
+
// is dropped by `pushAsset`, which is correct: it still isn't knowable up front.
|
|
58
|
+
const resolveRowUrl = (url: string, row: Record<string, unknown>, scope: string): string =>
|
|
59
|
+
url.replace(/\{\{([^}]+?)\}\}/g, (match, key: string) => {
|
|
60
|
+
const trimmed = key.trim();
|
|
61
|
+
if (!trimmed.startsWith(`${scope}.`)) return match;
|
|
62
|
+
const value = row[trimmed.slice(scope.length + 1)];
|
|
63
|
+
return value == null ? match : String(value);
|
|
64
|
+
});
|
|
65
|
+
|
|
46
66
|
// A `{ type, url }` MediaSource is remote (prefetchable); a `{ type, localPathId }`
|
|
47
67
|
// MediaSource is a bundled asset — skip it.
|
|
48
68
|
const pushMediaSource = (out: AssetRef[], media: any): void => {
|
|
@@ -76,11 +96,63 @@ const walkElement = (out: AssetRef[], element: any): void => {
|
|
|
76
96
|
break;
|
|
77
97
|
}
|
|
78
98
|
|
|
99
|
+
// A `Repeat` renders its template once per row, so the assets it actually
|
|
100
|
+
// shows are the template's url props resolved against each row — the template
|
|
101
|
+
// string itself is unfetchable and was skipped above. Walk the template once
|
|
102
|
+
// per row with the row substituted in, so repeated media still preloads.
|
|
103
|
+
if (element.type === "Repeat" && Array.isArray(props.data)) {
|
|
104
|
+
const scope = typeof props.as === "string" && props.as ? props.as : "item";
|
|
105
|
+
for (const row of props.data) {
|
|
106
|
+
if (!row || typeof row !== "object") continue;
|
|
107
|
+
const resolved: AssetRef[] = [];
|
|
108
|
+
if (Array.isArray(element.children)) {
|
|
109
|
+
for (const child of element.children) walkElementWithRow(resolved, child, row, scope);
|
|
110
|
+
}
|
|
111
|
+
out.push(...resolved);
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
79
116
|
if (Array.isArray(element.children)) {
|
|
80
117
|
for (const child of element.children) walkElement(out, child);
|
|
81
118
|
}
|
|
82
119
|
};
|
|
83
120
|
|
|
121
|
+
// `walkElement`, but url props are resolved against a Repeat row first. Separate
|
|
122
|
+
// from `walkElement` so the ordinary path stays allocation-free.
|
|
123
|
+
const walkElementWithRow = (
|
|
124
|
+
out: AssetRef[],
|
|
125
|
+
element: any,
|
|
126
|
+
row: Record<string, unknown>,
|
|
127
|
+
scope: string
|
|
128
|
+
): void => {
|
|
129
|
+
if (!element || typeof element !== "object") return;
|
|
130
|
+
const props = element.props ?? {};
|
|
131
|
+
const resolve = (u: unknown) => (typeof u === "string" ? resolveRowUrl(u, row, scope) : u);
|
|
132
|
+
|
|
133
|
+
switch (element.type) {
|
|
134
|
+
case "Image":
|
|
135
|
+
case "ProgressiveBlurImage":
|
|
136
|
+
pushAsset(out, resolve(props.url), "image");
|
|
137
|
+
break;
|
|
138
|
+
case "Video":
|
|
139
|
+
pushAsset(out, resolve(props.url), "video");
|
|
140
|
+
break;
|
|
141
|
+
case "Lottie":
|
|
142
|
+
pushAsset(out, resolve(props.source), "lottie");
|
|
143
|
+
break;
|
|
144
|
+
case "Rive":
|
|
145
|
+
pushAsset(out, resolve(props.url), "rive");
|
|
146
|
+
break;
|
|
147
|
+
default:
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (Array.isArray(element.children)) {
|
|
152
|
+
for (const child of element.children) walkElementWithRow(out, child, row, scope);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
84
156
|
// Collect every remote asset from one step. Defensive: a malformed step throws
|
|
85
157
|
// here and is swallowed by the per-step guard in extractAssetUrls.
|
|
86
158
|
const extractFromStep = (out: AssetRef[], step: BaseStepType): void => {
|
|
@@ -8,6 +8,7 @@ import { ComposableVariableEntry } from "../../steps/ComposableScreen/types";
|
|
|
8
8
|
import { FontLoaderGate } from "./FontLoader";
|
|
9
9
|
import { extractAssetUrls } from "../preload/extractAssetUrls";
|
|
10
10
|
import { preloadAssets } from "../preload/preloadAssets";
|
|
11
|
+
import { collectUnknownKeysInSteps, formatUnknownElementKeys } from "../../screens/unknownKeys";
|
|
11
12
|
import { OnboardingNavigationAdapter } from "../navigation/types";
|
|
12
13
|
import { expoRouterAdapter } from "../navigation/expoRouterAdapter";
|
|
13
14
|
import { useProducts } from "../../products/useProducts";
|
|
@@ -15,6 +16,9 @@ import { ProductProvider, ProductRef, ProductRuntime } from "../../products/type
|
|
|
15
16
|
import { useProductRuntime } from "../../products/ProductRuntimeContext";
|
|
16
17
|
import { mergeProductRuntimes } from "../../products/mergeProductRuntimes";
|
|
17
18
|
|
|
19
|
+
// React Native's dev flag; guarded at every use so non-RN consumers are fine.
|
|
20
|
+
declare const __DEV__: boolean;
|
|
21
|
+
|
|
18
22
|
const queryClient = new QueryClient({
|
|
19
23
|
defaultOptions: {
|
|
20
24
|
queries: {
|
|
@@ -173,6 +177,16 @@ const OnboardingDataGate = ({
|
|
|
173
177
|
if (!data || preloadedRef.current === data) return;
|
|
174
178
|
preloadedRef.current = data;
|
|
175
179
|
preloadAssets(extractAssetUrls(data));
|
|
180
|
+
|
|
181
|
+
// Dev-only payload diagnostic: report keys sitting at an element's top level
|
|
182
|
+
// that the schema silently drops (classically `animation` outside `props`,
|
|
183
|
+
// which parses, renders, and simply never animates). Non-fatal by design —
|
|
184
|
+
// rejecting these would turn a no-op into a broken screen. Dev-gated and run
|
|
185
|
+
// once per payload, so it costs production nothing.
|
|
186
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
187
|
+
const report = formatUnknownElementKeys(collectUnknownKeysInSteps(data.steps));
|
|
188
|
+
if (report) console.warn(report);
|
|
189
|
+
}
|
|
176
190
|
}, [data]);
|
|
177
191
|
|
|
178
192
|
if (error) throw error;
|
|
@@ -341,6 +341,24 @@ export const onboardingExample = {
|
|
|
341
341
|
marginVertical: 8,
|
|
342
342
|
},
|
|
343
343
|
},
|
|
344
|
+
{
|
|
345
|
+
// Cursor mode types characters in progressively, so the block would
|
|
346
|
+
// grow 1 -> 2 lines and shove everything below it down the screen.
|
|
347
|
+
// `reserveSpace` lays the finished string out invisibly first and
|
|
348
|
+
// overlays the animation, so the siblings never move. It measures
|
|
349
|
+
// the real resolved string, so it stays right in every locale.
|
|
350
|
+
id: "typewriter-reserved",
|
|
351
|
+
type: "TypewriterText",
|
|
352
|
+
props: {
|
|
353
|
+
content: "Meet your AI journal companion",
|
|
354
|
+
cursor: true,
|
|
355
|
+
reserveSpace: true,
|
|
356
|
+
stagger: 40,
|
|
357
|
+
fontSize: 16,
|
|
358
|
+
textAlign: "center",
|
|
359
|
+
marginVertical: 8,
|
|
360
|
+
},
|
|
361
|
+
},
|
|
344
362
|
{
|
|
345
363
|
id: "hero-video",
|
|
346
364
|
type: "Video",
|
|
@@ -860,6 +878,10 @@ export const onboardingExample = {
|
|
|
860
878
|
marginVertical: 8,
|
|
861
879
|
defaultIndex: 0,
|
|
862
880
|
variableName: "carouselPage",
|
|
881
|
+
// Snap-time variable (`carouselPage`) steps 0 -> 1 -> 2. This one
|
|
882
|
+
// tracks the finger continuously, so siblings can animate DURING
|
|
883
|
+
// the swipe instead of after it lands.
|
|
884
|
+
progressVariableName: "carouselProgress",
|
|
863
885
|
},
|
|
864
886
|
children: [
|
|
865
887
|
{
|
|
@@ -891,6 +913,104 @@ export const onboardingExample = {
|
|
|
891
913
|
},
|
|
892
914
|
],
|
|
893
915
|
},
|
|
916
|
+
{
|
|
917
|
+
// Gated on the CONTINUOUS position: `eq` compares the rounded value,
|
|
918
|
+
// so this mounts (and fades in) once the swipe passes halfway to
|
|
919
|
+
// slide 2 -- not when it snaps. Because the published value is
|
|
920
|
+
// normalized to [0, childCount), it behaves identically on every lap
|
|
921
|
+
// even though `loop` is on.
|
|
922
|
+
id: "carousel-swipe-reveal",
|
|
923
|
+
type: "Text",
|
|
924
|
+
renderWhen: { variable: "carouselProgress", operator: "eq", value: 1 },
|
|
925
|
+
props: {
|
|
926
|
+
// `animation` is a BaseBoxProp -- inside `props`, not top level.
|
|
927
|
+
animation: { entering: { preset: "FadeInDown", duration: 300 } },
|
|
928
|
+
content: "Revealed mid-swipe on slide 2",
|
|
929
|
+
fontSize: 13,
|
|
930
|
+
textAlign: "center",
|
|
931
|
+
marginVertical: 2,
|
|
932
|
+
},
|
|
933
|
+
},
|
|
934
|
+
{
|
|
935
|
+
// Data-driven Image: ONE element instead of one duplicated subtree
|
|
936
|
+
// per case. The URL rebuilds as `carouselPage` changes, so paging
|
|
937
|
+
// the carousel swaps this image. `{{var}}` resolves to the
|
|
938
|
+
// variable's VALUE (not its label) — a URL segment is an identifier.
|
|
939
|
+
id: "carousel-derived-image",
|
|
940
|
+
type: "Image",
|
|
941
|
+
props: {
|
|
942
|
+
url: "https://picsum.photos/seed/{{carouselPage}}/120/120",
|
|
943
|
+
mode: "expression",
|
|
944
|
+
width: 120,
|
|
945
|
+
height: 120,
|
|
946
|
+
borderRadius: 12,
|
|
947
|
+
alignSelf: "center",
|
|
948
|
+
marginVertical: 4,
|
|
949
|
+
},
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
// `animation.replayWhen`: re-fires the entering animation each
|
|
953
|
+
// time `carouselPage` changes, WITHOUT the element disappearing.
|
|
954
|
+
// Previously the only way to replay was to toggle `renderWhen`,
|
|
955
|
+
// which couples "animate again" to "change visibility".
|
|
956
|
+
id: "carousel-replay-label",
|
|
957
|
+
type: "Text",
|
|
958
|
+
props: {
|
|
959
|
+
content: "Slide {{carouselPage}}",
|
|
960
|
+
mode: "expression",
|
|
961
|
+
fontSize: 14,
|
|
962
|
+
fontWeight: "600",
|
|
963
|
+
textAlign: "center",
|
|
964
|
+
marginVertical: 2,
|
|
965
|
+
animation: {
|
|
966
|
+
entering: { preset: "FadeInUp", duration: 260 },
|
|
967
|
+
replayWhen: "carouselPage",
|
|
968
|
+
},
|
|
969
|
+
},
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
// `Repeat`: ONE template materialized per row of payload-authored
|
|
973
|
+
// data, instead of three near-identical hand-written subtrees.
|
|
974
|
+
// Layout-transparent, so these rows become children of the
|
|
975
|
+
// enclosing YStack and its `gap` applies between them.
|
|
976
|
+
// Row fields are exposed as `{{item.*}}`; `item.index` is always
|
|
977
|
+
// available. A `renderWhen` on the template gates per row, which
|
|
978
|
+
// is how Repeat also covers the "switch" case without a separate
|
|
979
|
+
// Match element.
|
|
980
|
+
id: "feature-rows",
|
|
981
|
+
type: "Repeat",
|
|
982
|
+
props: {
|
|
983
|
+
keyField: "key",
|
|
984
|
+
data: [
|
|
985
|
+
{ key: "track", label: "Track every workout" },
|
|
986
|
+
{ key: "plan", label: "Plan your week" },
|
|
987
|
+
{ key: "coach", label: "Coaching that adapts" },
|
|
988
|
+
],
|
|
989
|
+
},
|
|
990
|
+
children: [
|
|
991
|
+
{
|
|
992
|
+
id: "feature-row",
|
|
993
|
+
type: "XStack",
|
|
994
|
+
props: { gap: 10, alignItems: "center", marginVertical: 2 },
|
|
995
|
+
children: [
|
|
996
|
+
{
|
|
997
|
+
// Static: `Icon.name` has no `mode`, so it does NOT
|
|
998
|
+
// interpolate — `{{item.icon}}` here would render as a
|
|
999
|
+
// literal, unmatched icon name. Only props documented as
|
|
1000
|
+
// supporting `expression` accept `{{var}}`.
|
|
1001
|
+
id: "feature-icon",
|
|
1002
|
+
type: "Icon",
|
|
1003
|
+
props: { name: "check", size: 18 },
|
|
1004
|
+
},
|
|
1005
|
+
{
|
|
1006
|
+
id: "feature-label",
|
|
1007
|
+
type: "Text",
|
|
1008
|
+
props: { content: "{{item.label}}", mode: "expression", fontSize: 15 },
|
|
1009
|
+
},
|
|
1010
|
+
],
|
|
1011
|
+
},
|
|
1012
|
+
],
|
|
1013
|
+
},
|
|
894
1014
|
{
|
|
895
1015
|
id: "carousel-page-label",
|
|
896
1016
|
type: "Text",
|
|
@@ -985,6 +1105,26 @@ export const onboardingExample = {
|
|
|
985
1105
|
},
|
|
986
1106
|
],
|
|
987
1107
|
},
|
|
1108
|
+
{
|
|
1109
|
+
// `inset`: declarative off-anchor placement. Supplying one side
|
|
1110
|
+
// per axis leaves this content-sized and pinned by its top-left
|
|
1111
|
+
// corner, instead of doing the arithmetic with
|
|
1112
|
+
// transform.translateX/Y. Percentages keep it stable across
|
|
1113
|
+
// device widths. Honoured only on a ZStack child.
|
|
1114
|
+
id: "zstack-inset-badge",
|
|
1115
|
+
type: "Text",
|
|
1116
|
+
props: {
|
|
1117
|
+
inset: { top: "12%", left: "62%" },
|
|
1118
|
+
content: "NEW",
|
|
1119
|
+
fontSize: 12,
|
|
1120
|
+
fontWeight: "700",
|
|
1121
|
+
color: "#fff",
|
|
1122
|
+
backgroundColor: "#E76F51",
|
|
1123
|
+
paddingHorizontal: 8,
|
|
1124
|
+
paddingVertical: 4,
|
|
1125
|
+
borderRadius: 999,
|
|
1126
|
+
},
|
|
1127
|
+
},
|
|
988
1128
|
],
|
|
989
1129
|
},
|
|
990
1130
|
{
|
|
@@ -244,6 +244,26 @@ export type ElementAnimation = {
|
|
|
244
244
|
exiting?: ExitingAnimation;
|
|
245
245
|
layout?: LayoutAnimation;
|
|
246
246
|
effect?: ElementEffect;
|
|
247
|
+
/**
|
|
248
|
+
* Replay `entering` whenever the named variable's VALUE changes.
|
|
249
|
+
*
|
|
250
|
+
* Reanimated fires an `entering` builder on mount and never again, so without
|
|
251
|
+
* this the only way to re-run an entrance is to unmount and remount the
|
|
252
|
+
* element — which today means toggling `renderWhen`, i.e. you cannot replay
|
|
253
|
+
* without also changing visibility. This covers the case where the element
|
|
254
|
+
* stays on screen and should re-animate because something it depends on
|
|
255
|
+
* changed (a recalculated total, the answer to the question above it).
|
|
256
|
+
*
|
|
257
|
+
* Mechanism, because it has a visible consequence: the element's subtree is
|
|
258
|
+
* remounted (its React key is derived from the variable's value). Any
|
|
259
|
+
* transient state inside it resets — an `Input`'s uncommitted text, a
|
|
260
|
+
* `Carousel`'s scroll position — and a continuous `animation.effect` restarts.
|
|
261
|
+
* Use it on presentational subtrees; avoid wrapping inputs in one.
|
|
262
|
+
*
|
|
263
|
+
* The first render is not a replay: the key only changes on a subsequent
|
|
264
|
+
* write, so `entering` still fires exactly once on mount.
|
|
265
|
+
*/
|
|
266
|
+
replayWhen?: string;
|
|
247
267
|
};
|
|
248
268
|
|
|
249
269
|
const ElementAnimationSchema = z.object({
|
|
@@ -251,6 +271,35 @@ const ElementAnimationSchema = z.object({
|
|
|
251
271
|
exiting: ExitingAnimationSchema.optional(),
|
|
252
272
|
layout: LayoutAnimationSchema.optional(),
|
|
253
273
|
effect: EffectSchema.optional(),
|
|
274
|
+
replayWhen: z.string().min(1).optional(),
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// Declarative absolute placement for a ZStack child. Numbers are density-
|
|
278
|
+
// independent pixels; strings are percentages of the stack ("62.1%") — the same
|
|
279
|
+
// number|string convention `width`/`height` already use via `dim()`.
|
|
280
|
+
//
|
|
281
|
+
// ONLY honoured on a direct child of a `ZStack`, because that is the only
|
|
282
|
+
// container that absolutely-positions its children; elsewhere it is inert.
|
|
283
|
+
//
|
|
284
|
+
// A side you omit is NOT treated as 0 — it falls back to the ZStack's shared
|
|
285
|
+
// anchor for that axis, so partial placement works (`{ top: 40 }` pins vertically
|
|
286
|
+
// while still honouring the anchor horizontally). Supplying exactly one side per
|
|
287
|
+
// axis (`top` + `left`) leaves the child content-sized and pinned by that corner,
|
|
288
|
+
// which is what a drag-to-place gesture means; supplying BOTH sides of an axis
|
|
289
|
+
// resolves to a width/height instead, which stretches the child.
|
|
290
|
+
export type ElementInset = {
|
|
291
|
+
top?: number | string;
|
|
292
|
+
left?: number | string;
|
|
293
|
+
right?: number | string;
|
|
294
|
+
bottom?: number | string;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const InsetSide = z.union([z.number(), z.string()]);
|
|
298
|
+
const InsetSchema = z.object({
|
|
299
|
+
top: InsetSide.optional(),
|
|
300
|
+
left: InsetSide.optional(),
|
|
301
|
+
right: InsetSide.optional(),
|
|
302
|
+
bottom: InsetSide.optional(),
|
|
254
303
|
});
|
|
255
304
|
|
|
256
305
|
// Static transform surface — also what `effect` animates at runtime.
|
|
@@ -303,6 +352,12 @@ export type BaseBoxProps = {
|
|
|
303
352
|
shadowOpacity?: number;
|
|
304
353
|
shadowRadius?: number;
|
|
305
354
|
elevation?: number;
|
|
355
|
+
/**
|
|
356
|
+
* Declarative absolute placement inside a `ZStack` (ignored elsewhere).
|
|
357
|
+
* Replaces doing the arithmetic by hand with `transform.translateX/Y`;
|
|
358
|
+
* composes with `transform` rather than replacing it.
|
|
359
|
+
*/
|
|
360
|
+
inset?: ElementInset;
|
|
306
361
|
transform?: ElementTransform;
|
|
307
362
|
animation?: ElementAnimation;
|
|
308
363
|
/**
|
|
@@ -344,6 +399,7 @@ export const BaseBoxPropsSchema = z.object({
|
|
|
344
399
|
shadowOpacity: z.number().min(0).max(1).optional(),
|
|
345
400
|
shadowRadius: z.number().min(0).optional(),
|
|
346
401
|
elevation: z.number().min(0).optional(),
|
|
402
|
+
inset: InsetSchema.optional(),
|
|
347
403
|
transform: TransformSchema.optional(),
|
|
348
404
|
animation: ElementAnimationSchema.optional(),
|
|
349
405
|
onPress: z.array(ButtonActionSchema).optional(),
|
|
@@ -19,6 +19,36 @@ export type CarouselElementProps = BaseBoxProps & {
|
|
|
19
19
|
dotsMarginBottom?: number;
|
|
20
20
|
defaultIndex?: number | null;
|
|
21
21
|
variableName?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Publishes the carousel's *continuous* swipe position as a screen-scoped
|
|
24
|
+
* animated variable, so sibling elements can gate `renderWhen` on the finger
|
|
25
|
+
* rather than on the settled slide.
|
|
26
|
+
*
|
|
27
|
+
* `variableName` is written only on snap, so it steps 0 → 1 → 2. This tracks
|
|
28
|
+
* the drag: 0 → 0.37 → 0.81 → 1, updating every frame.
|
|
29
|
+
*
|
|
30
|
+
* Value semantics — ALWAYS normalized to `[0, childCount)`:
|
|
31
|
+
* • the underlying `absoluteProgress` from react-native-reanimated-carousel
|
|
32
|
+
* is clamped to `[0, n-1]` when `loop: false`, but is UNBOUNDED when
|
|
33
|
+
* `loop: true` (the library never wraps its internal offset — on the
|
|
34
|
+
* second lap slide 1 reports 4, not 1, and it keeps climbing).
|
|
35
|
+
* • `loop` defaults to TRUE here, so publishing the raw value would silently
|
|
36
|
+
* break any `eq`/`lt`/`gte` gate after the first lap. We therefore publish
|
|
37
|
+
* `((raw % n) + n) % n`, which is a no-op for `loop: false` and makes every
|
|
38
|
+
* lap read identically.
|
|
39
|
+
* • consequence: under `loop: true` the value is discontinuous at the wrap
|
|
40
|
+
* seam, jumping from just under `n` back to 0. That is the same seam the
|
|
41
|
+
* dots cross, so it matches what the user sees.
|
|
42
|
+
*
|
|
43
|
+
* Consumed on the UI thread — see `AnimatedVariablesContext` / `GatedElement`.
|
|
44
|
+
* Note `eq` compares the ROUNDED value, so `eq 1` flips once the swipe passes
|
|
45
|
+
* halfway to slide 1 (that is the intended "fade in during the gesture" feel).
|
|
46
|
+
*
|
|
47
|
+
* Safe to set to the same string as `variableName`: the store then holds the
|
|
48
|
+
* snapped integer for branching/analytics while gates on this screen read the
|
|
49
|
+
* live value, since an animated variable takes precedence in `GatedElement`.
|
|
50
|
+
*/
|
|
51
|
+
progressVariableName?: string;
|
|
22
52
|
};
|
|
23
53
|
|
|
24
54
|
export const CarouselElementPropsSchema = BaseBoxPropsSchema.extend({
|
|
@@ -39,4 +69,5 @@ export const CarouselElementPropsSchema = BaseBoxPropsSchema.extend({
|
|
|
39
69
|
dotsMarginBottom: z.number().optional().default(0),
|
|
40
70
|
defaultIndex: z.number().int().nonnegative().nullable().optional(),
|
|
41
71
|
variableName: z.string().min(1).optional(),
|
|
72
|
+
progressVariableName: z.string().min(1).optional(),
|
|
42
73
|
});
|
|
@@ -3,6 +3,21 @@ import { BaseBoxProps, BaseBoxPropsSchema } from "./BaseBoxProps";
|
|
|
3
3
|
|
|
4
4
|
export type ImageElementProps = BaseBoxProps & {
|
|
5
5
|
url: string;
|
|
6
|
+
/**
|
|
7
|
+
* `expression` enables `{{variable}}` interpolation in `url`, so ONE Image can
|
|
8
|
+
* serve a data-driven set instead of one duplicated subtree per case — e.g.
|
|
9
|
+
* `https://cdn.example.com/zodiac/{{zodiacSign}}.png` replaces 13 gated Images.
|
|
10
|
+
*
|
|
11
|
+
* References resolve to the variable's `value`, NOT its `label` (the inverse of
|
|
12
|
+
* `Text`, which is display copy). A URL segment is a machine identifier: for a
|
|
13
|
+
* variable carrying `{ value: "aries", label: "Aries" }` the URL needs `aries`.
|
|
14
|
+
* An unknown variable interpolates to the empty string, so authors should keep
|
|
15
|
+
* a fallback path segment or a `renderWhen` guard around the element.
|
|
16
|
+
*
|
|
17
|
+
* Defaults to `"plain"` — no interpolation, and the element stays fully static
|
|
18
|
+
* (it does not subscribe to variable writes).
|
|
19
|
+
*/
|
|
20
|
+
mode?: "plain" | "expression";
|
|
6
21
|
aspectRatio?: number;
|
|
7
22
|
resizeMode?: "cover" | "contain" | "stretch" | "center";
|
|
8
23
|
/** Uniform Gaussian blur radius (px). 0/undefined = sharp. Ignored for SVGs. */
|
|
@@ -11,6 +26,7 @@ export type ImageElementProps = BaseBoxProps & {
|
|
|
11
26
|
|
|
12
27
|
export const ImageElementPropsSchema = BaseBoxPropsSchema.extend({
|
|
13
28
|
url: z.string().min(1, "url must not be empty"),
|
|
29
|
+
mode: z.enum(["plain", "expression"]).optional(),
|
|
14
30
|
aspectRatio: z.number().optional(),
|
|
15
31
|
resizeMode: z.enum(["cover", "contain", "stretch", "center"]).optional(),
|
|
16
32
|
blurRadius: z.number().min(0).optional(),
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Materializes its `children` (the template) once per row of `data`.
|
|
5
|
+
*
|
|
6
|
+
* Solves the duplicated-subtree problem: a screen with one card design and six
|
|
7
|
+
* cards, or one reveal design and thirteen zodiac signs, otherwise needs the
|
|
8
|
+
* subtree copy-pasted N times, and every copy or style change becomes an N-fold
|
|
9
|
+
* edit. That duplication has already produced real drift in shipped screens.
|
|
10
|
+
*
|
|
11
|
+
* **Repeat plus a per-row gate is a switch**, so there is no separate `Match`
|
|
12
|
+
* element: give the template's root a `renderWhen` of
|
|
13
|
+
* `{ variable: "item.sign", operator: "eq", value: "{{zodiacSign}}" }`-style
|
|
14
|
+
* shape and exactly one row renders. Iterate-and-show-all and
|
|
15
|
+
* iterate-and-show-one are the same primitive.
|
|
16
|
+
*
|
|
17
|
+
* ## Scope
|
|
18
|
+
*
|
|
19
|
+
* Each row's fields are exposed to that row's subtree under the `as` prefix
|
|
20
|
+
* (default `item`), so `{{item.title}}` interpolates and
|
|
21
|
+
* `{ variable: "item.sign", ... }` gates. `item.index` is always present.
|
|
22
|
+
*
|
|
23
|
+
* The scope reaches BOTH render-time reads (`{{var}}` interpolation,
|
|
24
|
+
* `renderWhen`) and press-time reads (a `setVariable` action with
|
|
25
|
+
* `valueMode: "expression"` referencing `{{item.id}}`), which is what lets a
|
|
26
|
+
* repeated card write its own row's value when tapped. Without the press-time
|
|
27
|
+
* half a repeated grid could be drawn but not answered.
|
|
28
|
+
*
|
|
29
|
+
* Scoped values are READ-ONLY. Nothing writes back into a row; an interactive
|
|
30
|
+
* child still writes to the ordinary variable store, and because the template is
|
|
31
|
+
* shared, every row's child writes the SAME variable name. That is usually what
|
|
32
|
+
* you want for single-select (the row distinguishes itself through the *value*
|
|
33
|
+
* it writes, not the variable it writes to).
|
|
34
|
+
*
|
|
35
|
+
* ## Data lives in the payload
|
|
36
|
+
*
|
|
37
|
+
* `data` is authored in the step, not sourced from a variable holding JSON. That
|
|
38
|
+
* is deliberate: it keeps copy and asset URLs in the studio where designers and
|
|
39
|
+
* the translation pipeline are. Rows sourced from the app would move product copy
|
|
40
|
+
* into the binary, where a typo fix needs a store release and i18n never sees it.
|
|
41
|
+
*
|
|
42
|
+
* For the same reason, a translatable string in a row carries its own literal
|
|
43
|
+
* i18n key (`{ sign: "aries", titleKey: "zodiac_aries_title" }`) rather than a
|
|
44
|
+
* derived one. Key coverage is computed by scanning payloads for *literal* key
|
|
45
|
+
* strings, so a computed key (`"zodiac_{{item.sign}}_title"`) would make the
|
|
46
|
+
* scanner find nothing, report the screen fully translated, and ship untranslated
|
|
47
|
+
* rows. Literal keys per row keep that machinery working untouched.
|
|
48
|
+
*
|
|
49
|
+
* ## Layout
|
|
50
|
+
*
|
|
51
|
+
* Repeat renders no view of its own — the materialized rows become direct
|
|
52
|
+
* children of whatever contains the Repeat, so the parent's `gap`, direction and
|
|
53
|
+
* alignment apply per row exactly as if the rows had been hand-written. Put a
|
|
54
|
+
* Repeat inside a `YStack`/`XStack`/`ZStack` and lay the rows out there.
|
|
55
|
+
*
|
|
56
|
+
* This is why the props below do NOT extend `BaseBoxProps`: with no view to style,
|
|
57
|
+
* box props would silently do nothing.
|
|
58
|
+
*/
|
|
59
|
+
export type RepeatElementProps = {
|
|
60
|
+
/**
|
|
61
|
+
* One record per materialization. Flat scalars only — nested objects are not
|
|
62
|
+
* addressable by `{{item.x}}` and are rejected.
|
|
63
|
+
*/
|
|
64
|
+
data: Array<Record<string, string | number | boolean>>;
|
|
65
|
+
/** Prefix the row's fields are exposed under. Default `"item"`. */
|
|
66
|
+
as?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Row field used to build each materialized element's id suffix and React key
|
|
69
|
+
* (`card` → `card__aries`). Falls back to the row index when unset or missing.
|
|
70
|
+
* Prefer setting it: ids stay meaningful in diagnostics, and identity survives
|
|
71
|
+
* a reordering of `data`.
|
|
72
|
+
*/
|
|
73
|
+
keyField?: string;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const RepeatElementPropsSchema = z.object({
|
|
77
|
+
data: z.array(z.record(z.string(), z.union([z.string(), z.number(), z.boolean()]))),
|
|
78
|
+
as: z.string().min(1).optional(),
|
|
79
|
+
keyField: z.string().min(1).optional(),
|
|
80
|
+
});
|
|
@@ -56,6 +56,24 @@ export type TypewriterTextElementProps = BaseBoxProps & {
|
|
|
56
56
|
cursor?: boolean;
|
|
57
57
|
/** Caret glyph when `cursor` is on. Default "|". */
|
|
58
58
|
cursorChar?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Reserve the fully-revealed text's layout box up front, so the element never
|
|
61
|
+
* grows as it reveals and never pushes its siblings down.
|
|
62
|
+
*
|
|
63
|
+
* Only meaningful with `cursor: true`. Without a cursor every character is
|
|
64
|
+
* already mounted from frame 0 and only its opacity/transform animates, so the
|
|
65
|
+
* box is stable and this is a no-op. With `cursor` the characters mount
|
|
66
|
+
* progressively, so an unreserved block grows 1 → 2 → 3 lines mid-reveal and
|
|
67
|
+
* shoves everything below it down the screen.
|
|
68
|
+
*
|
|
69
|
+
* Implemented by laying out the fully resolved string invisibly to establish the
|
|
70
|
+
* box, then overlaying the animating characters on top of it. Because the
|
|
71
|
+
* reservation measures the REAL resolved string, it stays correct per locale —
|
|
72
|
+
* a hardcoded wrapper height is what breaks when e.g. `fr` runs 15-20% longer.
|
|
73
|
+
*
|
|
74
|
+
* Default false (unchanged behaviour).
|
|
75
|
+
*/
|
|
76
|
+
reserveSpace?: boolean;
|
|
59
77
|
fontSize?: number;
|
|
60
78
|
fontWeight?: string;
|
|
61
79
|
/**
|
|
@@ -83,6 +101,7 @@ export const TypewriterTextElementPropsSchema = BaseBoxPropsSchema.extend({
|
|
|
83
101
|
loopDelay: z.number().min(0).optional(),
|
|
84
102
|
cursor: z.boolean().optional(),
|
|
85
103
|
cursorChar: z.string().optional(),
|
|
104
|
+
reserveSpace: z.boolean().optional(),
|
|
86
105
|
fontSize: z.number().optional(),
|
|
87
106
|
fontWeight: z.string().optional(),
|
|
88
107
|
fontFamily: z.string().optional(),
|
package/src/screens/types.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { type CheckboxGroupElementProps, CheckboxGroupElementPropsSchema } from
|
|
|
24
24
|
import { type DatePickerElementProps, DatePickerElementPropsSchema } from "./elements/DatePickerElement";
|
|
25
25
|
import { type WheelPickerElementProps, WheelPickerElementPropsSchema } from "./elements/WheelPickerElement";
|
|
26
26
|
import { type CarouselElementProps, CarouselElementPropsSchema } from "./elements/CarouselElement";
|
|
27
|
+
import { type RepeatElementProps, RepeatElementPropsSchema } from "./elements/RepeatElement";
|
|
27
28
|
import { type ZStackElementProps, ZStackElementPropsSchema } from "./elements/ZStackElement";
|
|
28
29
|
import { type SafeAreaViewElementProps, SafeAreaViewElementPropsSchema } from "./elements/SafeAreaViewElement";
|
|
29
30
|
import { type ScrollViewElementProps, ScrollViewElementPropsSchema } from "./elements/ScrollViewElement";
|
|
@@ -79,6 +80,7 @@ export type { DatePickerElementProps } from "./elements/DatePickerElement";
|
|
|
79
80
|
export type { WheelPickerElementProps, WheelPickerItem, WheelPickerRange } from "./elements/WheelPickerElement";
|
|
80
81
|
export { WheelPickerElementPropsSchema, generateWheelPickerRangeItems, resolveWheelPickerItems } from "./elements/WheelPickerElement";
|
|
81
82
|
export type { CarouselElementProps } from "./elements/CarouselElement";
|
|
83
|
+
export type { RepeatElementProps } from "./elements/RepeatElement";
|
|
82
84
|
export type { ZStackElementProps } from "./elements/ZStackElement";
|
|
83
85
|
export type { SafeAreaViewElementProps, SafeAreaEdge, SafeAreaEdgeMode } from "./elements/SafeAreaViewElement";
|
|
84
86
|
export type { ScrollViewElementProps, ScrollViewContentInset } from "./elements/ScrollViewElement";
|
|
@@ -227,6 +229,14 @@ export type UIElement =
|
|
|
227
229
|
props: CarouselElementProps;
|
|
228
230
|
children: UIElement[];
|
|
229
231
|
}
|
|
232
|
+
| {
|
|
233
|
+
id: string;
|
|
234
|
+
name?: string;
|
|
235
|
+
renderWhen?: LeafCondition | ConditionGroup;
|
|
236
|
+
type: "Repeat";
|
|
237
|
+
props: RepeatElementProps;
|
|
238
|
+
children: UIElement[];
|
|
239
|
+
}
|
|
230
240
|
| {
|
|
231
241
|
id: string;
|
|
232
242
|
name?: string;
|
|
@@ -417,6 +427,14 @@ export const UIElementSchema: z.ZodType<UIElement> = z.lazy(() =>
|
|
|
417
427
|
props: CarouselElementPropsSchema,
|
|
418
428
|
children: z.array(UIElementSchema),
|
|
419
429
|
}),
|
|
430
|
+
z.object({
|
|
431
|
+
id: z.string(),
|
|
432
|
+
name: z.string().optional(),
|
|
433
|
+
renderWhen: z.union([LeafConditionSchema, ConditionGroupSchema]).optional(),
|
|
434
|
+
type: z.literal("Repeat"),
|
|
435
|
+
props: RepeatElementPropsSchema,
|
|
436
|
+
children: z.array(UIElementSchema),
|
|
437
|
+
}),
|
|
420
438
|
z.object({
|
|
421
439
|
id: z.string(),
|
|
422
440
|
name: z.string().optional(),
|