@applicaster/zapp-react-native-ui-components 16.0.0-rc.47 → 16.0.0-rc.49

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.
@@ -1,205 +1,500 @@
1
- import { withDimensions } from "..";
1
+ import { mergeQueryParams, withDimensions } from "..";
2
+
3
+ const mockWarning = jest.fn();
4
+
5
+ jest.mock("@applicaster/zapp-react-native-utils/logger", () => {
6
+ const mockLogger = {
7
+ addSubsystem: jest.fn(() => mockLogger),
8
+ warning: (...args) => mockWarning(...args),
9
+ };
10
+
11
+ return { coreLogger: mockLogger };
12
+ });
2
13
 
3
14
  describe("withDimensions", () => {
4
15
  const width = 300;
5
16
  const height = 200;
17
+ const defaultTemplate = "width={{width}}&height={{height}}";
6
18
 
7
- it("only width in the beginning", () => {
8
- const url = "https://some_url?width=511&quality=95&sharpen=true";
19
+ beforeEach(() => {
20
+ mockWarning.mockClear();
21
+ });
9
22
 
10
- const result = withDimensions(url, width, height);
23
+ describe("with default template (width={{width}}&height={{height}})", () => {
24
+ it("injects width and height into a URL without existing dimension params", () => {
25
+ const url = "https://some_url?quality=95&sharpen=true";
11
26
 
12
- expect(result).toEqual(
13
- `https://some_url?width=${width}&quality=95&sharpen=true`
14
- );
15
- });
27
+ const result = withDimensions(url, width, height, defaultTemplate);
16
28
 
17
- it("only width in the middle", () => {
18
- const url = "https://some_url?quality=95&width=511&sharpen=true";
29
+ expect(result).toContain("width=300");
30
+ expect(result).toContain("height=200");
31
+ expect(result).toContain("quality=95");
32
+ expect(result).toContain("sharpen=true");
33
+ });
19
34
 
20
- const result = withDimensions(url, width, height);
35
+ it("replaces existing width and height params regardless of original size", () => {
36
+ const url =
37
+ "https://some_url?width=511&quality=95&height=400&sharpen=true";
21
38
 
22
- expect(result).toEqual(
23
- `https://some_url?quality=95&width=${width}&sharpen=true`
24
- );
25
- });
39
+ const result = withDimensions(url, width, height, defaultTemplate);
26
40
 
27
- it("only height in the beginning", () => {
28
- const url = "https://some_url?height=511&quality=95&sharpen=true";
41
+ expect(result).toContain("width=300");
42
+ expect(result).toContain("height=200");
43
+ expect(result).toContain("quality=95");
44
+ });
29
45
 
30
- const result = withDimensions(url, width, height);
46
+ it("replaces width even when new width is larger than original", () => {
47
+ const largeWidth = 1024;
48
+ const url = "https://some_url?width=511&quality=95&sharpen=true";
31
49
 
32
- expect(result).toEqual(
33
- `https://some_url?height=${height}&quality=95&sharpen=true`
34
- );
35
- });
50
+ const result = withDimensions(url, largeWidth, height, defaultTemplate);
36
51
 
37
- it("only height in the middle", () => {
38
- const url = "https://some_url?quality=95&height=511&sharpen=true";
52
+ expect(result).toContain("width=1024");
53
+ });
39
54
 
40
- const result = withDimensions(url, width, height);
55
+ it("replaces height even when new height is larger than original", () => {
56
+ const largeHeight = 1024;
57
+ const url = "https://some_url?height=511&quality=95&sharpen=true";
41
58
 
42
- expect(result).toEqual(
43
- `https://some_url?quality=95&height=${height}&sharpen=true`
44
- );
45
- });
59
+ const result = withDimensions(url, width, largeHeight, defaultTemplate);
46
60
 
47
- it("width and height", () => {
48
- const url = "https://some_url?width=511&quality=95&height=400&sharpen=true";
61
+ expect(result).toContain("height=1024");
62
+ });
49
63
 
50
- const result = withDimensions(url, width, height);
64
+ it("adds width and height to URL with no query params", () => {
65
+ const url = "https://some_url";
51
66
 
52
- expect(result).toEqual(
53
- `https://some_url?width=${width}&quality=95&height=${height}&sharpen=true`
54
- );
55
- });
67
+ const result = withDimensions(url, width, height, defaultTemplate);
56
68
 
57
- it("no width and no height", () => {
58
- const url = "https://some_url?quality=95&sharpen=true";
69
+ expect(result).toContain("width=300");
70
+ expect(result).toContain("height=200");
71
+ });
59
72
 
60
- const result = withDimensions(url, width, height);
73
+ it("truncates decimal width values", () => {
74
+ const decimalWidth = 243.42857142857142;
75
+ const url = "https://some_url?quality=95";
61
76
 
62
- expect(result).toEqual("https://some_url?quality=95&sharpen=true");
63
- });
77
+ const result = withDimensions(url, decimalWidth, height, defaultTemplate);
64
78
 
65
- it("undefined width", () => {
66
- const url = "https://some_url?width=511&quality=95&sharpen=true";
79
+ expect(result).toContain("width=243");
80
+ });
67
81
 
68
- const result = withDimensions(url, undefined, height);
82
+ it("replaces URL with width=0 in the original", () => {
83
+ const url = "https://some_url?width=0&quality=95&sharpen=true";
69
84
 
70
- expect(result).toEqual(
71
- "https://some_url?width=511&quality=95&sharpen=true"
72
- );
73
- });
85
+ const result = withDimensions(url, width, height, defaultTemplate);
74
86
 
75
- it("undefined height", () => {
76
- const url = "https://some_url?height=511&quality=95&sharpen=true";
87
+ expect(result).toContain("width=300");
88
+ });
77
89
 
78
- const result = withDimensions(url, width, undefined);
90
+ it("replaces URL with empty width in the original", () => {
91
+ const url = "https://some_url?width=&quality=95&sharpen=true";
79
92
 
80
- expect(result).toEqual(
81
- "https://some_url?height=511&quality=95&sharpen=true"
82
- );
93
+ const result = withDimensions(url, width, height, defaultTemplate);
94
+
95
+ expect(result).toContain("width=300");
96
+ });
83
97
  });
84
98
 
85
- it("only Width", () => {
86
- const url = "https://some_url?Width=511&quality=95&sharpen=true";
99
+ describe("with custom template", () => {
100
+ it("uses custom short param names (w, h)", () => {
101
+ const template = "w={{width}}&h={{height}}";
102
+ const url = "https://cdn.example.com/image.jpg?quality=95";
87
103
 
88
- const result = withDimensions(url, width, height);
104
+ const result = withDimensions(url, width, height, template);
89
105
 
90
- expect(result).toEqual(
91
- `https://some_url?Width=${width}&quality=95&sharpen=true`
92
- );
93
- });
106
+ expect(result).toContain("w=300");
107
+ expect(result).toContain("h=200");
108
+ expect(result).toContain("quality=95");
109
+ });
94
110
 
95
- it("only heighT", () => {
96
- const url = "https://some_url?heighT=511&quality=95&sharpen=true";
111
+ it("uses template with combined size param (size=WxH)", () => {
112
+ const template = "size={{width}}x{{height}}";
113
+ const url = "https://cdn.example.com/image.jpg?quality=95";
97
114
 
98
- const result = withDimensions(url, width, height);
115
+ const result = withDimensions(url, width, height, template);
99
116
 
100
- expect(result).toEqual(
101
- `https://some_url?heighT=${height}&quality=95&sharpen=true`
102
- );
103
- });
117
+ expect(result).toContain(`size=${width}x${height}`);
118
+ expect(result).toContain("quality=95");
119
+ });
104
120
 
105
- it("no params", () => {
106
- const url = "https://some_url";
121
+ it("replaces existing custom param with same key", () => {
122
+ const template = "w={{width}}&h={{height}}";
123
+ const url = "https://cdn.example.com/image.jpg?w=999&h=888&quality=95";
107
124
 
108
- const result = withDimensions(url, width, height);
125
+ const result = withDimensions(url, width, height, template);
109
126
 
110
- expect(result).toEqual(url);
111
- });
127
+ expect(result).toContain("w=300");
128
+ expect(result).toContain("h=200");
129
+ expect(result).not.toContain("w=999");
130
+ expect(result).not.toContain("h=888");
131
+ });
112
132
 
113
- it("round input width", () => {
114
- const width = 243.42857142857142;
115
- const url = "https://some_url?width=511&quality=95&sharpen=true";
133
+ it("handles template with only width", () => {
134
+ const template = "w={{width}}";
135
+ const url = "https://cdn.example.com/image.jpg";
116
136
 
117
- const result = withDimensions(url, width, height);
137
+ const result = withDimensions(url, width, height, template);
118
138
 
119
- expect(result).toEqual(
120
- "https://some_url?width=243&quality=95&sharpen=true"
121
- );
122
- });
139
+ expect(result).toContain("w=300");
140
+ expect(result).not.toContain("height");
141
+ });
123
142
 
124
- it("takes original width when provided width more than original", () => {
125
- const width = 1024;
126
- const url = "https://some_url?width=511&quality=95&sharpen=true";
143
+ it("handles template with only height", () => {
144
+ const template = "h={{height}}";
145
+ const url = "https://cdn.example.com/image.jpg";
127
146
 
128
- const result = withDimensions(url, width, height);
147
+ const result = withDimensions(url, width, height, template);
129
148
 
130
- expect(result).toEqual(url);
131
- });
149
+ expect(result).toContain("h=200");
150
+ expect(result).not.toContain("width");
151
+ });
132
152
 
133
- it("takes original height when provided height more than original", () => {
134
- const height = 1024;
135
- const url = "https://some_url?height=511&quality=95&sharpen=true";
153
+ it("handles case-insensitive placeholders", () => {
154
+ const template = "w={{Width}}&h={{HEIGHT}}";
155
+ const url = "https://cdn.example.com/image.jpg";
136
156
 
137
- const result = withDimensions(url, width, height);
157
+ const result = withDimensions(url, width, height, template);
138
158
 
139
- expect(result).toEqual(url);
159
+ expect(result).toContain("w=300");
160
+ expect(result).toContain("h=200");
161
+ });
140
162
  });
141
163
 
142
- it("doesnt touch url if no width value is provided", () => {
143
- const url = "https://some_url?width=&quality=95&sharpen=true";
164
+ describe("no template provided", () => {
165
+ it("returns original url when template is undefined", () => {
166
+ const url = "https://some_url?width=511&quality=95&sharpen=true";
144
167
 
145
- const result = withDimensions(url, width, height);
168
+ const result = withDimensions(url, width, height, undefined);
146
169
 
147
- expect(result).toEqual(url);
148
- });
170
+ expect(result).toEqual(url);
171
+ });
172
+
173
+ it("returns original url when template is empty string", () => {
174
+ const url = "https://some_url?width=511&quality=95&sharpen=true";
175
+
176
+ const result = withDimensions(url, width, height, "");
177
+
178
+ expect(result).toEqual(url);
179
+ });
149
180
 
150
- it("doesnt touch url if width=0", () => {
151
- const url = "https://some_url?width=0&quality=95&sharpen=true";
181
+ it("returns original url when template is null", () => {
182
+ const url = "https://some_url?width=511&quality=95&sharpen=true";
152
183
 
153
- const result = withDimensions(url, width, height);
184
+ const result = withDimensions(url, width, height, null);
154
185
 
155
- expect(result).toEqual(url);
186
+ expect(result).toEqual(url);
187
+ });
156
188
  });
157
189
 
158
- it("doesnt touch url if no height value is provided", () => {
159
- const url = "https://some_url?height=&quality=95&sharpen=true";
190
+ describe("invalid / malformed template mappings", () => {
191
+ it("ignores params with unrecognized placeholders like {{heit}}", () => {
192
+ const template = "width={{width}}&height={{heit}}";
193
+ const url = "https://some_url?quality=95";
194
+
195
+ const result = withDimensions(url, width, height, template);
196
+
197
+ expect(result).toContain("width=300");
198
+ expect(result).not.toContain("heit");
199
+ expect(result).not.toContain("height");
200
+ expect(result).toContain("quality=95");
201
+ });
202
+
203
+ it("ignores params with typo placeholder and keeps valid ones", () => {
204
+ const template = "w={{wdth}}&h={{height}}";
205
+ const url = "https://cdn.example.com/image.jpg?quality=95";
206
+
207
+ const result = withDimensions(url, width, height, template);
208
+
209
+ expect(result).toContain("h=200");
210
+ expect(result).not.toContain("wdth");
211
+ expect(result).not.toContain("w=");
212
+ expect(result).toContain("quality=95");
213
+ });
214
+
215
+ it("returns original url when all template params are invalid", () => {
216
+ const template = "w={{wdth}}&h={{hght}}";
217
+ const url = "https://cdn.example.com/image.jpg?quality=95";
218
+
219
+ const result = withDimensions(url, width, height, template);
220
+
221
+ expect(result).toEqual(url);
222
+ });
223
+
224
+ it("ignores completely broken placeholder syntax", () => {
225
+ const template = "width={{width}}&height{{heit}}";
226
+ const url = "https://some_url?quality=95";
227
+
228
+ const result = withDimensions(url, width, height, template);
229
+
230
+ expect(result).toContain("width=300");
231
+ expect(result).not.toContain("heit");
232
+ expect(result).toContain("quality=95");
233
+ });
234
+
235
+ it("ignores param with empty placeholder {{}}", () => {
236
+ const template = "width={{width}}&height={{}}";
237
+ const url = "https://some_url?quality=95";
238
+
239
+ const result = withDimensions(url, width, height, template);
240
+
241
+ expect(result).toContain("width=300");
242
+ expect(result).not.toContain("{{}}");
243
+ });
244
+
245
+ it("ignores malformed placeholder with single closing brace {{heit}", () => {
246
+ const template = "width={{width}}&height={{heit}";
247
+ const url = "https://some_url?quality=95";
248
+
249
+ const result = withDimensions(url, width, height, template);
250
+
251
+ expect(result).toContain("width=300");
252
+ expect(result).not.toContain("heit");
253
+ expect(result).toContain("quality=95");
254
+ });
255
+
256
+ it("ignores malformed placeholder missing closing braces entirely", () => {
257
+ const template = "width={{width}}&height={{height";
258
+ const url = "https://some_url?quality=95";
259
+
260
+ const result = withDimensions(url, width, height, template);
261
+
262
+ expect(result).toContain("width=300");
263
+ expect(result).not.toContain("{{height");
264
+ expect(result).toContain("quality=95");
265
+ });
266
+
267
+ it("logs a warning for each invalid placeholder", () => {
268
+ const template = "width={{width}}&height={{heit}}";
269
+ const url = "https://some_url?quality=95";
270
+
271
+ withDimensions(url, width, height, template);
272
+
273
+ expect(mockWarning).toHaveBeenCalledTimes(1);
160
274
 
161
- const result = withDimensions(url, width, height);
275
+ expect(mockWarning).toHaveBeenCalledWith(
276
+ expect.objectContaining({
277
+ message: expect.stringContaining("{{heit}}"),
278
+ data: expect.objectContaining({
279
+ invalidNames: ["heit"],
280
+ }),
281
+ })
282
+ );
283
+ });
162
284
 
163
- expect(result).toEqual(url);
285
+ it("logs a warning for each dropped param pair independently", () => {
286
+ const template = "w={{wdth}}&h={{hght}}";
287
+ const url = "https://cdn.example.com/image.jpg?quality=95";
288
+
289
+ withDimensions(url, width, height, template);
290
+
291
+ expect(mockWarning).toHaveBeenCalledTimes(2);
292
+ });
293
+
294
+ it("does not log when all placeholders are valid", () => {
295
+ const url = "https://some_url?quality=95";
296
+
297
+ withDimensions(url, width, height, defaultTemplate);
298
+
299
+ expect(mockWarning).not.toHaveBeenCalled();
300
+ });
164
301
  });
165
302
 
166
- it("doesnt touch url if height=0", () => {
167
- const url = "https://some_url?height=0&quality=95&sharpen=true";
303
+ describe("leading question mark in template", () => {
304
+ it("strips leading ? from template", () => {
305
+ const template = "?width={{width}}&height={{height}}";
306
+ const url = "https://some_url?quality=95";
307
+
308
+ const result = withDimensions(url, width, height, template);
309
+
310
+ expect(result).toContain("width=300");
311
+ expect(result).toContain("height=200");
312
+ expect(result).toContain("quality=95");
313
+ });
314
+
315
+ it("strips leading ? with whitespace from template", () => {
316
+ const template = " ?width={{width}}&height={{height}}";
317
+ const url = "https://some_url?quality=95";
318
+
319
+ const result = withDimensions(url, width, height, template);
320
+
321
+ expect(result).toContain("width=300");
322
+ expect(result).toContain("height=200");
323
+ });
324
+
325
+ it("strips leading ? on URL without existing query params", () => {
326
+ const template = "?w={{width}}&h={{height}}";
327
+ const url = "https://cdn.example.com/image.jpg";
328
+
329
+ const result = withDimensions(url, width, height, template);
330
+
331
+ expect(result).toContain("w=300");
332
+ expect(result).toContain("h=200");
333
+ });
334
+
335
+ it("handles template that is just ?", () => {
336
+ const template = "?";
337
+ const url = "https://some_url?quality=95";
168
338
 
169
- const result = withDimensions(url, width, height);
339
+ const result = withDimensions(url, width, height, template);
170
340
 
171
- expect(result).toEqual(url);
341
+ expect(result).toEqual(url);
342
+ });
172
343
  });
173
344
 
174
- it("returns original url ir url is undefined", () => {
175
- const url = undefined;
345
+ describe("URLs without query params", () => {
346
+ it("adds params to a clean URL with no query string", () => {
347
+ const url = "https://cdn.example.com/image.jpg";
176
348
 
177
- const result = withDimensions(url, width, height);
349
+ const result = withDimensions(url, width, height, defaultTemplate);
178
350
 
179
- expect(result).toEqual(url);
351
+ expect(result).toContain("width=300");
352
+ expect(result).toContain("height=200");
353
+ });
354
+
355
+ it("adds custom params to a clean URL with no query string", () => {
356
+ const template = "w={{width}}&h={{height}}";
357
+ const url = "https://cdn.example.com/path/to/image.jpg";
358
+
359
+ const result = withDimensions(url, width, height, template);
360
+
361
+ expect(result).toContain("w=300");
362
+ expect(result).toContain("h=200");
363
+ });
364
+
365
+ it("adds combined size param to URL with no query string", () => {
366
+ const template = "size={{width}}x{{height}}";
367
+ const url = "https://cdn.example.com/image.jpg";
368
+
369
+ const result = withDimensions(url, width, height, template);
370
+
371
+ expect(result).toContain("size=300x200");
372
+ });
373
+
374
+ it("adds only valid params to clean URL when template has invalid mappings", () => {
375
+ const template = "width={{width}}&height={{heit}}";
376
+ const url = "https://cdn.example.com/image.jpg";
377
+
378
+ const result = withDimensions(url, width, height, template);
379
+
380
+ expect(result).toContain("width=300");
381
+ expect(result).not.toContain("heit");
382
+ });
180
383
  });
181
384
 
182
- it("returns original url ir url is empty string", () => {
183
- const url = "";
385
+ describe("edge cases", () => {
386
+ it("returns original url when url is undefined", () => {
387
+ const result = withDimensions(undefined, width, height, defaultTemplate);
388
+
389
+ expect(result).toEqual(undefined);
390
+ });
391
+
392
+ it("returns original url when url is empty string", () => {
393
+ const result = withDimensions("", width, height, defaultTemplate);
394
+
395
+ expect(result).toEqual("");
396
+ });
397
+
398
+ it("returns original url when url is invalid (non-http)", () => {
399
+ const url = "invalid_url";
184
400
 
185
- const result = withDimensions(url, width, height);
401
+ const result = withDimensions(url, width, height, defaultTemplate);
186
402
 
187
- expect(result).toEqual(url);
403
+ expect(result).toEqual(url);
404
+ });
405
+
406
+ it("returns original url when url is a number passed as string", () => {
407
+ const url = 1 as unknown as string;
408
+
409
+ const result = withDimensions(url, width, height, defaultTemplate);
410
+
411
+ expect(result).toEqual(url);
412
+ });
413
+
414
+ it("returns original url when width is undefined and height is undefined", () => {
415
+ const url = "https://some_url?quality=95";
416
+
417
+ const result = withDimensions(url, undefined, undefined, defaultTemplate);
418
+
419
+ expect(result).toEqual(url);
420
+ });
421
+
422
+ it("returns original url when width is 0 and height is 0", () => {
423
+ const url = "https://some_url?quality=95";
424
+
425
+ const result = withDimensions(url, 0, 0, defaultTemplate);
426
+
427
+ expect(result).toEqual(url);
428
+ });
429
+
430
+ it("still works when only width is provided and does not inject height=0", () => {
431
+ const url = "https://some_url?quality=95";
432
+
433
+ const result = withDimensions(url, width, undefined, defaultTemplate);
434
+
435
+ expect(result).toContain("width=300");
436
+ expect(result).not.toContain("height=0");
437
+ expect(result).not.toContain("height=");
438
+ });
439
+
440
+ it("still works when only height is provided and does not inject width=0", () => {
441
+ const url = "https://some_url?quality=95";
442
+
443
+ const result = withDimensions(url, undefined, height, defaultTemplate);
444
+
445
+ expect(result).toContain("height=200");
446
+ expect(result).not.toContain("width=0");
447
+ expect(result).not.toContain("width=");
448
+ });
449
+
450
+ it("preserves URL hash fragment", () => {
451
+ const url = "https://some_url?quality=95#section1";
452
+
453
+ const result = withDimensions(url, width, height, defaultTemplate);
454
+
455
+ expect(result).toContain("width=300");
456
+ expect(result).toContain("height=200");
457
+ });
188
458
  });
459
+ });
189
460
 
190
- it("returns original url ir url is invalid", () => {
191
- const url = "invalid_url";
461
+ describe("mergeQueryParams", () => {
462
+ it("adds new params to URL without existing params", () => {
463
+ const result = mergeQueryParams(
464
+ "https://example.com/img.jpg",
465
+ "w=300&h=200"
466
+ );
192
467
 
193
- const result = withDimensions(url, width, height);
468
+ expect(result).toContain("w=300");
469
+ expect(result).toContain("h=200");
470
+ });
194
471
 
195
- expect(result).toEqual(url);
472
+ it("overwrites existing params with same key", () => {
473
+ const result = mergeQueryParams(
474
+ "https://example.com/img.jpg?w=999&quality=95",
475
+ "w=300"
476
+ );
477
+
478
+ expect(result).toContain("w=300");
479
+ expect(result).not.toContain("w=999");
480
+ expect(result).toContain("quality=95");
196
481
  });
197
482
 
198
- it("returns original url ir url is invalid", () => {
199
- const url = 1 as unknown as string;
483
+ it("returns original URL if parsing fails", () => {
484
+ const badUrl = "not a url at all";
485
+
486
+ const result = mergeQueryParams(badUrl, "w=300");
200
487
 
201
- const result = withDimensions(url, width, height);
488
+ expect(result).toEqual(badUrl);
489
+ });
490
+
491
+ it("handles combined values (e.g. size=300x200)", () => {
492
+ const result = mergeQueryParams(
493
+ "https://example.com/img.jpg?quality=95",
494
+ "size=300x200"
495
+ );
202
496
 
203
- expect(result).toEqual(url);
497
+ expect(result).toContain("size=300x200");
498
+ expect(result).toContain("quality=95");
204
499
  });
205
500
  });
@@ -1,15 +1,85 @@
1
- import {
2
- toFiniteNumberWithDefault,
3
- toNumber,
4
- } from "@applicaster/zapp-react-native-utils/numberUtils";
1
+ import { toFiniteNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
5
2
  import { isNil } from "ramda";
3
+ import { coreLogger } from "@applicaster/zapp-react-native-utils/logger";
6
4
 
7
- const dimensionRegex = /\b(width|height)=(\d+)\b/gi;
5
+ const imageResizingLogger = coreLogger
6
+ ?.addSubsystem("components")
7
+ ?.addSubsystem("ImageResizing");
8
8
 
9
+ const TEMPLATE_REGEX = /{{(width|height)}}/gi;
10
+ const UNRESOLVED_PLACEHOLDER_REGEX = /{{[^}]*}}?/;
11
+ const INVALID_PLACEHOLDER_EXTRACT_REGEX = /{{([^}]*)}}?/g;
12
+ const ALLOWED_PLACEHOLDERS = ["width", "height"];
13
+
14
+ /**
15
+ * Merges query-param string `paramsString` into `baseUrl`.
16
+ * Params from `paramsString` override any existing params with the same key.
17
+ */
18
+ export const mergeQueryParams = (
19
+ baseUrl: string,
20
+ paramsString: string
21
+ ): string => {
22
+ try {
23
+ const urlObj = new URL(baseUrl);
24
+ const newParams = new URLSearchParams(paramsString);
25
+
26
+ newParams.forEach((value, key) => {
27
+ urlObj.searchParams.set(key, value);
28
+ });
29
+
30
+ return urlObj.toString();
31
+ } catch {
32
+ // If URL parsing fails, return original
33
+ return baseUrl;
34
+ }
35
+ };
36
+
37
+ /**
38
+ * Extracts unresolved placeholder names from a param pair and logs a warning.
39
+ */
40
+ const logInvalidPlaceholders = (pair: string): void => {
41
+ const invalidNames: string[] = [];
42
+ let match: RegExpExecArray | null;
43
+
44
+ // Reset lastIndex before using the global regex
45
+ INVALID_PLACEHOLDER_EXTRACT_REGEX.lastIndex = 0;
46
+
47
+ while ((match = INVALID_PLACEHOLDER_EXTRACT_REGEX.exec(pair)) !== null) {
48
+ const name = match[1];
49
+
50
+ if (!ALLOWED_PLACEHOLDERS.includes(name?.toLowerCase())) {
51
+ invalidNames.push(name);
52
+ }
53
+ }
54
+
55
+ if (invalidNames.length > 0) {
56
+ imageResizingLogger?.warning({
57
+ message: `Image resizing: invalid placeholder(s) found: ${invalidNames.map((n) => `{{${n}}}`).join(", ")}. Allowed placeholders are: {{width}}, {{height}}. The param "${pair}" was ignored.`,
58
+ data: { pair, invalidNames, allowedPlaceholders: ALLOWED_PLACEHOLDERS },
59
+ });
60
+ }
61
+ };
62
+
63
+ /**
64
+ * Parses a dimension mapping template string (query param format) and injects
65
+ * the resolved width/height values into the given URL.
66
+ *
67
+ * The template uses `{{width}}` and `{{height}}` placeholders.
68
+ * It is treated as query-param key=value pairs (e.g. "w={{width}}&h={{height}}"
69
+ * or "size={{width}}x{{height}}").
70
+ *
71
+ * Resolved params are **merged** into the original URL – existing params with
72
+ * the same key are replaced; new ones are appended.
73
+ *
74
+ * Invalid mappings (containing unresolved placeholders like `{{heit}}` or
75
+ * malformed `{{heit}`) are silently dropped and logged as warnings.
76
+ * A leading `?` in the template is stripped.
77
+ */
9
78
  export const withDimensions = (
10
79
  url: Option<string>,
11
80
  width: Option<number | string>,
12
- height: Option<number | string>
81
+ height: Option<number | string>,
82
+ dimensionMappingTemplate?: Option<string>
13
83
  ) => {
14
84
  if (isNil(url)) {
15
85
  return url;
@@ -22,23 +92,48 @@ export const withDimensions = (
22
92
  const newWidth = Math.trunc(toFiniteNumberWithDefault(0, width));
23
93
  const newHeight = Math.trunc(toFiniteNumberWithDefault(0, height));
24
94
 
25
- return url.replace(dimensionRegex, (match, name, originalValue) => {
26
- if (name.toLocaleLowerCase() === "width" && newWidth > 0) {
27
- const originalWidth = toNumber(originalValue);
95
+ if (newWidth <= 0 && newHeight <= 0) {
96
+ return url;
97
+ }
98
+
99
+ // Strip leading `?` and whitespace from the template
100
+ const template = dimensionMappingTemplate?.trim()?.replace(/^\?/, "");
28
101
 
29
- if (originalWidth > 0 && originalWidth > newWidth) {
30
- return `${name}=${newWidth}`;
31
- }
32
- }
102
+ if (!template) {
103
+ return url;
104
+ }
33
105
 
34
- if (name.toLocaleLowerCase() === "height" && newHeight > 0) {
35
- const originalHeight = toNumber(originalValue);
106
+ // Replace {{width}} / {{height}} placeholders in the template
107
+ const resolvedTemplate = template.replace(TEMPLATE_REGEX, (_match, name) => {
108
+ if (name.toLowerCase() === "width") {
109
+ return newWidth > 0 ? String(newWidth) : _match;
110
+ }
36
111
 
37
- if (originalHeight > 0 && originalHeight > newHeight) {
38
- return `${name}=${newHeight}`;
39
- }
112
+ if (name.toLowerCase() === "height") {
113
+ return newHeight > 0 ? String(newHeight) : _match;
40
114
  }
41
115
 
42
- return match;
116
+ return _match;
43
117
  });
118
+
119
+ // Filter out param pairs that still contain unresolved / malformed placeholders
120
+ const cleanedParams = resolvedTemplate
121
+ .split("&")
122
+ .filter((pair) => {
123
+ if (UNRESOLVED_PLACEHOLDER_REGEX.test(pair)) {
124
+ logInvalidPlaceholders(pair);
125
+
126
+ return false;
127
+ }
128
+
129
+ return true;
130
+ })
131
+ .join("&");
132
+
133
+ if (!cleanedParams) {
134
+ return url;
135
+ }
136
+
137
+ // Parse the resolved template as query params and merge into URL
138
+ return mergeQueryParams(url, cleanedParams);
44
139
  };
@@ -14,25 +14,36 @@ type Style = {
14
14
  height: Option<number | string>;
15
15
  };
16
16
 
17
- const withAppliedDimensions = (style: Style) => (source: Source) => ({
18
- ...source,
19
- uri: withDimensions(source?.uri, style?.width, style?.height),
20
- });
17
+ const withAppliedDimensions =
18
+ (style: Style, dimensionMappingTemplate: string) => (source: Source) => ({
19
+ ...source,
20
+ uri: withDimensions(
21
+ source?.uri,
22
+ style?.width,
23
+ style?.height,
24
+ dimensionMappingTemplate
25
+ ),
26
+ });
21
27
 
22
28
  export const withDimensionsHOC = (Component) => {
23
29
  return function WithDimensions(props: Record<string, unknown>) {
24
30
  const theme = useTheme<BaseThemePropertiesMobile>();
25
31
 
26
- const useDownScalingImages = toBooleanWithDefaultFalse(
27
- theme.use_downscaling_images
32
+ const useImageResizing = toBooleanWithDefaultFalse(
33
+ theme.use_image_resizing ?? theme.use_downscaling_images
28
34
  );
29
35
 
36
+ const dimensionMappingTemplate = theme.image_resizing_template;
37
+
30
38
  return (
31
39
  <Component
32
40
  {...props}
33
41
  withDimensions={
34
- useDownScalingImages
35
- ? withAppliedDimensions((props?.style || {}) as Style)
42
+ useImageResizing
43
+ ? withAppliedDimensions(
44
+ (props?.style || {}) as Style,
45
+ dimensionMappingTemplate
46
+ )
36
47
  : identity
37
48
  }
38
49
  />
@@ -9,6 +9,7 @@ import {
9
9
  platformSelect,
10
10
  isAndroidTVPlatform,
11
11
  isTvOSPlatform,
12
+ isApplePlatform,
12
13
  } from "@applicaster/zapp-react-native-utils/reactUtils";
13
14
  import {
14
15
  isAudioItem,
@@ -60,6 +61,7 @@ import {
60
61
  PlayerNativeSendCommand,
61
62
  } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/playerNativeCommand";
62
63
  import { useAppData } from "@applicaster/zapp-react-native-redux";
64
+ import { PLAYER_EVENTS } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/conts";
63
65
 
64
66
  type Props = {
65
67
  Player: React.ComponentType<any>;
@@ -282,12 +284,16 @@ const PlayerContainerComponent = (props: Props) => {
282
284
  }
283
285
 
284
286
  log_debug(
285
- `onPlayNextPerformNextVideoPlay: delay completed, replaceTop to item: ${playNextOverlayState.entry.title}, id: ${playNextOverlayState.entry.id}`
287
+ `onPlayNextPerformNextVideoPlay: delay completed, replaceTop to item: ${playNextOverlayState.entry.title}, id: ${playNextOverlayState.entry.id}, outgoing item id: ${item?.id}`
286
288
  );
287
289
 
290
+ playNextOverlayState.hidePlayNext();
291
+
292
+ playerEvent(PLAYER_EVENTS.PlayNextTriggered, { id: item?.id });
293
+
288
294
  setIsLoadingNextVideo(true);
289
295
  playEntry(playNextOverlayState.entry);
290
- }, [playNextOverlayState]);
296
+ }, [playNextOverlayState, item?.id]);
291
297
 
292
298
  const playNextData: Nullable<PlayNextData> = React.useMemo(() => {
293
299
  if (!playNextOverlayState) {
@@ -495,7 +501,7 @@ const PlayerContainerComponent = (props: Props) => {
495
501
  const isAudioContent = isAudioItem(item);
496
502
 
497
503
  useEffect(() => {
498
- if (!isAudioContent) {
504
+ if (!isAudioContent && isApplePlatform()) {
499
505
  sendQuickBrickEvent(
500
506
  QUICK_BRICK_EVENTS.IDLE_TIMER_DISABLED as QuickBrickEvent,
501
507
  {
@@ -20,6 +20,7 @@ jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
20
20
  isTV: jest.fn(() => false),
21
21
  isAndroidTVPlatform: jest.fn(() => false),
22
22
  isTvOSPlatform: jest.fn(() => false),
23
+ isApplePlatform: jest.fn(() => true),
23
24
  platformSelect: jest.fn(({ native }) => native),
24
25
  }));
25
26
 
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.47",
3
+ "version": "16.0.0-rc.49",
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.47",
32
- "@applicaster/zapp-react-native-bridge": "16.0.0-rc.47",
33
- "@applicaster/zapp-react-native-redux": "16.0.0-rc.47",
34
- "@applicaster/zapp-react-native-utils": "16.0.0-rc.47",
31
+ "@applicaster/applicaster-types": "16.0.0-rc.49",
32
+ "@applicaster/zapp-react-native-bridge": "16.0.0-rc.49",
33
+ "@applicaster/zapp-react-native-redux": "16.0.0-rc.49",
34
+ "@applicaster/zapp-react-native-utils": "16.0.0-rc.49",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "url": "^0.11.0",