@applicaster/zapp-react-native-utils 13.0.0-alpha.8490438700 → 13.0.0-alpha.9103242840

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.
@@ -0,0 +1,130 @@
1
+ const defaultPlatforms = {
2
+ tvos: "tvOS",
3
+ android_tv: "Android TV",
4
+ lg_tv: "LG TV",
5
+ samsung_tv: "Samsung TV",
6
+ };
7
+
8
+ const global_defaults = {
9
+ fontSize: 20,
10
+ lineHeight: 40,
11
+ letterSpacing: 0.4,
12
+ };
13
+
14
+ const generateFontConfiguration = (platforms = defaultPlatforms) => {
15
+ const platformEntries = Object.entries(platforms);
16
+ const defaultsEntries = Object.entries(global_defaults);
17
+ const splitCamelCase = (str) => str.replace(/([a-z](?=[A-Z]))/g, "$1_");
18
+
19
+ return platformEntries.reduce((acc, [platformKey, platformValue]) => {
20
+ acc.push(
21
+ ...defaultsEntries.reduce((acc2, [valueKey, defaultValue]) => {
22
+ acc2.push({
23
+ type: "number_input",
24
+ label: `${platformValue} ${splitCamelCase(valueKey).replace(
25
+ "_",
26
+ " "
27
+ )}`,
28
+ key: `${platformKey}_${splitCamelCase(valueKey)}`.toLowerCase(),
29
+ initial_value: defaultValue,
30
+ });
31
+
32
+ return acc2;
33
+ }, [])
34
+ );
35
+
36
+ return acc;
37
+ }, []);
38
+ };
39
+
40
+ const conditional_rule = (key, condition_value) => ({
41
+ key,
42
+ condition_value,
43
+ });
44
+
45
+ const createConditionalConfig = (rules, matchAll = false) => ({
46
+ rules: matchAll ? "all_conditions" : "conditional",
47
+ conditional_fields: rules.map((field) => conditional_rule(...field)),
48
+ });
49
+
50
+ const conditional_horizontal_type = createConditionalConfig([
51
+ ["styles/screen_picker_type", "horizontal"],
52
+ ]);
53
+
54
+ const conditional_vertical_type = createConditionalConfig([
55
+ ["styles/screen_picker_type", "vertical"],
56
+ ]);
57
+
58
+ const conditional_horizontal_type_item_fixed = createConditionalConfig(
59
+ [
60
+ ["styles/screen_picker_type", "horizontal"],
61
+ ["styles/screen_picker_item_size", "fixed"],
62
+ ],
63
+ true
64
+ );
65
+
66
+ const conditional_horizontal_type_item_dynamic = createConditionalConfig(
67
+ [
68
+ ["styles/screen_picker_type", "horizontal"],
69
+ ["screen_picker_horizontal_display_type", "dynamic"],
70
+ ],
71
+ true
72
+ );
73
+
74
+ const conditional_horizontal_display_type_fixed = createConditionalConfig(
75
+ [
76
+ ["styles/screen_picker_type", "horizontal"],
77
+ ["styles/screen_picker_horizontal_display_type", "fixed"],
78
+ ],
79
+ true
80
+ );
81
+
82
+ const conditional_horizontal_asset_on = createConditionalConfig(
83
+ [
84
+ ["styles/screen_picker_type", "horizontal"],
85
+ ["styles/screen_picker_asset_switch", true],
86
+ ],
87
+ true
88
+ );
89
+
90
+ const createVariationFields = ({
91
+ prefix = "screen_picker",
92
+ key,
93
+ type = "number_input",
94
+ label = "",
95
+ variants: [a, b],
96
+ }) => {
97
+ return [
98
+ {
99
+ type,
100
+ key: `${prefix}${prefix.length > 0 ? "_" : ""}${
101
+ a?.key ?? "vertical"
102
+ }_${key}`,
103
+ label: a?.label ?? label,
104
+ initial_value: a.initial_value,
105
+ ...conditional_vertical_type,
106
+ },
107
+ {
108
+ type,
109
+ key: `${prefix}${prefix.length > 0 ? "_" : ""}${
110
+ b.key ?? "horizontal"
111
+ }_${key}`,
112
+ label: b?.label ?? label,
113
+ initial_value: b.initial_value,
114
+ ...conditional_horizontal_type,
115
+ },
116
+ ];
117
+ };
118
+
119
+ module.exports = {
120
+ generateFontConfiguration,
121
+ createVariationFields,
122
+ createConditionalConfig,
123
+ conditional_rule,
124
+ conditional_horizontal_type,
125
+ conditional_vertical_type,
126
+ conditional_horizontal_type_item_fixed,
127
+ conditional_horizontal_type_item_dynamic,
128
+ conditional_horizontal_display_type_fixed,
129
+ conditional_horizontal_asset_on,
130
+ };
@@ -644,8 +644,8 @@ export const getScreenId = (
644
644
  fallbackRiver: ZappRiver
645
645
  ) => {
646
646
  return screenData?.targetScreen
647
- ? (screenData?.targetScreen?.id ?? fallbackRiver.id)
647
+ ? screenData?.targetScreen?.id ?? fallbackRiver.id
648
648
  : "screen_id" in screenData
649
- ? screenData.screen_id
650
- : fallbackRiver.id;
649
+ ? screenData.screen_id
650
+ : fallbackRiver.id;
651
651
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "13.0.0-alpha.8490438700",
3
+ "version": "13.0.0-alpha.9103242840",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "13.0.0-alpha.8490438700",
31
+ "@applicaster/applicaster-types": "13.0.0-alpha.9103242840",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
34
  "create-react-context": "^0.2.3",
@@ -5,7 +5,7 @@ const mockDimensionsGet = jest.fn(
5
5
  ({
6
6
  window: { width: 1, height: 1 },
7
7
  screen: { width: 360, height: 540 },
8
- })[type]
8
+ }[type])
9
9
  );
10
10
 
11
11
  ReactNative.Dimensions.get = mockDimensionsGet;
@@ -52,14 +52,6 @@ export const useDimensions: UseDimensions = (
52
52
  ? { fullDimensions }
53
53
  : { ...fullDimensions };
54
54
 
55
- if (options.updateForInactiveScreens === undefined) {
56
- options.updateForInactiveScreens = true;
57
- }
58
-
59
- if (options.fullDimensions === undefined) {
60
- options.fullDimensions = false;
61
- }
62
-
63
55
  const [dimensions, setDimensions] = useState(getInitialDimensions(context));
64
56
  const deviceInfo = useRef(getDeviceInfo(dimensions, appData));
65
57
 
@@ -91,7 +91,7 @@ export function useLayoutConfiguration<
91
91
  S extends unknown,
92
92
  G extends unknown,
93
93
  R extends unknown,
94
- L extends unknown,
94
+ L extends unknown
95
95
  >(layoutData, manifest, options: Options = {}) {
96
96
  const keys = options.keys || [
97
97
  "assets",
@@ -4,10 +4,9 @@ import { subscriber } from "@applicaster/zapp-react-native-utils/functionUtils";
4
4
  const subscriberObjects = Object.create({});
5
5
 
6
6
  interface UseSubscriberFor {
7
- (
8
- eventName: string,
9
- handler?: (...args: unknown[]) => void
10
- ): (...args: unknown[]) => ReturnType<typeof subscriber>;
7
+ (eventName: string, handler?: (...args: unknown[]) => void): (
8
+ ...args: unknown[]
9
+ ) => ReturnType<typeof subscriber>;
11
10
  }
12
11
 
13
12
  /**
@@ -1,8 +1,6 @@
1
1
  import { create } from "zustand";
2
2
  import { produce } from "immer";
3
3
  import { path } from "ramda";
4
- import React from "react";
5
- import { useShallow } from "zustand/react/shallow";
6
4
 
7
5
  type ScreenState = {
8
6
  selectedEntry: {
@@ -20,8 +18,6 @@ type ScreenStore = {
20
18
  setSelectedEntry: (screenId: string, entryId: string) => void;
21
19
  };
22
20
 
23
- type SetSelectedEntry = (screenId: string, entryId: string) => void;
24
-
25
21
  const useScreenStore = create<ScreenStore>((set) => ({
26
22
  screens: screensInitialState,
27
23
  setSelectedEntry: (screenId, entryId) =>
@@ -39,27 +35,17 @@ const useScreenStore = create<ScreenStore>((set) => ({
39
35
  export function useScreenState(
40
36
  screenId: ScreenId
41
37
  ): null | { screen: ScreenState; setSelectedEntry: (entryId: string) => void } {
42
- const screenState = useScreenStore<ScreenState>(
43
- useShallow(path(["screens", screenId]))
44
- );
38
+ // const state = useState(screenState);
39
+ const screenState = useScreenStore(
40
+ path(["screens", screenId])
41
+ ) as ScreenState;
45
42
 
46
- const setSelectedEntry = useScreenStore<SetSelectedEntry>(
47
- useShallow(path(["setSelectedEntry"]))
48
- );
43
+ const setSelectedEntry = useScreenStore((state) => state.setSelectedEntry);
49
44
 
50
- const memoizedSetSelectedEntry = React.useCallback(
51
- (entryId) => setSelectedEntry(screenId, entryId),
52
- [screenId, setSelectedEntry]
53
- );
45
+ if (!screenId) return null;
54
46
 
55
- return React.useMemo(
56
- () =>
57
- !screenId
58
- ? null
59
- : {
60
- screen: screenState,
61
- setSelectedEntry: memoizedSetSelectedEntry,
62
- },
63
- [screenId, screenState]
64
- );
47
+ return {
48
+ screen: screenState,
49
+ setSelectedEntry: (entryId) => setSelectedEntry(screenId, entryId),
50
+ };
65
51
  }
package/theme/index.ts CHANGED
@@ -14,7 +14,7 @@ export const ThemeContext = React.createContext({
14
14
  export function useTheme<
15
15
  T extends Record<string, any> =
16
16
  | BaseThemePropertiesTV
17
- | BaseThemePropertiesMobile,
17
+ | BaseThemePropertiesMobile
18
18
  >(): T {
19
19
  const { themes, selectedThemeId } = React.useContext(ThemeContext);
20
20
 
package/time/Timer.ts CHANGED
@@ -3,10 +3,7 @@ export class Timer {
3
3
  private remaining: number;
4
4
  private timeoutId: NodeJS.Timeout | null;
5
5
 
6
- constructor(
7
- private callback: () => void,
8
- private duration: number
9
- ) {
6
+ constructor(private callback: () => void, private duration: number) {
10
7
  this.remaining = this.duration;
11
8
  this.timeoutId = null;
12
9
  }
package/types.ts CHANGED
@@ -8,5 +8,4 @@ export type ManifestField<T> = {
8
8
 
9
9
  export enum ENDPOINT_TAGS {
10
10
  allow_missing_keys = "allow_missing_keys",
11
- observe_storage = "observe_storage",
12
11
  }
@@ -92,8 +92,9 @@ export const PresentHookPluginOneTime = (
92
92
  const presentOneTimeVersionName =
93
93
  await getLatestWatchedVersionNumberFromStorage(storageKey, namespace);
94
94
 
95
- const applicationVersionName =
96
- await sessionStorage.getItem(versionNameKey);
95
+ const applicationVersionName = await sessionStorage.getItem(
96
+ versionNameKey
97
+ );
97
98
 
98
99
  if (!presentOneTimeVersionName || !applicationVersionName) {
99
100
  log_info(
@@ -1,37 +0,0 @@
1
- import { TestScheduler } from "rxjs/testing";
2
-
3
- import { withTimeout$ } from "..";
4
-
5
- describe("withTimeout$", () => {
6
- let testScheduler: TestScheduler;
7
-
8
- beforeEach(() => {
9
- testScheduler = new TestScheduler((actual, expected) => {
10
- expect(actual).toEqual(expected);
11
- });
12
- });
13
-
14
- it("should emit undefined after the specified timeout", () => {
15
- testScheduler.run(({ expectObservable }) => {
16
- const timeout = 1000;
17
- const expectedMarble = "1s (a|)";
18
- const expectedValues = { a: undefined };
19
-
20
- const result$ = withTimeout$(timeout);
21
-
22
- expectObservable(result$).toBe(expectedMarble, expectedValues);
23
- });
24
- });
25
-
26
- it("should complete after emitting undefined", () => {
27
- testScheduler.run(({ expectObservable }) => {
28
- const timeout = 500;
29
- const expectedMarble = "500ms (a|)";
30
- const expectedValues = { a: undefined };
31
-
32
- const result$ = withTimeout$(timeout);
33
-
34
- expectObservable(result$).toBe(expectedMarble, expectedValues);
35
- });
36
- });
37
- });
@@ -1,14 +0,0 @@
1
- import React from "react";
2
-
3
- /**
4
- * returns a ref with an initial value that is lazily evaluated once
5
- * */
6
- export const useRefWithInitialValue = <T>(initialValueGetter: () => T) => {
7
- const ref = React.useRef<T>(null);
8
-
9
- if (ref.current === null) {
10
- ref.current = initialValueGetter();
11
- }
12
-
13
- return ref;
14
- };
@@ -1,23 +0,0 @@
1
- import { useEffect, useState } from "react";
2
- import type { Subject } from "rxjs";
3
-
4
- export const useStateFromSubscribe = <T, U>(
5
- subject: Subject<T>,
6
- onUpdate: (
7
- observerValue: T,
8
- next: React.Dispatch<React.SetStateAction<U>>
9
- ) => void,
10
- initialValue: U
11
- ) => {
12
- const [state, setState] = useState<U>(initialValue);
13
-
14
- useEffect(() => {
15
- const subscription = subject.subscribe((observer) =>
16
- onUpdate(observer, setState)
17
- );
18
-
19
- return () => subscription.unsubscribe();
20
- }, [subject]);
21
-
22
- return state;
23
- };