@applicaster/zapp-react-native-ui-components 16.0.0-alpha.1263110541 → 16.0.0-alpha.1334507601
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/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +15 -0
- package/Components/MasterCell/DefaultComponents/ActionButton.tsx +5 -1
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/ActionButtonController.tsx +19 -4
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/__tests__/ActionButtonController.test.tsx +43 -1
- package/Components/MasterCell/DefaultComponents/Button.tsx +1 -0
- package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/factory.test.ts +32 -0
- package/Components/MasterCell/SharedUI/CollapsibleTextContainer/index.ts +1 -2
- package/Components/ModalComponent/ActionsBottomSheet/ActionButton.tsx +4 -2
- package/Components/ModalComponent/ActionsBottomSheet/__tests__/openActionsBottomSheet.test.ts +38 -0
- package/Components/ModalComponent/ActionsBottomSheet/boundActionButton.tsx +5 -2
- package/Components/ModalComponent/ActionsBottomSheet/openActionsBottomSheet.ts +4 -1
- package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +70 -73
- package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +1 -36
- package/Components/ModalComponent/AudioPlayer/Components/Input.tsx +1 -26
- package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +180 -47
- package/Components/ModalComponent/AudioPlayer/Components/NowPlayingHeaderSection.tsx +13 -20
- package/Components/ModalComponent/AudioPlayer/Components/__tests__/Item.test.tsx +113 -0
- package/Components/ModalComponent/AudioPlayer/Components/index.ts +0 -2
- package/Components/ModalComponent/AudioPlayer/utils/__tests__/mergeStyles.test.ts +248 -0
- package/Components/ModalComponent/AudioPlayer/utils/mergeStyles.ts +194 -19
- package/Components/ModalComponent/BottomSheetModalContent.tsx +94 -66
- package/Components/ModalComponent/Header/CloseButton.tsx +12 -0
- package/Components/ModalComponent/Header/__tests__/CloseButton.test.tsx +72 -0
- package/Components/ModalComponent/SortableList.tsx +38 -23
- package/Components/ModalComponent/SortableList.web.tsx +1 -1
- package/Components/ModalComponent/TextInputContent.tsx +15 -3
- package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +37 -5
- package/Components/ModalComponent/__tests__/TextInputContent.test.tsx +36 -0
- package/Components/ModalComponent/index.tsx +7 -9
- package/Components/ModalComponent/presets/__tests__/getCell.test.ts +24 -0
- package/Components/ModalComponent/presets/dynamicCollectionCell.tsx +1 -1
- package/Components/ModalComponent/presets/selectableCell.tsx +1 -1
- package/Components/ModalComponent/utils.ts +6 -1
- package/Components/OfflineHandler/hooks.ts +0 -12
- package/Components/River/ComponentsMap/ComponentsMap.tsx +85 -59
- package/Components/River/River.tsx +4 -0
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +138 -75
- package/Components/River/__tests__/componentsMap.test.js +8 -3
- package/Components/River/__tests__/resultCallback.test.tsx +47 -0
- package/Components/Screen/__tests__/Screen.test.tsx +24 -0
- package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +2 -0
- package/Components/Screen/index.tsx +5 -0
- package/Components/Screen/navigationHandler.ts +8 -8
- 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 +21 -4
- package/Contexts/ModalNavigationContext/__tests__/index.test.tsx +15 -0
- package/Contexts/ModalNavigationContext/index.tsx +2 -2
- package/package.json +5 -5
- package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +0 -314
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
memo,
|
|
3
|
+
useCallback,
|
|
4
|
+
useDeferredValue,
|
|
5
|
+
useEffect,
|
|
6
|
+
useMemo,
|
|
7
|
+
useRef,
|
|
8
|
+
} from "react";
|
|
2
9
|
import {
|
|
3
10
|
ActivityIndicator,
|
|
4
11
|
ScrollView,
|
|
@@ -26,7 +33,6 @@ import { SortableList } from "./SortableList";
|
|
|
26
33
|
import {
|
|
27
34
|
AudioPlayerButton,
|
|
28
35
|
NowPlayingHeaderSection,
|
|
29
|
-
VARIANT_WITH_ICON,
|
|
30
36
|
} from "./AudioPlayer/Components";
|
|
31
37
|
import { BottomSheetDragArea } from "./BottomSheetDragArea";
|
|
32
38
|
import { ModalBlocksStyleContext } from "./ModalBlocksStyleContext";
|
|
@@ -48,6 +54,10 @@ const styles = StyleSheet.create({
|
|
|
48
54
|
fontSize: 14,
|
|
49
55
|
textAlign: "center",
|
|
50
56
|
},
|
|
57
|
+
scrollView: {
|
|
58
|
+
flexShrink: 1,
|
|
59
|
+
},
|
|
60
|
+
someStyles: { paddingHorizontal: 20, paddingTop: 8, paddingBottom: 12 },
|
|
51
61
|
});
|
|
52
62
|
|
|
53
63
|
type ModalComponentProps = {
|
|
@@ -81,9 +91,10 @@ type ModalComponentProps = {
|
|
|
81
91
|
contentComponent?: React.ComponentType<any>;
|
|
82
92
|
contentComponentProps?: Record<string, any>;
|
|
83
93
|
styleOverrides?: ModalBlocksConfig | Record<string, any>;
|
|
94
|
+
measurementPhase?: boolean;
|
|
84
95
|
};
|
|
85
96
|
|
|
86
|
-
|
|
97
|
+
function _BottomSheetModalContent(props: ModalComponentProps) {
|
|
87
98
|
const {
|
|
88
99
|
items,
|
|
89
100
|
currentRoute,
|
|
@@ -103,13 +114,21 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
|
|
|
103
114
|
contentComponent: ContentComponent,
|
|
104
115
|
contentComponentProps = {},
|
|
105
116
|
styleOverrides: propStyleOverrides,
|
|
117
|
+
measurementPhase = false,
|
|
106
118
|
} = props;
|
|
107
119
|
|
|
108
120
|
const route = useRef(currentRoute);
|
|
109
121
|
const theme = useTheme<BaseThemePropertiesMobile>();
|
|
122
|
+
const bottomInset = useSafeAreaInsets().bottom;
|
|
110
123
|
const paddingTop = Number(theme.modal_bottom_sheet_padding_top);
|
|
111
124
|
const paddingBottom = Number(theme.modal_bottom_sheet_padding_bottom);
|
|
112
125
|
|
|
126
|
+
const calculatedcontentContainerStyle = useMemo(() => {
|
|
127
|
+
return {
|
|
128
|
+
paddingBottom: paddingBottom + bottomInset,
|
|
129
|
+
};
|
|
130
|
+
}, [paddingBottom, bottomInset]);
|
|
131
|
+
|
|
113
132
|
const {
|
|
114
133
|
items: fetchedItems,
|
|
115
134
|
showCentralLoading,
|
|
@@ -156,14 +175,28 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
|
|
|
156
175
|
? pluginLocalizations?.[`${normalizedPluginId}_header_title`]
|
|
157
176
|
: undefined;
|
|
158
177
|
|
|
159
|
-
const
|
|
160
|
-
pluginLocalizations?.
|
|
178
|
+
const nextUpTitle =
|
|
179
|
+
pluginLocalizations?.next_up_title ||
|
|
180
|
+
(normalizedPluginId
|
|
181
|
+
? pluginLocalizations?.[`${normalizedPluginId}_next_up_title`]
|
|
182
|
+
: undefined) ||
|
|
183
|
+
"Next Up";
|
|
184
|
+
|
|
185
|
+
const nowPlayingTitle =
|
|
186
|
+
pluginLocalizations?.now_playing_title ||
|
|
187
|
+
(normalizedPluginId
|
|
188
|
+
? pluginLocalizations?.[`${normalizedPluginId}_now_playing_title`]
|
|
189
|
+
: undefined) ||
|
|
190
|
+
"Now Playing";
|
|
161
191
|
|
|
162
192
|
const resolvedTitle = props.title || localizedHeaderTitle || title;
|
|
163
193
|
|
|
164
194
|
const itemsToRender = viewModel ? fetchedItems : items;
|
|
165
195
|
const operations = editableCollection?.operations || [];
|
|
166
|
-
|
|
196
|
+
|
|
197
|
+
const isSortable = useDeferredValue(
|
|
198
|
+
!measurementPhase && hasOperation(operations, OPERATIONS.REORDER)
|
|
199
|
+
);
|
|
167
200
|
|
|
168
201
|
const cell = getCell(
|
|
169
202
|
viewModel ? role : undefined,
|
|
@@ -264,7 +297,17 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
|
|
|
264
297
|
]
|
|
265
298
|
);
|
|
266
299
|
|
|
267
|
-
const
|
|
300
|
+
const sortableListRenderItem = useCallback(
|
|
301
|
+
({ item, index, renderHandle }) =>
|
|
302
|
+
cell.renderItem({
|
|
303
|
+
item,
|
|
304
|
+
index,
|
|
305
|
+
onPress: onItemPress,
|
|
306
|
+
context: renderContext,
|
|
307
|
+
renderHandle,
|
|
308
|
+
}),
|
|
309
|
+
[cell, onItemPress, renderContext]
|
|
310
|
+
);
|
|
268
311
|
|
|
269
312
|
const hasNowPlaying = hasOperation(operations, OPERATIONS.NOW_PLAYING);
|
|
270
313
|
const hasClearAll = hasOperation(operations, OPERATIONS.CLEAR_ALL);
|
|
@@ -277,9 +320,9 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
|
|
|
277
320
|
const handleCreatePlaylist = useCallback(() => {
|
|
278
321
|
editableCollection?.add?.({
|
|
279
322
|
id: "create_new_playlist",
|
|
280
|
-
title:
|
|
323
|
+
title: "unknown title",
|
|
281
324
|
});
|
|
282
|
-
}, [editableCollection
|
|
325
|
+
}, [editableCollection]);
|
|
283
326
|
|
|
284
327
|
const headers = useMemo(() => {
|
|
285
328
|
const list: Array<{ index: number; component: () => React.ReactElement }> =
|
|
@@ -291,6 +334,8 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
|
|
|
291
334
|
component: () => (
|
|
292
335
|
<NowPlayingHeaderSection
|
|
293
336
|
onClear={hasClearAll ? handleDeleteCollection : undefined}
|
|
337
|
+
nextUpTitle={nextUpTitle}
|
|
338
|
+
nowPlayingTitle={nowPlayingTitle}
|
|
294
339
|
/>
|
|
295
340
|
),
|
|
296
341
|
});
|
|
@@ -303,11 +348,7 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
|
|
|
303
348
|
<View
|
|
304
349
|
style={{ paddingHorizontal: 20, paddingTop: 8, paddingBottom: 12 }}
|
|
305
350
|
>
|
|
306
|
-
<AudioPlayerButton
|
|
307
|
-
configuration={VARIANT_WITH_ICON}
|
|
308
|
-
data={{ title: createPlaylistTitle }}
|
|
309
|
-
onPress={handleCreatePlaylist}
|
|
310
|
-
/>
|
|
351
|
+
<AudioPlayerButton onPress={handleCreatePlaylist} />
|
|
311
352
|
</View>
|
|
312
353
|
),
|
|
313
354
|
});
|
|
@@ -318,11 +359,31 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
|
|
|
318
359
|
hasNowPlaying,
|
|
319
360
|
hasClearAll,
|
|
320
361
|
handleDeleteCollection,
|
|
362
|
+
nextUpTitle,
|
|
363
|
+
nowPlayingTitle,
|
|
321
364
|
hasAdd,
|
|
322
365
|
handleCreatePlaylist,
|
|
323
366
|
]);
|
|
324
367
|
|
|
325
|
-
const
|
|
368
|
+
const _items = useMemo(() => {
|
|
369
|
+
return (itemsToRender || []).map((item, index) =>
|
|
370
|
+
cell.renderItem({
|
|
371
|
+
item,
|
|
372
|
+
index,
|
|
373
|
+
onPress: onItemPress,
|
|
374
|
+
context: renderContext,
|
|
375
|
+
})
|
|
376
|
+
);
|
|
377
|
+
}, [itemsToRender, cell, onItemPress, renderContext]);
|
|
378
|
+
|
|
379
|
+
const _styles = useMemo(() => {
|
|
380
|
+
return {
|
|
381
|
+
maxHeight: props.maxHeight,
|
|
382
|
+
paddingTop: paddingTop,
|
|
383
|
+
};
|
|
384
|
+
}, [props.maxHeight, paddingTop]);
|
|
385
|
+
|
|
386
|
+
const renderedBody = (() => {
|
|
326
387
|
if (ContentComponent) {
|
|
327
388
|
const shouldWrapInScrollView =
|
|
328
389
|
!contentComponentProps?.disableScrollViewWrap &&
|
|
@@ -331,9 +392,8 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
|
|
|
331
392
|
if (shouldWrapInScrollView) {
|
|
332
393
|
return (
|
|
333
394
|
<ScrollView
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}}
|
|
395
|
+
keyboardShouldPersistTaps="handled"
|
|
396
|
+
contentContainerStyle={calculatedcontentContainerStyle}
|
|
337
397
|
>
|
|
338
398
|
<ContentComponent
|
|
339
399
|
{...contentComponentProps}
|
|
@@ -346,12 +406,7 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
|
|
|
346
406
|
}
|
|
347
407
|
|
|
348
408
|
return (
|
|
349
|
-
<View
|
|
350
|
-
style={{
|
|
351
|
-
flexShrink: 1,
|
|
352
|
-
paddingBottom: paddingBottom + bottomInset,
|
|
353
|
-
}}
|
|
354
|
-
>
|
|
409
|
+
<View style={[styles.scrollView, calculatedcontentContainerStyle]}>
|
|
355
410
|
<ContentComponent
|
|
356
411
|
{...contentComponentProps}
|
|
357
412
|
dismiss={dismiss}
|
|
@@ -395,70 +450,41 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
|
|
|
395
450
|
<SortableList
|
|
396
451
|
sortableData={itemsToRender}
|
|
397
452
|
headers={headers}
|
|
398
|
-
scrollViewStyle={
|
|
399
|
-
|
|
400
|
-
}}
|
|
401
|
-
contentContainerStyle={{
|
|
402
|
-
paddingBottom: paddingBottom + bottomInset,
|
|
403
|
-
}}
|
|
453
|
+
scrollViewStyle={styles.scrollView}
|
|
454
|
+
contentContainerStyle={calculatedcontentContainerStyle}
|
|
404
455
|
onDragEnd={handleDragEnd}
|
|
405
|
-
renderItem={
|
|
406
|
-
cell.renderItem({
|
|
407
|
-
item,
|
|
408
|
-
index,
|
|
409
|
-
onPress: onItemPress,
|
|
410
|
-
context: renderContext,
|
|
411
|
-
renderHandle,
|
|
412
|
-
})
|
|
413
|
-
}
|
|
456
|
+
renderItem={sortableListRenderItem}
|
|
414
457
|
/>
|
|
415
458
|
);
|
|
416
459
|
}
|
|
417
460
|
|
|
418
461
|
return (
|
|
419
462
|
<ScrollView
|
|
463
|
+
keyboardShouldPersistTaps="handled"
|
|
420
464
|
overScrollMode="never"
|
|
421
465
|
bounces={false}
|
|
422
|
-
contentContainerStyle={
|
|
423
|
-
paddingBottom: paddingBottom + bottomInset,
|
|
424
|
-
}}
|
|
466
|
+
contentContainerStyle={calculatedcontentContainerStyle}
|
|
425
467
|
>
|
|
426
468
|
{hasNowPlaying ? (
|
|
427
469
|
<NowPlayingHeaderSection
|
|
428
470
|
onClear={hasClearAll ? handleDeleteCollection : undefined}
|
|
471
|
+
nextUpTitle={nextUpTitle}
|
|
472
|
+
nowPlayingTitle={nowPlayingTitle}
|
|
429
473
|
/>
|
|
430
474
|
) : null}
|
|
431
475
|
{hasAdd ? (
|
|
432
|
-
<View
|
|
433
|
-
|
|
434
|
-
>
|
|
435
|
-
<AudioPlayerButton
|
|
436
|
-
configuration={VARIANT_WITH_ICON}
|
|
437
|
-
data={{ title: createPlaylistTitle }}
|
|
438
|
-
onPress={handleCreatePlaylist}
|
|
439
|
-
/>
|
|
476
|
+
<View style={styles.someStyles}>
|
|
477
|
+
<AudioPlayerButton onPress={handleCreatePlaylist} />
|
|
440
478
|
</View>
|
|
441
479
|
) : null}
|
|
442
|
-
{
|
|
443
|
-
cell.renderItem({
|
|
444
|
-
item,
|
|
445
|
-
index,
|
|
446
|
-
onPress: onItemPress,
|
|
447
|
-
context: renderContext,
|
|
448
|
-
})
|
|
449
|
-
)}
|
|
480
|
+
{_items}
|
|
450
481
|
</ScrollView>
|
|
451
482
|
);
|
|
452
|
-
};
|
|
483
|
+
})();
|
|
453
484
|
|
|
454
485
|
return (
|
|
455
486
|
<ModalBlocksStyleContext.Provider value={styleOverrides as any}>
|
|
456
|
-
<View
|
|
457
|
-
style={{
|
|
458
|
-
maxHeight: props.maxHeight,
|
|
459
|
-
paddingTop: paddingTop,
|
|
460
|
-
}}
|
|
461
|
-
>
|
|
487
|
+
<View style={_styles}>
|
|
462
488
|
<BottomSheetDragArea>
|
|
463
489
|
<Header
|
|
464
490
|
dismiss={dismiss}
|
|
@@ -467,8 +493,10 @@ export function BottomSheetModalContent(props: ModalComponentProps) {
|
|
|
467
493
|
title={resolvedTitle}
|
|
468
494
|
/>
|
|
469
495
|
</BottomSheetDragArea>
|
|
470
|
-
{
|
|
496
|
+
{renderedBody}
|
|
471
497
|
</View>
|
|
472
498
|
</ModalBlocksStyleContext.Provider>
|
|
473
499
|
);
|
|
474
500
|
}
|
|
501
|
+
|
|
502
|
+
export const BottomSheetModalContent = memo(_BottomSheetModalContent);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useMemo } from "react";
|
|
2
2
|
import { TouchableOpacity } from "react-native";
|
|
3
3
|
import { QBImage } from "@applicaster/zapp-react-native-ui-components/Components";
|
|
4
|
+
import { AccessibilityManager } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager";
|
|
4
5
|
// @ts-ignore
|
|
5
6
|
import { defaultCloseAsset } from "./assets";
|
|
6
7
|
|
|
@@ -40,9 +41,20 @@ export function CloseButton(props: CloseButtonProps) {
|
|
|
40
41
|
|
|
41
42
|
if (!enabled) return null;
|
|
42
43
|
|
|
44
|
+
// Expose the close button as its own accessible control so screen readers
|
|
45
|
+
// (e.g. iOS VoiceOver) can focus and activate it. The image-only button
|
|
46
|
+
// otherwise has no label/role, leaving it unreachable/unannounced. Uses the
|
|
47
|
+
// framework's localized "close" button config (label + hint + button role).
|
|
48
|
+
// Computed each render (not memoized) so runtime localization updates via
|
|
49
|
+
// AccessibilityManager.updateLocalizations() are picked up on re-render.
|
|
50
|
+
const accessibilityProps =
|
|
51
|
+
AccessibilityManager.getInstance().getButtonAccessibilityProps("close");
|
|
52
|
+
|
|
43
53
|
return (
|
|
44
54
|
<TouchableOpacity
|
|
45
55
|
activeOpacity={1}
|
|
56
|
+
testID="closeButton"
|
|
57
|
+
{...accessibilityProps}
|
|
46
58
|
style={{
|
|
47
59
|
marginBottom,
|
|
48
60
|
marginTop,
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react-native";
|
|
3
|
+
import { CloseButton, CloseButtonProps } from "../CloseButton";
|
|
4
|
+
|
|
5
|
+
jest.mock("@applicaster/zapp-react-native-ui-components/Components", () => {
|
|
6
|
+
const { Image } = require("react-native");
|
|
7
|
+
|
|
8
|
+
return { QBImage: Image };
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const mockGetButtonA11yProps = jest.fn(() => ({
|
|
12
|
+
accessible: true,
|
|
13
|
+
accessibilityLabel: "Close",
|
|
14
|
+
accessibilityHint: "Closes the sheet",
|
|
15
|
+
accessibilityRole: "button",
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
jest.mock(
|
|
19
|
+
"@applicaster/zapp-react-native-utils/appUtils/accessibilityManager",
|
|
20
|
+
() => ({
|
|
21
|
+
AccessibilityManager: {
|
|
22
|
+
getInstance: () => ({
|
|
23
|
+
getButtonAccessibilityProps: mockGetButtonA11yProps,
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
})
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
const baseProps: CloseButtonProps = {
|
|
30
|
+
enabled: true,
|
|
31
|
+
close: jest.fn(),
|
|
32
|
+
asset: "close.png",
|
|
33
|
+
assetFocused: "close_focused.png",
|
|
34
|
+
height: 24,
|
|
35
|
+
width: 24,
|
|
36
|
+
marginTop: 0,
|
|
37
|
+
marginBottom: 0,
|
|
38
|
+
marginLeft: 0,
|
|
39
|
+
marginRight: 0,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
describe("ModalComponent Header CloseButton", () => {
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
jest.clearAllMocks();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("renders as an accessible button reachable by screen readers", () => {
|
|
48
|
+
render(<CloseButton {...baseProps} />);
|
|
49
|
+
|
|
50
|
+
const button = screen.getByTestId("closeButton");
|
|
51
|
+
|
|
52
|
+
expect(button.props.accessible).toBe(true);
|
|
53
|
+
expect(button.props.accessibilityRole).toBe("button");
|
|
54
|
+
expect(button.props.accessibilityLabel).toBe("Close");
|
|
55
|
+
expect(mockGetButtonA11yProps).toHaveBeenCalledWith("close");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("invokes close on press", () => {
|
|
59
|
+
const close = jest.fn();
|
|
60
|
+
render(<CloseButton {...baseProps} close={close} />);
|
|
61
|
+
|
|
62
|
+
fireEvent.press(screen.getByTestId("closeButton"));
|
|
63
|
+
|
|
64
|
+
expect(close).toHaveBeenCalledTimes(1);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("renders nothing when disabled", () => {
|
|
68
|
+
render(<CloseButton {...baseProps} enabled={false} />);
|
|
69
|
+
|
|
70
|
+
expect(screen.queryByTestId("closeButton")).toBeNull();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useState } from "react";
|
|
1
|
+
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
2
2
|
import Sortable from "react-native-sortables";
|
|
3
3
|
import { Text, View, ViewStyle } from "react-native";
|
|
4
4
|
import Animated, { useAnimatedRef } from "react-native-reanimated";
|
|
@@ -65,6 +65,9 @@ export type SortableListProps = {
|
|
|
65
65
|
}) => void;
|
|
66
66
|
};
|
|
67
67
|
|
|
68
|
+
const defaultKeyExtractor = (item, index) =>
|
|
69
|
+
`sortable-item-${item?.id ?? item?.title ?? index}`;
|
|
70
|
+
|
|
68
71
|
export const SortableList = ({
|
|
69
72
|
scrollViewStyle,
|
|
70
73
|
contentContainerStyle,
|
|
@@ -73,8 +76,7 @@ export const SortableList = ({
|
|
|
73
76
|
columns = 1,
|
|
74
77
|
rowGap = 0,
|
|
75
78
|
columnGap = 0,
|
|
76
|
-
keyExtractor =
|
|
77
|
-
`sortable-item-${item?.id ?? item?.title ?? index}`,
|
|
79
|
+
keyExtractor = defaultKeyExtractor,
|
|
78
80
|
renderItem,
|
|
79
81
|
sortableData = DEFAULT_SORTABLE_DATA,
|
|
80
82
|
headers = DEFAULT_HEADERS,
|
|
@@ -85,7 +87,9 @@ export const SortableList = ({
|
|
|
85
87
|
const [localData, setLocalData] = useState(sortableData);
|
|
86
88
|
|
|
87
89
|
useEffect(() => {
|
|
88
|
-
setLocalData(
|
|
90
|
+
setLocalData((localData) =>
|
|
91
|
+
localData !== sortableData ? sortableData : localData
|
|
92
|
+
);
|
|
89
93
|
}, [sortableData]);
|
|
90
94
|
|
|
91
95
|
const handleDragEnd = useCallback(
|
|
@@ -101,13 +105,24 @@ export const SortableList = ({
|
|
|
101
105
|
[onDragEnd]
|
|
102
106
|
);
|
|
103
107
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
const _renderItem = useCallback(
|
|
109
|
+
({ item, index }) => (
|
|
110
|
+
<View key={keyExtractor(item, index)} style={itemStyle}>
|
|
111
|
+
{renderItem({
|
|
112
|
+
item,
|
|
113
|
+
index,
|
|
114
|
+
renderHandle: (children) => (
|
|
115
|
+
<Sortable.Handle>{children}</Sortable.Handle>
|
|
116
|
+
),
|
|
117
|
+
})}
|
|
118
|
+
</View>
|
|
119
|
+
),
|
|
120
|
+
[itemStyle, keyExtractor, renderItem]
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
const renderHeader = useMemo(
|
|
124
|
+
() =>
|
|
125
|
+
(headers || []).map((header, idx) => (
|
|
111
126
|
<View key={`static-header-${idx}`} style={headerStyle}>
|
|
112
127
|
{header.title ? (
|
|
113
128
|
<SortableListHeader title={header.title} />
|
|
@@ -115,7 +130,17 @@ export const SortableList = ({
|
|
|
115
130
|
renderHeaderComponent(header.component)
|
|
116
131
|
)}
|
|
117
132
|
</View>
|
|
118
|
-
))
|
|
133
|
+
)),
|
|
134
|
+
[headers, headerStyle]
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<Animated.ScrollView
|
|
139
|
+
ref={scrollableRef}
|
|
140
|
+
style={scrollViewStyle}
|
|
141
|
+
contentContainerStyle={contentContainerStyle}
|
|
142
|
+
>
|
|
143
|
+
{renderHeader}
|
|
119
144
|
<Sortable.Grid
|
|
120
145
|
scrollableRef={scrollableRef}
|
|
121
146
|
customHandle
|
|
@@ -125,17 +150,7 @@ export const SortableList = ({
|
|
|
125
150
|
data={localData}
|
|
126
151
|
keyExtractor={keyExtractor}
|
|
127
152
|
onDragEnd={handleDragEnd}
|
|
128
|
-
renderItem={
|
|
129
|
-
<View key={keyExtractor(item, index)} style={itemStyle}>
|
|
130
|
-
{renderItem({
|
|
131
|
-
item,
|
|
132
|
-
index,
|
|
133
|
-
renderHandle: (children) => (
|
|
134
|
-
<Sortable.Handle>{children}</Sortable.Handle>
|
|
135
|
-
),
|
|
136
|
-
})}
|
|
137
|
-
</View>
|
|
138
|
-
)}
|
|
153
|
+
renderItem={_renderItem}
|
|
139
154
|
/>
|
|
140
155
|
</Animated.ScrollView>
|
|
141
156
|
);
|
|
@@ -20,6 +20,7 @@ export type TextInputContentProps = {
|
|
|
20
20
|
defaultValue?: string;
|
|
21
21
|
buttonLabel: string;
|
|
22
22
|
actions: ActionType[];
|
|
23
|
+
actionContext?: Record<string, any>;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
const styles = StyleSheet.create({
|
|
@@ -38,7 +39,13 @@ const styles = StyleSheet.create({
|
|
|
38
39
|
* Standard dismiss header comes from BottomSheetModalContent / ModalHeader.
|
|
39
40
|
*/
|
|
40
41
|
export function TextInputContent(props: TextInputContentProps) {
|
|
41
|
-
const {
|
|
42
|
+
const {
|
|
43
|
+
inputLabel,
|
|
44
|
+
defaultValue = "",
|
|
45
|
+
buttonLabel,
|
|
46
|
+
actions,
|
|
47
|
+
actionContext,
|
|
48
|
+
} = props;
|
|
42
49
|
|
|
43
50
|
const [textValue, setTextValue] = useState(defaultValue);
|
|
44
51
|
const [submitting, setSubmitting] = useState(false);
|
|
@@ -68,12 +75,17 @@ export function TextInputContent(props: TextInputContentProps) {
|
|
|
68
75
|
return item;
|
|
69
76
|
});
|
|
70
77
|
|
|
71
|
-
|
|
78
|
+
if (actionContext) {
|
|
79
|
+
await actionExecutor.handleActions(updatedActions, actionContext);
|
|
80
|
+
} else {
|
|
81
|
+
await actionExecutor.handleActions(updatedActions);
|
|
82
|
+
}
|
|
83
|
+
|
|
72
84
|
await actionExecutor.handleAction({ type: "dismissBottomSheet" });
|
|
73
85
|
} finally {
|
|
74
86
|
setSubmitting(false);
|
|
75
87
|
}
|
|
76
|
-
}, [submitting, actions, textValue]);
|
|
88
|
+
}, [submitting, actions, textValue, actionContext]);
|
|
77
89
|
|
|
78
90
|
return (
|
|
79
91
|
<View style={styles.container}>
|
|
@@ -82,18 +82,21 @@ jest.mock("../AudioPlayer/Components/Item", () => ({
|
|
|
82
82
|
VARIANT_PLAYLIST_ITEM: {},
|
|
83
83
|
}));
|
|
84
84
|
|
|
85
|
+
const mockAudioPlayerButtonProps: Array<any> = [];
|
|
86
|
+
|
|
85
87
|
jest.mock("../AudioPlayer/Components", () => ({
|
|
86
88
|
NowPlayingHeaderSection: () => null,
|
|
87
|
-
AudioPlayerButton: (
|
|
89
|
+
AudioPlayerButton: (props: any) => {
|
|
88
90
|
const { Text } = require("react-native");
|
|
89
91
|
|
|
92
|
+
mockAudioPlayerButtonProps.push(props);
|
|
93
|
+
|
|
90
94
|
return (
|
|
91
|
-
<Text testID="create-playlist-button" onPress={onPress}>
|
|
92
|
-
{data
|
|
95
|
+
<Text testID="create-playlist-button" onPress={props.onPress}>
|
|
96
|
+
{props.data?.title}
|
|
93
97
|
</Text>
|
|
94
98
|
);
|
|
95
99
|
},
|
|
96
|
-
VARIANT_WITH_ICON: {},
|
|
97
100
|
}));
|
|
98
101
|
|
|
99
102
|
const baseProps = {
|
|
@@ -171,6 +174,8 @@ describe("BottomSheetModalContent role/behavior cells", () => {
|
|
|
171
174
|
});
|
|
172
175
|
|
|
173
176
|
it("renders create playlist button when operations include add and calls editableCollection.add on press", () => {
|
|
177
|
+
mockAudioPlayerButtonProps.length = 0;
|
|
178
|
+
|
|
174
179
|
const addMock = jest.fn();
|
|
175
180
|
const { BehaviorSubject } = require("rxjs");
|
|
176
181
|
|
|
@@ -192,12 +197,22 @@ describe("BottomSheetModalContent role/behavior cells", () => {
|
|
|
192
197
|
const createBtn = screen.getByTestId("create-playlist-button");
|
|
193
198
|
expect(createBtn).toBeTruthy();
|
|
194
199
|
|
|
200
|
+
// The button is rendered bare: styling comes from the modal blocks theme
|
|
201
|
+
// and the title from the button block, so no configuration/data is passed.
|
|
202
|
+
expect(mockAudioPlayerButtonProps.length).toBeGreaterThan(0);
|
|
203
|
+
|
|
204
|
+
for (const props of mockAudioPlayerButtonProps) {
|
|
205
|
+
expect(props.configuration).toBeUndefined();
|
|
206
|
+
expect(props.data).toBeUndefined();
|
|
207
|
+
expect(typeof props.onPress).toBe("function");
|
|
208
|
+
}
|
|
209
|
+
|
|
195
210
|
const { fireEvent } = require("@testing-library/react-native");
|
|
196
211
|
fireEvent.press(createBtn);
|
|
197
212
|
|
|
198
213
|
expect(addMock).toHaveBeenCalledWith({
|
|
199
214
|
id: "create_new_playlist",
|
|
200
|
-
title: "
|
|
215
|
+
title: "unknown title",
|
|
201
216
|
});
|
|
202
217
|
});
|
|
203
218
|
|
|
@@ -235,4 +250,21 @@ describe("BottomSheetModalContent role/behavior cells", () => {
|
|
|
235
250
|
const { ScrollView } = require("react-native");
|
|
236
251
|
expect(() => UNSAFE_getByType(ScrollView)).toThrow();
|
|
237
252
|
});
|
|
253
|
+
|
|
254
|
+
it("sets keyboardShouldPersistTaps='handled' on ScrollView wrapping contentComponent", () => {
|
|
255
|
+
const CustomComponent = () => (
|
|
256
|
+
<React.Fragment>Custom Content</React.Fragment>
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
const { UNSAFE_getByType } = render(
|
|
260
|
+
<BottomSheetModalContent
|
|
261
|
+
{...baseProps}
|
|
262
|
+
contentComponent={CustomComponent}
|
|
263
|
+
/>
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
const { ScrollView } = require("react-native");
|
|
267
|
+
const scrollView = UNSAFE_getByType(ScrollView);
|
|
268
|
+
expect(scrollView.props.keyboardShouldPersistTaps).toBe("handled");
|
|
269
|
+
});
|
|
238
270
|
});
|
|
@@ -117,4 +117,40 @@ describe("TextInputContent", () => {
|
|
|
117
117
|
type: "dismissBottomSheet",
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
|
+
|
|
121
|
+
it("forwards actionContext into handleActions so rename can refresh the List", async () => {
|
|
122
|
+
const actionContext = {
|
|
123
|
+
component: {
|
|
124
|
+
id: "list-1",
|
|
125
|
+
data: { source: "https://example.com/user/collections/abc" },
|
|
126
|
+
},
|
|
127
|
+
screenData: { id: "playlist-screen" },
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
render(<TextInputContent {...baseProps} actionContext={actionContext} />);
|
|
131
|
+
|
|
132
|
+
fireEvent.press(screen.getByTestId("submit-button"));
|
|
133
|
+
|
|
134
|
+
await waitFor(() => {
|
|
135
|
+
expect(actionExecutor.handleActions).toHaveBeenCalledTimes(1);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
expect(actionExecutor.handleActions).toHaveBeenCalledWith(
|
|
139
|
+
[
|
|
140
|
+
{
|
|
141
|
+
type: "sendCloudEvent",
|
|
142
|
+
options: {
|
|
143
|
+
url: "https://server.com/cloud-events",
|
|
144
|
+
type: "com.applicaster.collection.create.v1",
|
|
145
|
+
subject: "edit_collection",
|
|
146
|
+
data: {
|
|
147
|
+
collectionId: "playlist-123",
|
|
148
|
+
name: "Summer Hits",
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
actionContext
|
|
154
|
+
);
|
|
155
|
+
});
|
|
120
156
|
});
|