@applicaster/zapp-react-native-ui-components 16.0.0-rc.76 → 16.0.0-rc.78
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/Cell/Cell.tsx +3 -6
- package/Components/GeneralContentScreen/hookAdapter/__tests__/skipExpression.test.ts +294 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +64 -0
- package/Components/GeneralContentScreen/hookAdapter/skipExpression.ts +252 -0
- package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +18 -0
- package/Components/ModalComponent/SortableList.web.tsx +2 -70
- package/Components/ModalComponent/__tests__/SortableList.web.test.tsx +16 -0
- 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/package.json +5 -5
package/Components/Cell/Cell.tsx
CHANGED
|
@@ -134,7 +134,7 @@ export class CellComponent extends React.Component<Props, State> {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
onFocus(focusable
|
|
137
|
+
onFocus(focusable) {
|
|
138
138
|
const {
|
|
139
139
|
item: { id, title },
|
|
140
140
|
shouldScrollVertically,
|
|
@@ -145,10 +145,7 @@ export class CellComponent extends React.Component<Props, State> {
|
|
|
145
145
|
if (isFocusable) {
|
|
146
146
|
this.setState({ cellFocused: true });
|
|
147
147
|
|
|
148
|
-
if (
|
|
149
|
-
shouldUpdate &&
|
|
150
|
-
shouldScrollVertically?.(mouse, focusable, id, title)
|
|
151
|
-
) {
|
|
148
|
+
if (shouldUpdate && shouldScrollVertically?.(focusable, id, title)) {
|
|
152
149
|
this.scrollVertically(focusable);
|
|
153
150
|
}
|
|
154
151
|
}
|
|
@@ -262,7 +259,7 @@ export class CellComponent extends React.Component<Props, State> {
|
|
|
262
259
|
const handleFocus = (focusable, mouse) => {
|
|
263
260
|
const focusFn = onFocus || noop;
|
|
264
261
|
focusFn(focusable, mouse);
|
|
265
|
-
this.onFocus(focusable
|
|
262
|
+
this.onFocus(focusable);
|
|
266
263
|
};
|
|
267
264
|
|
|
268
265
|
if (this.state.hasFocusableInside) {
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import {
|
|
2
|
+
looksLikeSkipExpression,
|
|
3
|
+
parseSkipExpression,
|
|
4
|
+
evaluateSkipExpression,
|
|
5
|
+
} from "../skipExpression";
|
|
6
|
+
|
|
7
|
+
jest.mock("../logger", () => ({
|
|
8
|
+
log_debug: jest.fn(),
|
|
9
|
+
log_error: jest.fn(),
|
|
10
|
+
log_info: jest.fn(),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
const TOKEN = "quick-brick-login-flow.access_token";
|
|
14
|
+
const PROFILE = "user_account.profile";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Stands in for `getKeyToSkipHook`: resolves a "namespace.key" store, so the
|
|
18
|
+
* expression evaluator is exercised against real lookups rather than mocks.
|
|
19
|
+
*/
|
|
20
|
+
const storage = (store: Record<string, unknown>) =>
|
|
21
|
+
jest.fn((key: string, namespace?: string) =>
|
|
22
|
+
Promise.resolve(store[`${namespace}.${key}`])
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const evaluate = (expression: unknown, store: Record<string, unknown> = {}) =>
|
|
26
|
+
evaluateSkipExpression(parseSkipExpression(expression), storage(store));
|
|
27
|
+
|
|
28
|
+
describe("looksLikeSkipExpression", () => {
|
|
29
|
+
it("recognises a JSON object, whatever its content", () => {
|
|
30
|
+
expect(looksLikeSkipExpression('{"exists":"ns.key"}')).toBe(true);
|
|
31
|
+
expect(looksLikeSkipExpression(' {"exists":"ns.key"} ')).toBe(true);
|
|
32
|
+
expect(looksLikeSkipExpression({ exists: "ns.key" })).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("recognises a malformed expression, so it is never read as a key list", () => {
|
|
36
|
+
expect(looksLikeSkipExpression('{"any":')).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("rejects a legacy comma-separated key list", () => {
|
|
40
|
+
expect(looksLikeSkipExpression("ns1.key1, ns2.key2")).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("rejects empty and missing input", () => {
|
|
44
|
+
expect(looksLikeSkipExpression("")).toBe(false);
|
|
45
|
+
expect(looksLikeSkipExpression(" ")).toBe(false);
|
|
46
|
+
expect(looksLikeSkipExpression(undefined)).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("parseSkipExpression", () => {
|
|
51
|
+
it("parses a JSON string into an expression object", () => {
|
|
52
|
+
expect(parseSkipExpression('{"exists":"ns.key"}')).toEqual({
|
|
53
|
+
exists: "ns.key",
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("ignores leading and trailing whitespace around the JSON", () => {
|
|
58
|
+
expect(parseSkipExpression(' {"exists":"ns.key"} ')).toEqual({
|
|
59
|
+
exists: "ns.key",
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("accepts an expression that is already an object", () => {
|
|
64
|
+
expect(parseSkipExpression({ exists: "ns.key" })).toEqual({
|
|
65
|
+
exists: "ns.key",
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("returns null for a legacy comma-separated key list", () => {
|
|
70
|
+
expect(parseSkipExpression("ns1.key1, ns2.key2")).toBeNull();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("returns null for a malformed JSON object", () => {
|
|
74
|
+
expect(parseSkipExpression('{"exists":')).toBeNull();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("returns null for empty and missing input", () => {
|
|
78
|
+
expect(parseSkipExpression("")).toBeNull();
|
|
79
|
+
expect(parseSkipExpression(undefined)).toBeNull();
|
|
80
|
+
expect(parseSkipExpression(null)).toBeNull();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("returns null for a JSON array, which is not a valid expression", () => {
|
|
84
|
+
expect(parseSkipExpression('["ns.key"]')).toBeNull();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe("evaluateSkipExpression", () => {
|
|
89
|
+
it("returns false when there is no expression", async () => {
|
|
90
|
+
await expect(evaluateSkipExpression(null, storage({}))).resolves.toBe(
|
|
91
|
+
false
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("exists", () => {
|
|
96
|
+
it("is true when the key holds a value", async () => {
|
|
97
|
+
await expect(
|
|
98
|
+
evaluate({ exists: "ns.key" }, { "ns.key": "value" })
|
|
99
|
+
).resolves.toBe(true);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("is false when the key is absent", async () => {
|
|
103
|
+
await expect(evaluate({ exists: "ns.key" })).resolves.toBe(false);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("is false when the key holds an empty string", async () => {
|
|
107
|
+
await expect(
|
|
108
|
+
evaluate({ exists: "ns.key" }, { "ns.key": "" })
|
|
109
|
+
).resolves.toBe(false);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("splits the namespace on the last dot, like the legacy format", async () => {
|
|
113
|
+
const readKey = storage({ "com.applicaster.feature.someKey": "value" });
|
|
114
|
+
|
|
115
|
+
await evaluateSkipExpression(
|
|
116
|
+
{ exists: "com.applicaster.feature.someKey" },
|
|
117
|
+
readKey
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
expect(readKey).toHaveBeenCalledWith(
|
|
121
|
+
"someKey",
|
|
122
|
+
"com.applicaster.feature"
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("treats a bare string operand as a shorthand for exists", async () => {
|
|
127
|
+
await expect(
|
|
128
|
+
evaluateSkipExpression("ns.key", storage({ "ns.key": "value" }))
|
|
129
|
+
).resolves.toBe(true);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("missing", () => {
|
|
134
|
+
it("is true when the key is absent", async () => {
|
|
135
|
+
await expect(evaluate({ missing: "ns.key" })).resolves.toBe(true);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("is false when the key holds a value", async () => {
|
|
139
|
+
await expect(
|
|
140
|
+
evaluate({ missing: "ns.key" }, { "ns.key": "value" })
|
|
141
|
+
).resolves.toBe(false);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("equals", () => {
|
|
146
|
+
it("is true when the stored value matches", async () => {
|
|
147
|
+
await expect(
|
|
148
|
+
evaluate(
|
|
149
|
+
{ equals: { key: "ns.key", value: "kids" } },
|
|
150
|
+
{ "ns.key": "kids" }
|
|
151
|
+
)
|
|
152
|
+
).resolves.toBe(true);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("is false when the stored value differs", async () => {
|
|
156
|
+
await expect(
|
|
157
|
+
evaluate(
|
|
158
|
+
{ equals: { key: "ns.key", value: "kids" } },
|
|
159
|
+
{ "ns.key": "adults" }
|
|
160
|
+
)
|
|
161
|
+
).resolves.toBe(false);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("compares a non-string stored value by its string form", async () => {
|
|
165
|
+
await expect(
|
|
166
|
+
evaluate({ equals: { key: "ns.key", value: "42" } }, { "ns.key": 42 })
|
|
167
|
+
).resolves.toBe(true);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe("all", () => {
|
|
172
|
+
it("is true only when every operand is true", async () => {
|
|
173
|
+
await expect(
|
|
174
|
+
evaluate({ all: ["ns.a", "ns.b"] }, { "ns.a": "1", "ns.b": "2" })
|
|
175
|
+
).resolves.toBe(true);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("is false when one operand is false", async () => {
|
|
179
|
+
await expect(
|
|
180
|
+
evaluate({ all: ["ns.a", "ns.b"] }, { "ns.a": "1" })
|
|
181
|
+
).resolves.toBe(false);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("stops reading storage after the first false operand", async () => {
|
|
185
|
+
const readKey = storage({ "ns.b": "2" });
|
|
186
|
+
|
|
187
|
+
await evaluateSkipExpression({ all: ["ns.a", "ns.b"] }, readKey);
|
|
188
|
+
|
|
189
|
+
expect(readKey).toHaveBeenCalledTimes(1);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("is false for an empty operand list", async () => {
|
|
193
|
+
await expect(evaluate({ all: [] })).resolves.toBe(false);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe("any", () => {
|
|
198
|
+
it("is true when one operand is true", async () => {
|
|
199
|
+
await expect(
|
|
200
|
+
evaluate({ any: ["ns.a", "ns.b"] }, { "ns.b": "2" })
|
|
201
|
+
).resolves.toBe(true);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("is false when every operand is false", async () => {
|
|
205
|
+
await expect(evaluate({ any: ["ns.a", "ns.b"] })).resolves.toBe(false);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("stops reading storage after the first true operand", async () => {
|
|
209
|
+
const readKey = storage({ "ns.a": "1", "ns.b": "2" });
|
|
210
|
+
|
|
211
|
+
await evaluateSkipExpression({ any: ["ns.a", "ns.b"] }, readKey);
|
|
212
|
+
|
|
213
|
+
expect(readKey).toHaveBeenCalledTimes(1);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("is false for an empty operand list", async () => {
|
|
217
|
+
await expect(evaluate({ any: [] })).resolves.toBe(false);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
describe("not", () => {
|
|
222
|
+
it("inverts a true operand", async () => {
|
|
223
|
+
await expect(
|
|
224
|
+
evaluate({ not: "ns.key" }, { "ns.key": "value" })
|
|
225
|
+
).resolves.toBe(false);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("inverts a false operand", async () => {
|
|
229
|
+
await expect(evaluate({ not: "ns.key" })).resolves.toBe(true);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
describe("malformed expressions fail open", () => {
|
|
234
|
+
it("is false for an unknown operator", async () => {
|
|
235
|
+
await expect(evaluate({ matches: "ns.key" })).resolves.toBe(false);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("is false for an operator carrying the wrong operand type", async () => {
|
|
239
|
+
await expect(evaluate({ exists: 42 })).resolves.toBe(false);
|
|
240
|
+
await expect(evaluate({ all: "ns.key" })).resolves.toBe(false);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("is false for an operand list holding a malformed node", async () => {
|
|
244
|
+
await expect(
|
|
245
|
+
evaluate({ all: ["ns.a", { matches: "ns.b" }] }, { "ns.a": "1" })
|
|
246
|
+
).resolves.toBe(false);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("is false when a storage read throws", async () => {
|
|
250
|
+
const readKey = jest.fn(() => Promise.reject(new Error("storage error")));
|
|
251
|
+
|
|
252
|
+
await expect(
|
|
253
|
+
evaluateSkipExpression({ exists: "ns.key" }, readKey)
|
|
254
|
+
).resolves.toBe(false);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("keeps evaluating the other operands when one storage read throws", async () => {
|
|
258
|
+
const readKey = jest.fn((key: string) =>
|
|
259
|
+
key === "a"
|
|
260
|
+
? Promise.reject(new Error("storage error"))
|
|
261
|
+
: Promise.resolve("value")
|
|
262
|
+
);
|
|
263
|
+
|
|
264
|
+
await expect(
|
|
265
|
+
evaluateSkipExpression({ any: ["ns.a", "ns.b"] }, readKey)
|
|
266
|
+
).resolves.toBe(true);
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
describe("profile selector scenario", () => {
|
|
271
|
+
const skipProfileSelector = {
|
|
272
|
+
any: [{ missing: TOKEN }, { exists: PROFILE }],
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
it("shows the hook to a logged-in user who has not picked a profile yet", async () => {
|
|
276
|
+
await expect(
|
|
277
|
+
evaluate(skipProfileSelector, { [TOKEN]: "a-token" })
|
|
278
|
+
).resolves.toBe(false);
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it("skips the hook for a logged-out user", async () => {
|
|
282
|
+
await expect(evaluate(skipProfileSelector)).resolves.toBe(true);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("skips the hook once a profile has been picked", async () => {
|
|
286
|
+
await expect(
|
|
287
|
+
evaluate(skipProfileSelector, {
|
|
288
|
+
[TOKEN]: "a-token",
|
|
289
|
+
[PROFILE]: "profile-id",
|
|
290
|
+
})
|
|
291
|
+
).resolves.toBe(true);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
});
|
|
@@ -122,3 +122,67 @@ describe("shouldSkipHook", () => {
|
|
|
122
122
|
await expect(shouldSkipHook("ns1.key1, ns2.key2")).resolves.toBe(true);
|
|
123
123
|
});
|
|
124
124
|
});
|
|
125
|
+
|
|
126
|
+
describe("shouldSkipHook with a packed expression", () => {
|
|
127
|
+
const SKIP_UNLESS_LOGGED_IN_WITHOUT_PROFILE = JSON.stringify({
|
|
128
|
+
any: [
|
|
129
|
+
{ missing: "quick-brick-login-flow.access_token" },
|
|
130
|
+
{ exists: "user_account.profile" },
|
|
131
|
+
],
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const storedKeys = (store: Record<string, string>) => {
|
|
135
|
+
mockSessionGetItem.mockImplementation((key, namespace) =>
|
|
136
|
+
Promise.resolve(store[`${namespace}.${key}`] ?? null)
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
mockLocalGetItem.mockResolvedValue(null);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
beforeEach(() => {
|
|
143
|
+
jest.clearAllMocks();
|
|
144
|
+
storedKeys({});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("does not skip for a logged-in user who has not picked a profile yet", async () => {
|
|
148
|
+
storedKeys({ "quick-brick-login-flow.access_token": "a-token" });
|
|
149
|
+
|
|
150
|
+
await expect(
|
|
151
|
+
shouldSkipHook(SKIP_UNLESS_LOGGED_IN_WITHOUT_PROFILE)
|
|
152
|
+
).resolves.toBe(false);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("skips for a logged-out user", async () => {
|
|
156
|
+
await expect(
|
|
157
|
+
shouldSkipHook(SKIP_UNLESS_LOGGED_IN_WITHOUT_PROFILE)
|
|
158
|
+
).resolves.toBe(true);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("skips once a profile has been picked", async () => {
|
|
162
|
+
storedKeys({
|
|
163
|
+
"quick-brick-login-flow.access_token": "a-token",
|
|
164
|
+
"user_account.profile": "profile-id",
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
await expect(
|
|
168
|
+
shouldSkipHook(SKIP_UNLESS_LOGGED_IN_WITHOUT_PROFILE)
|
|
169
|
+
).resolves.toBe(true);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("falls back to local storage for a key the session does not hold", async () => {
|
|
173
|
+
mockLocalGetItem.mockResolvedValue("a-token");
|
|
174
|
+
|
|
175
|
+
await expect(
|
|
176
|
+
shouldSkipHook(JSON.stringify({ exists: "ns.key" }))
|
|
177
|
+
).resolves.toBe(true);
|
|
178
|
+
|
|
179
|
+
expect(mockSessionGetItem).toHaveBeenCalledWith("key", "ns");
|
|
180
|
+
expect(mockLocalGetItem).toHaveBeenCalledWith("key", "ns");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("returns false for a malformed expression instead of reading storage", async () => {
|
|
184
|
+
await expect(shouldSkipHook('{"any":')).resolves.toBe(false);
|
|
185
|
+
expect(mockSessionGetItem).not.toHaveBeenCalled();
|
|
186
|
+
expect(mockLocalGetItem).not.toHaveBeenCalled();
|
|
187
|
+
});
|
|
188
|
+
});
|
|
@@ -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
|
+
};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { getNamespaceAndKey } from "@applicaster/zapp-react-native-utils/appUtils/contextKeysManager/utils";
|
|
2
2
|
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
3
3
|
import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
|
|
4
|
+
import {
|
|
5
|
+
looksLikeSkipExpression,
|
|
6
|
+
parseSkipExpression,
|
|
7
|
+
evaluateSkipExpression,
|
|
8
|
+
} from "./skipExpression";
|
|
4
9
|
import { log_error, log_info } from "./logger";
|
|
5
10
|
|
|
6
11
|
type ParseKey = { key: string; namespace?: string };
|
|
@@ -23,6 +28,12 @@ export const getKeyToSkipHook = async (key: string, namespace?: string) => {
|
|
|
23
28
|
return await localStorage.getItem(key, namespace);
|
|
24
29
|
};
|
|
25
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
|
+
*/
|
|
26
37
|
export const shouldSkipHook = async (
|
|
27
38
|
skipHookIfKeysExist?: string
|
|
28
39
|
): Promise<boolean> => {
|
|
@@ -32,6 +43,13 @@ export const shouldSkipHook = async (
|
|
|
32
43
|
return false;
|
|
33
44
|
}
|
|
34
45
|
|
|
46
|
+
if (looksLikeSkipExpression(skipHookIfKeysExist)) {
|
|
47
|
+
return await evaluateSkipExpression(
|
|
48
|
+
parseSkipExpression(skipHookIfKeysExist),
|
|
49
|
+
getKeyToSkipHook
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
35
53
|
const keyEntries = parseKeyEntries(skipHookIfKeysExist);
|
|
36
54
|
|
|
37
55
|
if (keyEntries.length === 0) {
|
|
@@ -1,37 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const DEFAULT_HEADERS: any[] = [];
|
|
5
|
-
const DEFAULT_SORTABLE_DATA: any[] = [];
|
|
6
|
-
|
|
7
|
-
const renderHeaderComponent = (component: any) => {
|
|
8
|
-
if (!component) return null;
|
|
9
|
-
if (React.isValidElement(component)) return component;
|
|
10
|
-
|
|
11
|
-
if (typeof component === "function") {
|
|
12
|
-
const HeaderComponent = component;
|
|
13
|
-
|
|
14
|
-
return <HeaderComponent />;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return null;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const SortableListHeader = ({
|
|
21
|
-
title,
|
|
22
|
-
style,
|
|
23
|
-
}: {
|
|
24
|
-
title?: string;
|
|
25
|
-
style?: ViewStyle;
|
|
26
|
-
}) => {
|
|
27
|
-
const displayTitle = typeof title === "string" ? title : String(title ?? "");
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<View style={style}>
|
|
31
|
-
{displayTitle ? <Text>{displayTitle}</Text> : null}
|
|
32
|
-
</View>
|
|
33
|
-
);
|
|
34
|
-
};
|
|
2
|
+
import type { ViewStyle } from "react-native";
|
|
35
3
|
|
|
36
4
|
export type SortableListProps = {
|
|
37
5
|
scrollViewStyle?: ViewStyle;
|
|
@@ -63,40 +31,4 @@ export type SortableListProps = {
|
|
|
63
31
|
}) => void;
|
|
64
32
|
};
|
|
65
33
|
|
|
66
|
-
export const SortableList = (
|
|
67
|
-
scrollViewStyle,
|
|
68
|
-
contentContainerStyle,
|
|
69
|
-
itemStyle,
|
|
70
|
-
headerStyle,
|
|
71
|
-
keyExtractor = (item, index) =>
|
|
72
|
-
`sortable-item-${item?.id ?? item?.title ?? index}`,
|
|
73
|
-
renderItem,
|
|
74
|
-
sortableData = DEFAULT_SORTABLE_DATA,
|
|
75
|
-
headers = DEFAULT_HEADERS,
|
|
76
|
-
}: SortableListProps) => {
|
|
77
|
-
return (
|
|
78
|
-
<ScrollView
|
|
79
|
-
style={scrollViewStyle}
|
|
80
|
-
contentContainerStyle={contentContainerStyle}
|
|
81
|
-
>
|
|
82
|
-
{(headers || []).map((header, idx) => (
|
|
83
|
-
<View key={`static-header-${idx}`} style={headerStyle}>
|
|
84
|
-
{header.title ? (
|
|
85
|
-
<SortableListHeader title={header.title} />
|
|
86
|
-
) : (
|
|
87
|
-
renderHeaderComponent(header.component)
|
|
88
|
-
)}
|
|
89
|
-
</View>
|
|
90
|
-
))}
|
|
91
|
-
{(sortableData || []).map((item, index) => (
|
|
92
|
-
<View key={keyExtractor(item, index)} style={itemStyle}>
|
|
93
|
-
{renderItem({
|
|
94
|
-
item,
|
|
95
|
-
index,
|
|
96
|
-
renderHandle: (children) => children,
|
|
97
|
-
})}
|
|
98
|
-
</View>
|
|
99
|
-
))}
|
|
100
|
-
</ScrollView>
|
|
101
|
-
);
|
|
102
|
-
};
|
|
34
|
+
export const SortableList = (_props: SortableListProps) => null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
|
+
import { SortableList } from "../SortableList.web";
|
|
4
|
+
|
|
5
|
+
describe("SortableList.web", () => {
|
|
6
|
+
it("renders nothing", () => {
|
|
7
|
+
const { toJSON } = render(
|
|
8
|
+
<SortableList
|
|
9
|
+
renderItem={() => null}
|
|
10
|
+
sortableData={[{ id: "1", title: "Track 1" }]}
|
|
11
|
+
/>
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
expect(toJSON()).toBeNull();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -42,9 +42,25 @@ export class ScreenRevealManager {
|
|
|
42
42
|
private subject$ = new Subject<void>();
|
|
43
43
|
private subscription: Subscription;
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
/**
|
|
46
|
+
* @param initialNumberToLoad how many components to wait for before revealing
|
|
47
|
+
* the screen. Staggering exists so a screen full of network-backed components
|
|
48
|
+
* does not load them all at once. A caller that has nothing to stagger - see
|
|
49
|
+
* `disableIncrementalLoading` on the HOC - passes the full count here so the
|
|
50
|
+
* reveal waits for exactly what gets rendered. Omitted, the count is derived
|
|
51
|
+
* from the components themselves.
|
|
52
|
+
*/
|
|
53
|
+
constructor(
|
|
54
|
+
componentsToRender: ZappUIComponent[],
|
|
55
|
+
callback: Callback,
|
|
56
|
+
initialNumberToLoad?: number
|
|
57
|
+
) {
|
|
46
58
|
this.numberOfComponentsWaitToLoadBeforePresent =
|
|
47
|
-
|
|
59
|
+
initialNumberToLoad == null
|
|
60
|
+
? getNumberOfComponentsWaitToLoadBeforePresent(componentsToRender)
|
|
61
|
+
: // Clamped like the computed path: waiting for components that do not
|
|
62
|
+
// exist would hold the screen behind its overlay until the timeout.
|
|
63
|
+
Math.min(initialNumberToLoad, componentsToRender.length);
|
|
48
64
|
|
|
49
65
|
this.renderingState = makeListOf<ComponentLoadingState>(
|
|
50
66
|
COMPONENT_LOADING_STATE.UNKNOWN,
|
|
@@ -22,6 +22,42 @@ import { makeListOf } from "@applicaster/zapp-react-native-utils/arrayUtils";
|
|
|
22
22
|
import { isFirstComponentGallery } from "@applicaster/zapp-react-native-utils/componentsUtils";
|
|
23
23
|
import { withTimeout$ } from "@applicaster/zapp-react-native-utils/idleUtils";
|
|
24
24
|
|
|
25
|
+
describe("ScreenRevealManager explicit component count", () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
(isFirstComponentGallery as jest.Mock).mockReturnValue(false);
|
|
28
|
+
|
|
29
|
+
(makeListOf as jest.Mock).mockImplementation((value, length) =>
|
|
30
|
+
Array(length).fill(value)
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
(withTimeout$ as jest.Mock).mockReturnValue(new Subject());
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("waits for the number of components it is given, not the computed default", () => {
|
|
37
|
+
const components = Array(6).fill({}) as any;
|
|
38
|
+
|
|
39
|
+
const manager = new ScreenRevealManager(components, jest.fn(), 6);
|
|
40
|
+
|
|
41
|
+
expect(manager.numberOfComponentsWaitToLoadBeforePresent).toBe(6);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("never waits for more components than it was handed", () => {
|
|
45
|
+
const components = Array(3).fill({}) as any;
|
|
46
|
+
|
|
47
|
+
const manager = new ScreenRevealManager(components, jest.fn(), 10);
|
|
48
|
+
|
|
49
|
+
expect(manager.numberOfComponentsWaitToLoadBeforePresent).toBe(3);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("falls back to the computed default when given no explicit count", () => {
|
|
53
|
+
const components = Array(6).fill({}) as any;
|
|
54
|
+
|
|
55
|
+
const manager = new ScreenRevealManager(components, jest.fn());
|
|
56
|
+
|
|
57
|
+
expect(manager.numberOfComponentsWaitToLoadBeforePresent).toBe(3);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
25
61
|
describe("ScreenRevealManager", () => {
|
|
26
62
|
let mockCallback: jest.Mock;
|
|
27
63
|
let timeout$: Subject<void>;
|
|
@@ -9,6 +9,12 @@ import {
|
|
|
9
9
|
TIMEOUT,
|
|
10
10
|
} from "../withScreenRevealManager";
|
|
11
11
|
|
|
12
|
+
jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
|
|
13
|
+
useTheme: () => ({ app_background_color: "#000000" }),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
jest.mock("../Overlay", () => ({ Overlay: () => null }));
|
|
17
|
+
|
|
12
18
|
// jest.mock("react-native/Libraries/Animated/NativeAnimatedHelper");
|
|
13
19
|
|
|
14
20
|
const MockComponent = ({
|
|
@@ -37,6 +43,56 @@ const MockComponent = ({
|
|
|
37
43
|
|
|
38
44
|
const WrappedComponent = withScreenRevealManager(MockComponent);
|
|
39
45
|
|
|
46
|
+
describe("withScreenRevealManager disableIncrementalLoading", () => {
|
|
47
|
+
const components = (count: number) =>
|
|
48
|
+
Array(count).fill({ component_type: "grid-qb" });
|
|
49
|
+
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
jest.clearAllMocks();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("asks for every component at once when incremental loading is disabled", () => {
|
|
55
|
+
render(
|
|
56
|
+
<WrappedComponent
|
|
57
|
+
componentsToRender={components(6)}
|
|
58
|
+
disableIncrementalLoading
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
expect(screen.getByTestId("mock-component").props.initialNumberToLoad).toBe(
|
|
63
|
+
6
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("still tracks the component count after it changes", () => {
|
|
68
|
+
const { rerender } = render(
|
|
69
|
+
<WrappedComponent
|
|
70
|
+
componentsToRender={components(6)}
|
|
71
|
+
disableIncrementalLoading
|
|
72
|
+
/>
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
rerender(
|
|
76
|
+
<WrappedComponent
|
|
77
|
+
componentsToRender={components(9)}
|
|
78
|
+
disableIncrementalLoading
|
|
79
|
+
/>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
expect(screen.getByTestId("mock-component").props.initialNumberToLoad).toBe(
|
|
83
|
+
9
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("loads incrementally when the flag is not set", () => {
|
|
88
|
+
render(<WrappedComponent componentsToRender={components(6)} />);
|
|
89
|
+
|
|
90
|
+
expect(screen.getByTestId("mock-component").props.initialNumberToLoad).toBe(
|
|
91
|
+
3
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
40
96
|
describe.skip("withScreenRevealManager", () => {
|
|
41
97
|
beforeEach(() => {
|
|
42
98
|
jest.clearAllMocks();
|
|
@@ -21,11 +21,23 @@ export const SHOWN = 1; // opacity = 1
|
|
|
21
21
|
type Props = {
|
|
22
22
|
componentsToRender: ZappUIComponent[];
|
|
23
23
|
backgroundColor?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Renders every component at once instead of revealing them a few at a time.
|
|
26
|
+
*
|
|
27
|
+
* For a screen that builds its own components and holds all of them already -
|
|
28
|
+
* a form, say - staggering buys nothing and costs: each rebuild of the list
|
|
29
|
+
* tears it back down to the first few and lets the rest crawl in again.
|
|
30
|
+
*
|
|
31
|
+
* This is a flag rather than a count on purpose. A count would have to be
|
|
32
|
+
* re-read whenever the number of components changes, while "do not stagger"
|
|
33
|
+
* stays true whatever the screen ends up holding.
|
|
34
|
+
*/
|
|
35
|
+
disableIncrementalLoading?: boolean;
|
|
24
36
|
};
|
|
25
37
|
|
|
26
38
|
export const withScreenRevealManager = (Component) => {
|
|
27
39
|
return function WithScreenRevealManager(props: Props) {
|
|
28
|
-
const { componentsToRender } = props;
|
|
40
|
+
const { componentsToRender, disableIncrementalLoading } = props;
|
|
29
41
|
|
|
30
42
|
const [isContentReadyToBeShown, setIsContentReadyToBeShown] =
|
|
31
43
|
React.useState(false);
|
|
@@ -42,7 +54,8 @@ export const withScreenRevealManager = (Component) => {
|
|
|
42
54
|
() =>
|
|
43
55
|
new ScreenRevealManager(
|
|
44
56
|
componentsToRender,
|
|
45
|
-
handleSetIsContentReadyToBeShown
|
|
57
|
+
handleSetIsContentReadyToBeShown,
|
|
58
|
+
disableIncrementalLoading ? componentsToRender.length : undefined
|
|
46
59
|
)
|
|
47
60
|
);
|
|
48
61
|
|
|
@@ -80,7 +93,11 @@ export const withScreenRevealManager = (Component) => {
|
|
|
80
93
|
<Component
|
|
81
94
|
{...props}
|
|
82
95
|
initialNumberToLoad={
|
|
83
|
-
|
|
96
|
+
// Recomputed on every render, so the count follows the components
|
|
97
|
+
// even though the manager settled its own expectation at mount.
|
|
98
|
+
disableIncrementalLoading
|
|
99
|
+
? componentsToRender.length
|
|
100
|
+
: managerRef.current.numberOfComponentsWaitToLoadBeforePresent
|
|
84
101
|
}
|
|
85
102
|
onLoadFinishedFromScreenRevealManager={
|
|
86
103
|
managerRef.current.onLoadFinished
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-ui-components",
|
|
3
|
-
"version": "16.0.0-rc.
|
|
3
|
+
"version": "16.0.0-rc.78",
|
|
4
4
|
"description": "Applicaster Zapp React Native ui components for the Quick Brick App",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "16.0.0-rc.
|
|
32
|
-
"@applicaster/zapp-react-native-bridge": "16.0.0-rc.
|
|
33
|
-
"@applicaster/zapp-react-native-redux": "16.0.0-rc.
|
|
34
|
-
"@applicaster/zapp-react-native-utils": "16.0.0-rc.
|
|
31
|
+
"@applicaster/applicaster-types": "16.0.0-rc.78",
|
|
32
|
+
"@applicaster/zapp-react-native-bridge": "16.0.0-rc.78",
|
|
33
|
+
"@applicaster/zapp-react-native-redux": "16.0.0-rc.78",
|
|
34
|
+
"@applicaster/zapp-react-native-utils": "16.0.0-rc.78",
|
|
35
35
|
"fast-json-stable-stringify": "^2.1.0",
|
|
36
36
|
"promise": "^8.3.0",
|
|
37
37
|
"react-native-sortables": "1.7.1",
|