@applicaster/zapp-react-native-ui-components 16.0.0-rc.8 → 16.0.0-rc.81
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/Components/AudioPlayer/tv/__tests__/audioPlayer.test.js +19 -0
- package/Components/AudioPlayer/tv/__tests__/index.test.tsx +120 -0
- package/Components/AudioPlayer/tv/index.tsx +5 -1
- package/Components/Cell/Cell.tsx +3 -6
- package/Components/Cell/TvOSCellComponent.tsx +0 -1
- package/Components/CellRendererResolver/index.ts +2 -2
- package/Components/ComponentResolver/__tests__/componentResolver.test.js +1 -1
- package/Components/FocusableGroup/FocusableTvOS.tsx +11 -7
- package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +39 -0
- package/Components/GeneralContentScreen/__tests__/GeneralContentScreenHookAdapter.test.tsx +64 -0
- package/Components/GeneralContentScreen/__tests__/HookContentFocusGroup.web.test.tsx +91 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/networkService.test.ts +74 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/runInBackground.test.ts +139 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/skipExpression.test.ts +294 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +188 -0
- package/Components/GeneralContentScreen/hookAdapter/logger.ts +6 -0
- package/Components/GeneralContentScreen/hookAdapter/networkService.ts +53 -0
- package/Components/GeneralContentScreen/hookAdapter/runInBackground.ts +48 -0
- package/Components/GeneralContentScreen/hookAdapter/skipExpression.ts +252 -0
- package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +90 -0
- package/Components/GeneralContentScreen/hookFocus/index.tsx +13 -0
- package/Components/GeneralContentScreen/hookFocus/index.web.tsx +69 -0
- package/Components/GeneralContentScreen/index.ts +2 -0
- package/Components/Layout/FullWidthRow.tsx +38 -0
- package/Components/MasterCell/DefaultComponents/ActionButton.tsx +16 -5
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +47 -21
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +34 -6
- package/Components/MasterCell/DefaultComponents/Image/hoc/utils/__tests__/withDimensions.test.ts +420 -125
- package/Components/MasterCell/DefaultComponents/Image/hoc/utils/index.ts +114 -19
- package/Components/MasterCell/DefaultComponents/Image/hoc/withDimensions.tsx +19 -8
- package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +5 -3
- package/Components/MasterCell/DefaultComponents/PressableView.tsx +29 -9
- package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +4 -0
- package/Components/MasterCell/DefaultComponents/Toggle.tsx +36 -14
- package/Components/MasterCell/DefaultComponents/__tests__/Toggle.test.tsx +167 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +154 -100
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +15 -4
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +56 -22
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +6 -4
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +3 -1
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +32 -21
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +15 -4
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +23 -16
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +8 -3
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +2 -2
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/insertButtonsBetweenLabels.test.ts +45 -13
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +2 -2
- package/Components/MasterCell/contexts/PressedStateContext.ts +3 -0
- package/Components/MasterCell/dataAdapter.ts +15 -5
- package/Components/MasterCell/hooks/index.ts +2 -0
- package/Components/MasterCell/hooks/usePressedState.ts +4 -0
- package/Components/MasterCell/index.tsx +30 -5
- package/Components/MasterCell/utils/__tests__/resolveColor.test.js +169 -132
- package/Components/MasterCell/utils/__tests__/resolveColorForProp.test.js +92 -0
- package/Components/MasterCell/utils/index.ts +85 -46
- package/Components/ModalComponent/ActionsBottomSheet/ActionButton.tsx +54 -0
- package/Components/ModalComponent/ActionsBottomSheet/boundActionButton.tsx +21 -0
- package/Components/ModalComponent/ActionsBottomSheet/index.ts +9 -0
- package/Components/ModalComponent/ActionsBottomSheet/openActionsBottomSheet.ts +58 -0
- package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +314 -0
- package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +407 -0
- package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +763 -0
- package/Components/ModalComponent/AudioPlayer/Components/Input.tsx +653 -0
- package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +960 -0
- package/Components/ModalComponent/AudioPlayer/Components/NowPlayingHeaderSection.tsx +89 -0
- package/Components/ModalComponent/AudioPlayer/Components/index.ts +11 -0
- package/Components/ModalComponent/AudioPlayer/utils/__tests__/mergeStyles.test.ts +230 -0
- package/Components/ModalComponent/AudioPlayer/utils/mergeStyles.ts +332 -0
- package/Components/ModalComponent/BottomSheetDragArea.tsx +33 -0
- package/Components/ModalComponent/BottomSheetModalContent.tsx +383 -42
- package/Components/ModalComponent/Button/index.tsx +5 -3
- package/Components/ModalComponent/Header/index.tsx +20 -7
- package/Components/ModalComponent/Header/utils.ts +1 -1
- package/Components/ModalComponent/ModalBlocksStyleContext.tsx +10 -0
- package/Components/ModalComponent/SortableList.tsx +142 -0
- package/Components/ModalComponent/SortableList.web.tsx +34 -0
- package/Components/ModalComponent/TextInputContent.tsx +100 -0
- package/Components/ModalComponent/__tests__/BottomSheetDragArea.test.tsx +74 -0
- package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +238 -0
- package/Components/ModalComponent/__tests__/SortableList.web.test.tsx +16 -0
- package/Components/ModalComponent/__tests__/TextInputContent.test.tsx +120 -0
- package/Components/ModalComponent/__tests__/showTextInput.test.ts +95 -0
- package/Components/ModalComponent/index.tsx +11 -0
- package/Components/ModalComponent/presets/__tests__/getCell.test.ts +66 -0
- package/Components/ModalComponent/presets/dynamicCollectionCell.tsx +78 -0
- package/Components/ModalComponent/presets/index.ts +27 -0
- package/Components/ModalComponent/presets/selectableCell.tsx +28 -0
- package/Components/ModalComponent/presets/standardCell.tsx +41 -0
- package/Components/ModalComponent/presets/types.ts +35 -0
- package/Components/ModalComponent/showTextInput.ts +43 -0
- package/Components/ModalComponent/utils.ts +82 -21
- package/Components/OfflineHandler/__tests__/__snapshots__/index.test.tsx.snap +4 -85
- package/Components/OfflineHandler/__tests__/index.test.tsx +78 -18
- package/Components/OfflineHandler/hooks.ts +111 -0
- package/Components/OfflineHandler/index.tsx +51 -73
- package/Components/OfflineHandler/utils/index.ts +1 -13
- package/Components/PlayerContainer/PlayerContainer.tsx +25 -17
- package/Components/PlayerContainer/ProgramInfo/index.tsx +3 -4
- package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +337 -0
- package/Components/PreloaderWrapper/index.tsx +1 -1
- package/Components/River/ComponentsMap/ComponentsMap.tsx +2 -2
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +3 -15
- package/Components/Screen/index.tsx +8 -4
- package/Components/ScreenFeedLoader/ScreenFeedLoader.tsx +5 -3
- package/Components/ScreenResolverFeedProvider/ScreenResolverFeedProvider.tsx +1 -1
- package/Components/ScreenRevealManager/ScreenRevealManager.ts +18 -2
- package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +36 -0
- package/Components/ScreenRevealManager/__tests__/withScreenRevealManager.test.tsx +56 -0
- package/Components/ScreenRevealManager/withScreenRevealManager.tsx +20 -3
- package/Components/TopCutoffOverlay/index.tsx +2 -2
- package/Components/Transitioner/Transitioner.tsx +28 -17
- package/Components/VideoLive/LiveImageManager.ts +1 -1
- package/Components/VideoModal/utils.ts +6 -1
- package/Components/ZappFrameworkComponents/BarView/BarView.tsx +12 -5
- package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
- package/Contexts/CachedDimensionsContext/__tests__/index.test.ts +154 -0
- package/Contexts/CachedDimensionsContext/index.ts +17 -2
- package/Helpers/ComponentCellSelectionHelper/index.js +0 -6
- package/Helpers/index.js +0 -39
- package/Hooks/useEntryActionsExpander.ts +63 -0
- package/package.json +6 -5
- package/Components/OfflineHandler/NotificationView/NotificationView.lg.tsx +0 -112
- package/Components/OfflineHandler/NotificationView/NotificationView.samsung.tsx +0 -107
- package/Components/OfflineHandler/NotificationView/NotificationView.tsx +0 -153
- package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +0 -66
- package/Components/OfflineHandler/NotificationView/utils.ts +0 -34
- package/Components/Screen/utils.ts +0 -16
- package/Helpers/Analytics/index.js +0 -95
- /package/Components/BackgroundImage/{BackgroundImage.tv.android.tsx → BackgroundImage.android.tv.tsx} +0 -0
- /package/Components/BackgroundImage/{BackgroundImage.tv.ios.tsx → BackgroundImage.ios.tv.tsx} +0 -0
- /package/Components/MasterCell/DefaultComponents/ButtonContainerView/{index.tv.android.tsx → index.android.tv.tsx} +0 -0
- /package/Decorators/ZappPipesDataConnector/__tests__/{Hero.js → Hero.tsx} +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { shouldSkipHook } from "./validationHelper";
|
|
2
|
+
import { requestToSkipHook } from "./networkService";
|
|
3
|
+
import { log_debug, log_error } from "./logger";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Headless pre-hook for the General Content Screen. `configuration` is the
|
|
7
|
+
* Hook object with the screen merged in; skip-hook fields live under `rules`.
|
|
8
|
+
*/
|
|
9
|
+
export const runInBackground = async (
|
|
10
|
+
item,
|
|
11
|
+
callback,
|
|
12
|
+
configuration,
|
|
13
|
+
presentUI
|
|
14
|
+
) => {
|
|
15
|
+
try {
|
|
16
|
+
const skipHookIfKeysExist = configuration?.rules?.skip_hook_storage_key;
|
|
17
|
+
|
|
18
|
+
if (skipHookIfKeysExist) {
|
|
19
|
+
const shouldSkip = await shouldSkipHook(skipHookIfKeysExist);
|
|
20
|
+
|
|
21
|
+
if (shouldSkip) {
|
|
22
|
+
log_debug(
|
|
23
|
+
`runInBackground: Storage key found: ${skipHookIfKeysExist}. Skipping hook.`
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return callback({ success: true, error: null, payload: item });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const skipHookEndpoint = configuration?.rules?.skip_hook_endpoint;
|
|
31
|
+
|
|
32
|
+
if (skipHookEndpoint?.source) {
|
|
33
|
+
const success = await requestToSkipHook(skipHookEndpoint, item);
|
|
34
|
+
|
|
35
|
+
if (success) {
|
|
36
|
+
log_debug(
|
|
37
|
+
"runInBackground: Network call forced to finish hook. Skipping hook."
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
return callback({ success: true, error: null, payload: item });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} catch (error) {
|
|
44
|
+
log_error(`runInBackground: Error: ${error.message}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return presentUI();
|
|
48
|
+
};
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { getNamespaceAndKey } from "@applicaster/zapp-react-native-utils/appUtils/contextKeysManager/utils";
|
|
2
|
+
import { log_error, log_info } from "./logger";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Boolean expressions over storage keys, used by the General Content Screen
|
|
6
|
+
* hook adapter to decide whether a hook should be skipped.
|
|
7
|
+
*
|
|
8
|
+
* The `skip_hook_storage_key` rule normally holds a comma-separated list of
|
|
9
|
+
* keys, meaning "skip when any of these exists". That covers presence only, so
|
|
10
|
+
* a condition such as "the user is logged in but has not picked a profile yet"
|
|
11
|
+
* cannot be expressed. To keep the manifest field untouched, an expression may
|
|
12
|
+
* be packed into the very same string as JSON: anything starting with `{` is
|
|
13
|
+
* parsed as an expression, anything else keeps the legacy behaviour.
|
|
14
|
+
*
|
|
15
|
+
* The expression evaluates to the SKIP condition — true means "do not present
|
|
16
|
+
* the hook" — matching the name of the rule it is configured in.
|
|
17
|
+
*
|
|
18
|
+
* Keys are written as `namespace.key` and resolved exactly like the legacy
|
|
19
|
+
* format: everything before the LAST dot is the namespace, so
|
|
20
|
+
* `com.applicaster.feature.someKey` reads `someKey` from `com.applicaster.feature`.
|
|
21
|
+
* A key with no dot falls back to the default namespace.
|
|
22
|
+
*
|
|
23
|
+
* Operators:
|
|
24
|
+
*
|
|
25
|
+
* "ns.key" shorthand for { "exists": "ns.key" }
|
|
26
|
+
* { "exists": "ns.key" } the key holds a truthy value
|
|
27
|
+
* { "missing": "ns.key" } the key holds no value
|
|
28
|
+
* { "equals": { "key": "ns.key", "value": "kids" } }
|
|
29
|
+
* { "all": [ …operands ] } AND, short-circuits on the first false
|
|
30
|
+
* { "any": [ …operands ] } OR, short-circuits on the first true
|
|
31
|
+
* { "not": operand } negation
|
|
32
|
+
*
|
|
33
|
+
* @example Show the profile selector to a logged-in user who has no profile yet
|
|
34
|
+
* ```json
|
|
35
|
+
* {
|
|
36
|
+
* "any": [
|
|
37
|
+
* { "missing": "quick-brick-login-flow.access_token" },
|
|
38
|
+
* { "exists": "user_account.profile" }
|
|
39
|
+
* ]
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
* As it is stored in the `skip_hook_storage_key` string field:
|
|
43
|
+
* ```json
|
|
44
|
+
* "skip_hook_storage_key": "{\"any\":[{\"missing\":\"quick-brick-login-flow.access_token\"},{\"exists\":\"user_account.profile\"}]}"
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example Skip an onboarding hook once it has been seen on a subscribed device
|
|
48
|
+
* ```json
|
|
49
|
+
* {
|
|
50
|
+
* "all": [
|
|
51
|
+
* "onboarding.completed",
|
|
52
|
+
* { "equals": { "key": "user_account.plan", "value": "premium" } }
|
|
53
|
+
* ]
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* Every failure mode — malformed JSON, an unknown operator, an operand of the
|
|
58
|
+
* wrong type, a storage read that throws — evaluates to false, so a broken
|
|
59
|
+
* configuration presents the hook rather than silently hiding a screen.
|
|
60
|
+
*/
|
|
61
|
+
export type SkipExpression =
|
|
62
|
+
| string
|
|
63
|
+
| { exists: string }
|
|
64
|
+
| { missing: string }
|
|
65
|
+
| { equals: { key: string; value: string } }
|
|
66
|
+
| { all: SkipExpression[] }
|
|
67
|
+
| { any: SkipExpression[] }
|
|
68
|
+
| { not: SkipExpression };
|
|
69
|
+
|
|
70
|
+
/** Reads a single storage key. Injected so evaluation stays storage-agnostic. */
|
|
71
|
+
export type ReadKey = (key: string, namespace?: string) => Promise<unknown>;
|
|
72
|
+
|
|
73
|
+
const isPlainObject = (value: unknown): value is Record<string, unknown> =>
|
|
74
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
75
|
+
|
|
76
|
+
const hasOperator = (node: Record<string, unknown>, operator: string) =>
|
|
77
|
+
Object.prototype.hasOwnProperty.call(node, operator);
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Whether a `skip_hook_storage_key` value is meant as an expression at all.
|
|
81
|
+
*
|
|
82
|
+
* Deliberately a shape check rather than a successful parse: a value that opens
|
|
83
|
+
* with `{` was written as an expression even when its JSON is broken, and must
|
|
84
|
+
* never fall back to being read as a list of storage keys.
|
|
85
|
+
*/
|
|
86
|
+
export const looksLikeSkipExpression = (input: unknown): boolean =>
|
|
87
|
+
isPlainObject(input) ||
|
|
88
|
+
(typeof input === "string" && input.trim().startsWith("{"));
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Reads a `skip_hook_storage_key` value as an expression, or returns null when
|
|
92
|
+
* it is not one — an empty value, a legacy comma-separated key list, or an
|
|
93
|
+
* expression whose JSON is malformed.
|
|
94
|
+
*/
|
|
95
|
+
export const parseSkipExpression = (input: unknown): SkipExpression | null => {
|
|
96
|
+
if (isPlainObject(input)) {
|
|
97
|
+
return input as SkipExpression;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!looksLikeSkipExpression(input)) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const trimmed = (input as string).trim();
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
const parsed = JSON.parse(trimmed);
|
|
108
|
+
|
|
109
|
+
if (!isPlainObject(parsed)) {
|
|
110
|
+
log_error(
|
|
111
|
+
`parseSkipExpression: Expression must be an object, got: ${trimmed}`
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return parsed as SkipExpression;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
log_error(
|
|
120
|
+
`parseSkipExpression: Malformed expression: ${trimmed}. Error: ${error.message}`,
|
|
121
|
+
{ error }
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const keyIsTruthy = async (key: string, readKey: ReadKey): Promise<boolean> => {
|
|
129
|
+
const { namespace, key: name } = getNamespaceAndKey(key);
|
|
130
|
+
|
|
131
|
+
return Boolean(await readKey(name, namespace));
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const evaluateEquals = async (
|
|
135
|
+
operand: { key: string; value: string },
|
|
136
|
+
readKey: ReadKey
|
|
137
|
+
): Promise<boolean> => {
|
|
138
|
+
const { namespace, key: name } = getNamespaceAndKey(operand.key);
|
|
139
|
+
const value = await readKey(name, namespace);
|
|
140
|
+
|
|
141
|
+
return value == null ? false : String(value) === String(operand.value);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const evaluateNode = async (
|
|
145
|
+
node: SkipExpression,
|
|
146
|
+
readKey: ReadKey
|
|
147
|
+
): Promise<boolean> => {
|
|
148
|
+
try {
|
|
149
|
+
if (typeof node === "string") {
|
|
150
|
+
return await keyIsTruthy(node, readKey);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (!isPlainObject(node)) {
|
|
154
|
+
log_error(
|
|
155
|
+
`evaluateSkipExpression: Not an operator: ${JSON.stringify(node)}`
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// The node came from configuration JSON, so every operand is read back as
|
|
162
|
+
// unknown and type-checked here rather than trusted from the union.
|
|
163
|
+
const operator = node as Record<string, unknown>;
|
|
164
|
+
|
|
165
|
+
if (
|
|
166
|
+
hasOperator(operator, "exists") &&
|
|
167
|
+
typeof operator.exists === "string"
|
|
168
|
+
) {
|
|
169
|
+
return await keyIsTruthy(operator.exists, readKey);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (
|
|
173
|
+
hasOperator(operator, "missing") &&
|
|
174
|
+
typeof operator.missing === "string"
|
|
175
|
+
) {
|
|
176
|
+
return !(await keyIsTruthy(operator.missing, readKey));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (hasOperator(operator, "equals") && isPlainObject(operator.equals)) {
|
|
180
|
+
return await evaluateEquals(
|
|
181
|
+
operator.equals as { key: string; value: string },
|
|
182
|
+
readKey
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (hasOperator(operator, "all") && Array.isArray(operator.all)) {
|
|
187
|
+
for (const operand of operator.all) {
|
|
188
|
+
if (!(await evaluateNode(operand, readKey))) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// An empty operand list carries no condition, so it stays false rather
|
|
194
|
+
// than skipping the hook on the vacuous truth of an empty AND.
|
|
195
|
+
return operator.all.length > 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (hasOperator(operator, "any") && Array.isArray(operator.any)) {
|
|
199
|
+
for (const operand of operator.any) {
|
|
200
|
+
if (await evaluateNode(operand, readKey)) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (hasOperator(operator, "not")) {
|
|
209
|
+
return !(await evaluateNode(operator.not as SkipExpression, readKey));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
log_error(
|
|
213
|
+
`evaluateSkipExpression: Unknown or malformed operator: ${JSON.stringify(
|
|
214
|
+
node
|
|
215
|
+
)}`
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
return false;
|
|
219
|
+
} catch (error) {
|
|
220
|
+
log_error(
|
|
221
|
+
`evaluateSkipExpression: Error: ${error.message} evaluating: ${JSON.stringify(
|
|
222
|
+
node
|
|
223
|
+
)}`,
|
|
224
|
+
{ error }
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Evaluates a parsed expression to the skip decision. A null expression — the
|
|
233
|
+
* field held no expression — is not a condition, so nothing is skipped.
|
|
234
|
+
*/
|
|
235
|
+
export const evaluateSkipExpression = async (
|
|
236
|
+
expression: SkipExpression | null,
|
|
237
|
+
readKey: ReadKey
|
|
238
|
+
): Promise<boolean> => {
|
|
239
|
+
if (!expression) {
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const shouldSkip = await evaluateNode(expression, readKey);
|
|
244
|
+
|
|
245
|
+
log_info(
|
|
246
|
+
`evaluateSkipExpression: Expression evaluated to ${shouldSkip}, ${
|
|
247
|
+
shouldSkip ? "skipping hook" : "proceeding with hook"
|
|
248
|
+
}`
|
|
249
|
+
);
|
|
250
|
+
|
|
251
|
+
return shouldSkip;
|
|
252
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { getNamespaceAndKey } from "@applicaster/zapp-react-native-utils/appUtils/contextKeysManager/utils";
|
|
2
|
+
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
3
|
+
import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
|
|
4
|
+
import {
|
|
5
|
+
looksLikeSkipExpression,
|
|
6
|
+
parseSkipExpression,
|
|
7
|
+
evaluateSkipExpression,
|
|
8
|
+
} from "./skipExpression";
|
|
9
|
+
import { log_error, log_info } from "./logger";
|
|
10
|
+
|
|
11
|
+
type ParseKey = { key: string; namespace?: string };
|
|
12
|
+
|
|
13
|
+
export function parseKeyEntries(input: string): ParseKey[] {
|
|
14
|
+
return input.split(",").flatMap((item) => {
|
|
15
|
+
const trimmed = item.trim();
|
|
16
|
+
|
|
17
|
+
return trimmed ? getNamespaceAndKey(trimmed) : [];
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const getKeyToSkipHook = async (key: string, namespace?: string) => {
|
|
22
|
+
const value = await sessionStorage.getItem(key, namespace);
|
|
23
|
+
|
|
24
|
+
if (value) {
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return await localStorage.getItem(key, namespace);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Decides whether the hook should be skipped, from the `skip_hook_storage_key`
|
|
33
|
+
* rule. The value is either a comma-separated key list — skip when ANY of them
|
|
34
|
+
* exists — or, packed into the same string, a JSON boolean expression over
|
|
35
|
+
* storage keys. See `skipExpression.ts` for the expression format.
|
|
36
|
+
*/
|
|
37
|
+
export const shouldSkipHook = async (
|
|
38
|
+
skipHookIfKeysExist?: string
|
|
39
|
+
): Promise<boolean> => {
|
|
40
|
+
if (!skipHookIfKeysExist?.trim()) {
|
|
41
|
+
log_info("shouldSkipHook: No skipping condition provided");
|
|
42
|
+
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (looksLikeSkipExpression(skipHookIfKeysExist)) {
|
|
47
|
+
return await evaluateSkipExpression(
|
|
48
|
+
parseSkipExpression(skipHookIfKeysExist),
|
|
49
|
+
getKeyToSkipHook
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const keyEntries = parseKeyEntries(skipHookIfKeysExist);
|
|
54
|
+
|
|
55
|
+
if (keyEntries.length === 0) {
|
|
56
|
+
log_info("shouldSkipHook: No valid keys provided");
|
|
57
|
+
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
for (const entry of keyEntries) {
|
|
62
|
+
try {
|
|
63
|
+
const value = await getKeyToSkipHook(entry.key, entry.namespace);
|
|
64
|
+
|
|
65
|
+
if (value) {
|
|
66
|
+
log_info(
|
|
67
|
+
`shouldSkipHook: Hook will be skipped due to: ${
|
|
68
|
+
entry.namespace ?? ""
|
|
69
|
+
} ${entry.key}. Finishing hook flow`
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
} catch (error) {
|
|
75
|
+
log_error(
|
|
76
|
+
`shouldSkipHook: Error: ${error.message} checking key: ${
|
|
77
|
+
entry.namespace ?? ""
|
|
78
|
+
} ${entry.key}`,
|
|
79
|
+
{ error }
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
log_info(
|
|
85
|
+
// eslint-disable-next-line max-len
|
|
86
|
+
"shouldSkipHook: No skipping condition met, none of the provided keys found in storage, proceeding with hook"
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
return false;
|
|
90
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
type Props = {
|
|
4
|
+
children: React.ReactElement;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* On native platforms the river `ComponentsMap` registers its own initial focus,
|
|
9
|
+
* so a hook-presented general content screen needs no extra focus wrapper here.
|
|
10
|
+
* The web counterpart (`index.web.tsx`) recreates the content focus group that
|
|
11
|
+
* the `River` wrapper would normally provide.
|
|
12
|
+
*/
|
|
13
|
+
export const HookContentFocusGroup = ({ children }: Props) => <>{children}</>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { StyleSheet } from "react-native";
|
|
3
|
+
import { shallow } from "zustand/shallow";
|
|
4
|
+
|
|
5
|
+
import { FocusableGroup } from "../../FocusableGroup";
|
|
6
|
+
import {
|
|
7
|
+
useContentId,
|
|
8
|
+
useNavbarId,
|
|
9
|
+
usePathname,
|
|
10
|
+
} from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
11
|
+
import { useZappHookModalStore } from "../../../Contexts/ZappHookModalContext";
|
|
12
|
+
|
|
13
|
+
import { useInitialFocus } from "../../Screen/TV/hooks";
|
|
14
|
+
|
|
15
|
+
const styles = StyleSheet.create({
|
|
16
|
+
container: { flex: 1 },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
type Props = {
|
|
20
|
+
children: React.ReactElement;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A general content screen presented as a full-screen hook is rendered straight
|
|
25
|
+
* through `ComponentsMap`, bypassing the web `River` wrapper. That wrapper is what
|
|
26
|
+
* normally creates the `quick-brick-content` FocusableGroup (with `preferredFocus`)
|
|
27
|
+
* the focus manager relies on and what lets initial focus land on the content.
|
|
28
|
+
*
|
|
29
|
+
* Without it the hook screen renders but nothing is focusable on web TV. This
|
|
30
|
+
* recreates that content group and triggers initial focus, mirroring `River`.
|
|
31
|
+
*/
|
|
32
|
+
const FocusedHookContent = ({ children }: Props) => {
|
|
33
|
+
const contentId = useContentId();
|
|
34
|
+
const navbarId = useNavbarId();
|
|
35
|
+
const pathname = usePathname();
|
|
36
|
+
|
|
37
|
+
useInitialFocus();
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<FocusableGroup
|
|
41
|
+
id={contentId}
|
|
42
|
+
// Nest under the hook-modal route so the focus manager treats this as the
|
|
43
|
+
// active screen's content node; `useInitialFocus` targets the same route.
|
|
44
|
+
groupId={pathname}
|
|
45
|
+
nextFocusUp={navbarId}
|
|
46
|
+
preferredFocus
|
|
47
|
+
shouldUsePreferredFocus
|
|
48
|
+
style={styles.container}
|
|
49
|
+
>
|
|
50
|
+
{React.cloneElement(children, { groupId: contentId })}
|
|
51
|
+
</FocusableGroup>
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const HookContentFocusGroup = ({ children }: Props) => {
|
|
56
|
+
const isRunningInBackground = useZappHookModalStore(
|
|
57
|
+
(state) => state.isRunningInBackground,
|
|
58
|
+
shallow
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// A hook presented full screen (either as a `/hooks/<id>` screen or a
|
|
62
|
+
// full-screen modal) needs the content focus group. Only background runs,
|
|
63
|
+
// which render invisibly, must be left alone so they don't steal focus.
|
|
64
|
+
if (isRunningInBackground) {
|
|
65
|
+
return <>{children}</>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return <FocusedHookContent>{children}</FocusedHookContent>;
|
|
69
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { StyleSheet, View } from "react-native";
|
|
3
|
+
|
|
4
|
+
const styles = StyleSheet.create({
|
|
5
|
+
row: { flexDirection: "row" },
|
|
6
|
+
basis: {
|
|
7
|
+
maxWidth: "100%",
|
|
8
|
+
flexBasis: "100%",
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Constrains its child to exactly the available parent width.
|
|
18
|
+
*
|
|
19
|
+
* UI components such as Hero and List render their items inside a parent
|
|
20
|
+
* `ScrollView` (e.g. when wrapped by tabs). A child placed directly in a
|
|
21
|
+
* scroll container can size itself to its own content rather than to the
|
|
22
|
+
* viewport, which causes items to be measured at a stale width and resize
|
|
23
|
+
* unexpectedly after layout changes such as device rotation.
|
|
24
|
+
*
|
|
25
|
+
* Wrapping the content in a `flexDirection: "row"` parent with a
|
|
26
|
+
* `flexBasis: "100%"` / `maxWidth: "100%"` child forces the child to
|
|
27
|
+
* re-derive its width from the parent on every layout pass instead of
|
|
28
|
+
* caching a measured pixel width, keeping it full-width and stable.
|
|
29
|
+
*
|
|
30
|
+
* @param children - The content to render at full parent width.
|
|
31
|
+
*/
|
|
32
|
+
export function FullWidthRow({ children }: Props) {
|
|
33
|
+
return (
|
|
34
|
+
<View style={styles.row}>
|
|
35
|
+
<View style={styles.basis}>{children}</View>
|
|
36
|
+
</View>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -37,13 +37,16 @@ function getAssetValue(asset, flavour, fallbackAsset = null) {
|
|
|
37
37
|
return null;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
if (typeof asset === "string") return asset;
|
|
40
|
+
if (typeof asset === "string") return fallbackAsset || asset;
|
|
41
41
|
|
|
42
42
|
if (Array.isArray(asset)) {
|
|
43
43
|
const flavourIndex = Number(flavour.replace("flavour_", ""));
|
|
44
|
-
if (flavour && flavourIndex > -1) return asset[flavourIndex - 1];
|
|
45
44
|
|
|
46
|
-
|
|
45
|
+
if (flavour && flavourIndex > -1) {
|
|
46
|
+
return fallbackAsset || asset[flavourIndex - 1];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return fallbackAsset || asset[0];
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
return asset.src || fallbackAsset;
|
|
@@ -109,13 +112,21 @@ export const ActionButton = React.memo(function ActionButtonComponent(
|
|
|
109
112
|
<Image
|
|
110
113
|
fadeDuration={0}
|
|
111
114
|
style={asset?.style || props?.style}
|
|
112
|
-
uri={getAssetValue(
|
|
115
|
+
uri={getAssetValue(
|
|
116
|
+
actionState.asset,
|
|
117
|
+
flavour,
|
|
118
|
+
actionState.state === 1 ? asset?.src.active : asset?.src.inactive
|
|
119
|
+
)}
|
|
113
120
|
{...asset?.props}
|
|
114
121
|
/>
|
|
115
122
|
) : (
|
|
116
123
|
<AssetComponent
|
|
117
124
|
flavour={flavour}
|
|
118
|
-
asset={getAssetValue(
|
|
125
|
+
asset={getAssetValue(
|
|
126
|
+
asset,
|
|
127
|
+
flavour,
|
|
128
|
+
actionState.state === 1 ? asset?.src.active : asset?.src.inactive
|
|
129
|
+
)}
|
|
119
130
|
cellUUID={cellUUID}
|
|
120
131
|
{...(props?.extraProps ?? {})}
|
|
121
132
|
/>
|
package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts
CHANGED
|
@@ -6,28 +6,54 @@ import {
|
|
|
6
6
|
describe("ActionButtonsCore placement", () => {
|
|
7
7
|
const buttons = { type: "View", name: "buttons" };
|
|
8
8
|
|
|
9
|
-
const
|
|
10
|
-
{ name: "
|
|
11
|
-
{ name: "
|
|
12
|
-
{ name: "
|
|
9
|
+
const slots = [
|
|
10
|
+
{ name: "text_label_1", element: { type: "View", id: "label_1" } },
|
|
11
|
+
{ name: "text_label_2", element: { type: "View", id: "label_2" } },
|
|
12
|
+
{ name: "text_label_3", element: { type: "View", id: "label_3" } },
|
|
13
13
|
];
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
{ name: "below_label_1" },
|
|
17
|
-
{ name: "below_label_2" },
|
|
18
|
-
{ name: "below_label_3" },
|
|
19
|
-
];
|
|
15
|
+
const labels = slots.map((slot) => slot.element);
|
|
20
16
|
|
|
21
17
|
it("inserts buttons after the matching label", () => {
|
|
22
18
|
expect(
|
|
23
|
-
insertBetweenLabels({ position: "
|
|
24
|
-
).toEqual([
|
|
19
|
+
insertBetweenLabels({ position: "below_text_label_2" }, buttons, slots)
|
|
20
|
+
).toEqual([labels[0], labels[1], buttons, labels[2]]);
|
|
25
21
|
});
|
|
26
22
|
|
|
27
23
|
it("inserts buttons before the matching label", () => {
|
|
28
24
|
expect(
|
|
29
|
-
insertBetweenLabels({ position: "
|
|
30
|
-
).toEqual([
|
|
25
|
+
insertBetweenLabels({ position: "above_text_label_2" }, buttons, slots)
|
|
26
|
+
).toEqual([labels[0], buttons, labels[1], labels[2]]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("inserts buttons after the matching label on a plain name match", () => {
|
|
30
|
+
expect(
|
|
31
|
+
insertBetweenLabels({ position: "text_label_2" }, buttons, slots)
|
|
32
|
+
).toEqual([labels[0], labels[1], buttons, labels[2]]);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("keeps the slot when its label is empty (null element)", () => {
|
|
36
|
+
const slotsWithEmpty = [
|
|
37
|
+
{ name: "text_label_1", element: { id: "label_1" } },
|
|
38
|
+
{ name: "text_label_2", element: null },
|
|
39
|
+
{ name: "text_label_3", element: { id: "label_3" } },
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
expect(
|
|
43
|
+
insertBetweenLabels(
|
|
44
|
+
{ position: "above_text_label_2" },
|
|
45
|
+
buttons,
|
|
46
|
+
slotsWithEmpty
|
|
47
|
+
)
|
|
48
|
+
).toEqual([{ id: "label_1" }, buttons, { id: "label_3" }]);
|
|
49
|
+
|
|
50
|
+
expect(
|
|
51
|
+
insertBetweenLabels(
|
|
52
|
+
{ position: "below_text_label_2" },
|
|
53
|
+
buttons,
|
|
54
|
+
slotsWithEmpty
|
|
55
|
+
)
|
|
56
|
+
).toEqual([{ id: "label_1" }, buttons, { id: "label_3" }]);
|
|
31
57
|
});
|
|
32
58
|
|
|
33
59
|
it("prepends buttons only when on_top is allowed", () => {
|
|
@@ -35,17 +61,17 @@ describe("ActionButtonsCore placement", () => {
|
|
|
35
61
|
insertBetweenLabels(
|
|
36
62
|
{ position: "on_top", allowOnTop: true },
|
|
37
63
|
buttons,
|
|
38
|
-
|
|
64
|
+
slots
|
|
39
65
|
)
|
|
40
|
-
).toEqual([buttons, ...
|
|
66
|
+
).toEqual([buttons, ...labels]);
|
|
41
67
|
|
|
42
68
|
expect(
|
|
43
69
|
insertBetweenLabels(
|
|
44
70
|
{ position: "on_top", allowOnTop: false },
|
|
45
71
|
buttons,
|
|
46
|
-
|
|
72
|
+
slots
|
|
47
73
|
)
|
|
48
|
-
).toEqual(
|
|
74
|
+
).toEqual(labels);
|
|
49
75
|
});
|
|
50
76
|
|
|
51
77
|
it("appends buttons when appendWhenMissing is enabled", () => {
|
|
@@ -53,9 +79,9 @@ describe("ActionButtonsCore placement", () => {
|
|
|
53
79
|
insertBetweenLabels(
|
|
54
80
|
{ position: "unknown", appendWhenMissing: true },
|
|
55
81
|
buttons,
|
|
56
|
-
|
|
82
|
+
slots
|
|
57
83
|
)
|
|
58
|
-
).toEqual([...
|
|
84
|
+
).toEqual([...labels, buttons]);
|
|
59
85
|
});
|
|
60
86
|
|
|
61
87
|
it("returns labels unchanged when appendWhenMissing is disabled", () => {
|
|
@@ -63,9 +89,9 @@ describe("ActionButtonsCore placement", () => {
|
|
|
63
89
|
insertBetweenLabels(
|
|
64
90
|
{ position: "unknown", appendWhenMissing: false },
|
|
65
91
|
buttons,
|
|
66
|
-
|
|
92
|
+
slots
|
|
67
93
|
)
|
|
68
|
-
).toEqual(
|
|
94
|
+
).toEqual(labels);
|
|
69
95
|
});
|
|
70
96
|
|
|
71
97
|
const labelContainers = [
|