@rocapine/react-native-onboarding 1.16.0 → 1.17.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 (70) hide show
  1. package/dist/infra/fonts/FontRegistryContext.d.ts +16 -0
  2. package/dist/infra/fonts/FontRegistryContext.d.ts.map +1 -0
  3. package/dist/infra/fonts/FontRegistryContext.js +35 -0
  4. package/dist/infra/fonts/FontRegistryContext.js.map +1 -0
  5. package/dist/infra/fonts/index.d.ts +3 -0
  6. package/dist/infra/fonts/index.d.ts.map +1 -0
  7. package/dist/infra/fonts/index.js +13 -0
  8. package/dist/infra/fonts/index.js.map +1 -0
  9. package/dist/infra/fonts/registry.d.ts +6 -0
  10. package/dist/infra/fonts/registry.d.ts.map +1 -0
  11. package/dist/infra/fonts/registry.js +96 -0
  12. package/dist/infra/fonts/registry.js.map +1 -0
  13. package/dist/infra/index.d.ts +1 -0
  14. package/dist/infra/index.d.ts.map +1 -1
  15. package/dist/infra/index.js +1 -0
  16. package/dist/infra/index.js.map +1 -1
  17. package/dist/infra/provider/FontLoader.d.ts +9 -0
  18. package/dist/infra/provider/FontLoader.d.ts.map +1 -0
  19. package/dist/infra/provider/FontLoader.js +38 -0
  20. package/dist/infra/provider/FontLoader.js.map +1 -0
  21. package/dist/infra/provider/OnboardingProvider.d.ts +7 -1
  22. package/dist/infra/provider/OnboardingProvider.d.ts.map +1 -1
  23. package/dist/infra/provider/OnboardingProvider.js +11 -3
  24. package/dist/infra/provider/OnboardingProvider.js.map +1 -1
  25. package/dist/infra/provider/index.d.ts +1 -0
  26. package/dist/infra/provider/index.d.ts.map +1 -1
  27. package/dist/infra/provider/index.js +3 -1
  28. package/dist/infra/provider/index.js.map +1 -1
  29. package/dist/onboarding-example.d.ts +78 -0
  30. package/dist/onboarding-example.d.ts.map +1 -1
  31. package/dist/onboarding-example.js +23 -1
  32. package/dist/onboarding-example.js.map +1 -1
  33. package/dist/steps/ComposableScreen/elements/ButtonElement.d.ts +5 -0
  34. package/dist/steps/ComposableScreen/elements/ButtonElement.d.ts.map +1 -1
  35. package/dist/steps/ComposableScreen/elements/ButtonElement.js +1 -0
  36. package/dist/steps/ComposableScreen/elements/ButtonElement.js.map +1 -1
  37. package/dist/steps/ComposableScreen/elements/CarouselElement.d.ts +1 -1
  38. package/dist/steps/ComposableScreen/elements/CheckboxGroupElement.d.ts +5 -0
  39. package/dist/steps/ComposableScreen/elements/CheckboxGroupElement.d.ts.map +1 -1
  40. package/dist/steps/ComposableScreen/elements/CheckboxGroupElement.js +1 -0
  41. package/dist/steps/ComposableScreen/elements/CheckboxGroupElement.js.map +1 -1
  42. package/dist/steps/ComposableScreen/elements/InputElement.d.ts +5 -0
  43. package/dist/steps/ComposableScreen/elements/InputElement.d.ts.map +1 -1
  44. package/dist/steps/ComposableScreen/elements/InputElement.js +1 -0
  45. package/dist/steps/ComposableScreen/elements/InputElement.js.map +1 -1
  46. package/dist/steps/ComposableScreen/elements/RadioGroupElement.d.ts +5 -0
  47. package/dist/steps/ComposableScreen/elements/RadioGroupElement.d.ts.map +1 -1
  48. package/dist/steps/ComposableScreen/elements/RadioGroupElement.js +1 -0
  49. package/dist/steps/ComposableScreen/elements/RadioGroupElement.js.map +1 -1
  50. package/dist/steps/ComposableScreen/elements/TextElement.d.ts +5 -0
  51. package/dist/steps/ComposableScreen/elements/TextElement.d.ts.map +1 -1
  52. package/dist/steps/ComposableScreen/elements/TextElement.js +1 -0
  53. package/dist/steps/ComposableScreen/elements/TextElement.js.map +1 -1
  54. package/dist/types.d.ts +4 -0
  55. package/dist/types.d.ts.map +1 -1
  56. package/package.json +7 -1
  57. package/src/infra/fonts/FontRegistryContext.tsx +45 -0
  58. package/src/infra/fonts/index.ts +12 -0
  59. package/src/infra/fonts/registry.ts +104 -0
  60. package/src/infra/index.ts +1 -0
  61. package/src/infra/provider/FontLoader.tsx +40 -0
  62. package/src/infra/provider/OnboardingProvider.tsx +49 -5
  63. package/src/infra/provider/index.ts +1 -0
  64. package/src/onboarding-example.ts +23 -1
  65. package/src/steps/ComposableScreen/elements/ButtonElement.ts +2 -0
  66. package/src/steps/ComposableScreen/elements/CheckboxGroupElement.ts +2 -0
  67. package/src/steps/ComposableScreen/elements/InputElement.ts +2 -0
  68. package/src/steps/ComposableScreen/elements/RadioGroupElement.ts +2 -0
  69. package/src/steps/ComposableScreen/elements/TextElement.ts +2 -0
  70. package/src/types.ts +21 -0
@@ -1,10 +1,11 @@
1
1
  import { createContext, useCallback, useState } from "react";
2
- import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
2
+ import { QueryClient, QueryClientProvider, useQuery } from "@tanstack/react-query";
3
3
  import { OnboardingStudioClient } from "../../OnboardingStudioClient";
4
4
  import { getOnboardingQuery } from "../queries/getOnboarding.query";
5
5
  import { Onboarding } from "../../types";
6
6
  import { OnboardingStepType } from "../../steps/types";
7
7
  import { ComposableVariableEntry } from "../../steps/ComposableScreen/types";
8
+ import { FontLoaderGate } from "./FontLoader";
8
9
 
9
10
  const queryClient = new QueryClient({
10
11
  defaultOptions: {
@@ -32,14 +33,52 @@ interface OnboardingProviderProps {
32
33
  * variable map and may return a Promise.
33
34
  */
34
35
  customActions?: CustomActions;
36
+ /**
37
+ * Rendered while the onboarding payload is fetched and any remote fonts
38
+ * declared in the response (`onboarding.fonts`) are downloaded and registered.
39
+ * Defaults to `null`.
40
+ */
41
+ fontsFallback?: React.ReactNode;
42
+ }
43
+
44
+ interface OnboardingDataGateProps {
45
+ client: OnboardingStudioClient;
46
+ locale: string;
47
+ customAudienceParams: Record<string, any>;
48
+ setOnboarding: (onboarding: Onboarding<OnboardingStepType>) => void;
49
+ fontsFallback?: React.ReactNode;
50
+ children: React.ReactNode;
35
51
  }
36
52
 
53
+ const OnboardingDataGate = ({
54
+ client,
55
+ locale,
56
+ customAudienceParams,
57
+ setOnboarding,
58
+ fontsFallback,
59
+ children,
60
+ }: OnboardingDataGateProps) => {
61
+ const { data, error } = useQuery<Onboarding<OnboardingStepType>>(
62
+ getOnboardingQuery<OnboardingStepType>(client, locale, customAudienceParams, setOnboarding)
63
+ );
64
+
65
+ if (error) throw error;
66
+ if (!data) return <>{fontsFallback ?? null}</>;
67
+
68
+ return (
69
+ <FontLoaderGate fonts={data.fonts} fallback={fontsFallback}>
70
+ {children}
71
+ </FontLoaderGate>
72
+ );
73
+ };
74
+
37
75
  export const OnboardingProvider = ({
38
76
  children,
39
77
  client,
40
78
  locale = "en",
41
79
  customAudienceParams = {},
42
80
  customActions = {},
81
+ fontsFallback,
43
82
  }: OnboardingProviderProps) => {
44
83
  const [activeStep, setActiveStep] = useState({
45
84
  number: 0,
@@ -52,11 +91,8 @@ export const OnboardingProvider = ({
52
91
  setVariables((prev) => ({ ...prev, [name]: value }));
53
92
  }, []);
54
93
 
55
- queryClient.prefetchQuery(getOnboardingQuery(client, locale, customAudienceParams, setOnboarding))
56
-
57
94
  return (
58
95
  <QueryClientProvider client={queryClient}>
59
-
60
96
  <OnboardingProgressContext.Provider
61
97
  value={{
62
98
  activeStep,
@@ -73,7 +109,15 @@ export const OnboardingProvider = ({
73
109
  customActions,
74
110
  }}
75
111
  >
76
- {children}
112
+ <OnboardingDataGate
113
+ client={client}
114
+ locale={locale}
115
+ customAudienceParams={customAudienceParams}
116
+ setOnboarding={setOnboarding}
117
+ fontsFallback={fontsFallback}
118
+ >
119
+ {children}
120
+ </OnboardingDataGate>
77
121
  </OnboardingProgressContext.Provider>
78
122
  </QueryClientProvider>
79
123
  );
@@ -6,3 +6,4 @@ export type {
6
6
  CustomActionHandler,
7
7
  CustomActions,
8
8
  } from "./OnboardingProvider";
9
+ export { FontLoaderGate } from "./FontLoader";
@@ -9,6 +9,16 @@ export const onboardingExample = {
9
9
  audienceOrder: undefined,
10
10
  draft: true,
11
11
  },
12
+ fonts: {
13
+ Inter: {
14
+ regular: "https://cdn.jsdelivr.net/fontsource/fonts/inter@latest/latin-400-normal.ttf",
15
+ medium: "https://cdn.jsdelivr.net/fontsource/fonts/inter@latest/latin-500-normal.ttf",
16
+ bold: "https://cdn.jsdelivr.net/fontsource/fonts/inter@latest/latin-700-normal.ttf",
17
+ },
18
+ Lobster: {
19
+ regular: "https://cdn.jsdelivr.net/fontsource/fonts/lobster@latest/latin-400-normal.ttf",
20
+ },
21
+ },
12
22
  steps: [
13
23
  {
14
24
  id: "welcome",
@@ -188,8 +198,20 @@ export const onboardingExample = {
188
198
  content: "Built from the CMS",
189
199
  fontSize: 28,
190
200
  fontWeight: "700",
191
- fontFamily: "System",
201
+ fontFamily: "Inter",
202
+ textAlign: "center",
203
+ },
204
+ },
205
+ {
206
+ id: "headline-display",
207
+ type: "Text",
208
+ props: {
209
+ content: "Runtime-loaded font",
210
+ fontSize: 32,
211
+ fontFamily: "Lobster",
212
+ fontStyle: "italic",
192
213
  textAlign: "center",
214
+ marginVertical: 4,
193
215
  },
194
216
  },
195
217
  {
@@ -38,6 +38,7 @@ export type ButtonElementProps = BaseBoxProps & {
38
38
  fontSize?: number;
39
39
  fontWeight?: string;
40
40
  fontFamily?: string;
41
+ fontStyle?: "normal" | "italic";
41
42
  textAlign?: "left" | "center" | "right";
42
43
  };
43
44
 
@@ -51,5 +52,6 @@ export const ButtonElementPropsSchema = BaseBoxPropsSchema.extend({
51
52
  fontSize: z.number().optional(),
52
53
  fontWeight: z.string().optional(),
53
54
  fontFamily: z.string().optional(),
55
+ fontStyle: z.enum(["normal", "italic"]).optional(),
54
56
  textAlign: z.enum(["left", "center", "right"]).optional(),
55
57
  });
@@ -18,6 +18,7 @@ export type CheckboxGroupElementProps = BaseBoxProps & {
18
18
  itemFontSize?: number;
19
19
  itemFontWeight?: string;
20
20
  itemFontFamily?: string;
21
+ itemFontStyle?: "normal" | "italic";
21
22
  itemPadding?: number;
22
23
  itemPaddingHorizontal?: number;
23
24
  itemPaddingVertical?: number;
@@ -40,6 +41,7 @@ export const CheckboxGroupElementPropsSchema = BaseBoxPropsSchema.extend({
40
41
  itemFontSize: z.number().optional(),
41
42
  itemFontWeight: z.string().optional(),
42
43
  itemFontFamily: z.string().optional(),
44
+ itemFontStyle: z.enum(["normal", "italic"]).optional(),
43
45
  itemPadding: z.number().optional(),
44
46
  itemPaddingHorizontal: z.number().optional(),
45
47
  itemPaddingVertical: z.number().optional(),
@@ -18,6 +18,7 @@ export type InputElementProps = BaseBoxProps & {
18
18
  fontSize?: number;
19
19
  fontWeight?: string;
20
20
  fontFamily?: string;
21
+ fontStyle?: "normal" | "italic";
21
22
  lineHeight?: number;
22
23
  letterSpacing?: number;
23
24
  textAlign?: "left" | "center" | "right";
@@ -41,6 +42,7 @@ export const InputElementPropsSchema = BaseBoxPropsSchema.extend({
41
42
  fontSize: z.number().optional(),
42
43
  fontWeight: z.string().optional(),
43
44
  fontFamily: z.string().optional(),
45
+ fontStyle: z.enum(["normal", "italic"]).optional(),
44
46
  lineHeight: z.number().optional(),
45
47
  letterSpacing: z.number().optional(),
46
48
  textAlign: z.enum(["left", "center", "right"]).optional(),
@@ -18,6 +18,7 @@ export type RadioGroupElementProps = BaseBoxProps & {
18
18
  itemFontSize?: number;
19
19
  itemFontWeight?: string;
20
20
  itemFontFamily?: string;
21
+ itemFontStyle?: "normal" | "italic";
21
22
  itemPadding?: number;
22
23
  itemPaddingHorizontal?: number;
23
24
  itemPaddingVertical?: number;
@@ -40,6 +41,7 @@ export const RadioGroupElementPropsSchema = BaseBoxPropsSchema.extend({
40
41
  itemFontSize: z.number().optional(),
41
42
  itemFontWeight: z.string().optional(),
42
43
  itemFontFamily: z.string().optional(),
44
+ itemFontStyle: z.enum(["normal", "italic"]).optional(),
43
45
  itemPadding: z.number().optional(),
44
46
  itemPaddingHorizontal: z.number().optional(),
45
47
  itemPaddingVertical: z.number().optional(),
@@ -7,6 +7,7 @@ export type TextElementProps = BaseBoxProps & {
7
7
  fontSize?: number;
8
8
  fontWeight?: string;
9
9
  fontFamily?: string;
10
+ fontStyle?: "normal" | "italic";
10
11
  color?: string;
11
12
  textAlign?: "left" | "center" | "right";
12
13
  letterSpacing?: number;
@@ -19,6 +20,7 @@ export const TextElementPropsSchema = BaseBoxPropsSchema.extend({
19
20
  fontSize: z.number().optional(),
20
21
  fontWeight: z.string().optional(),
21
22
  fontFamily: z.string().optional(),
23
+ fontStyle: z.enum(["normal", "italic"]).optional(),
22
24
  color: z.string().optional(),
23
25
  textAlign: z.enum(["left", "center", "right"]).optional(),
24
26
  letterSpacing: z.number().optional(),
package/src/types.ts CHANGED
@@ -44,10 +44,31 @@ export interface OnboardingMetadata {
44
44
  draft?: boolean;
45
45
  }
46
46
 
47
+ export type FontWeightKey =
48
+ | "regular"
49
+ | "medium"
50
+ | "semibold"
51
+ | "bold"
52
+ | "extrabold"
53
+ | "100"
54
+ | "200"
55
+ | "300"
56
+ | "400"
57
+ | "500"
58
+ | "600"
59
+ | "700"
60
+ | "800"
61
+ | "900";
62
+
63
+ export type FontFamilyManifest = Partial<Record<FontWeightKey, string>>;
64
+
65
+ export type FontsManifest = Record<string, FontFamilyManifest>;
66
+
47
67
  export interface Onboarding<StepType extends BaseStepType = BaseStepType> {
48
68
  metadata: OnboardingMetadata;
49
69
  steps: StepType[];
50
70
  configuration: any;
71
+ fonts?: FontsManifest;
51
72
  }
52
73
 
53
74
  export interface GetStepsResponseHeaders {