@applicaster/zapp-react-native-ui-components 12.0.2-rc.0 → 13.0.0-alpha.1552112220
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 +5 -9
- package/Components/Cell/CellWithFocusable.tsx +1 -1
- package/Components/Cell/TvOSCellComponent.tsx +3 -4
- package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +67 -7
- package/Components/GeneralContentScreen/utils/useCurationAPI.ts +53 -9
- package/Components/NativeFocusables/{index.js → index.ts} +4 -2
- package/Decorators/Analytics/{index.js → index.tsx} +11 -11
- package/README.md +1 -13
- package/package.json +5 -5
package/Components/Cell/Cell.tsx
CHANGED
|
@@ -14,10 +14,7 @@ import { BaseFocusable } from "../BaseFocusable";
|
|
|
14
14
|
import { AccessibilityManager } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager";
|
|
15
15
|
|
|
16
16
|
type Props = {
|
|
17
|
-
item:
|
|
18
|
-
id: string;
|
|
19
|
-
title: string;
|
|
20
|
-
};
|
|
17
|
+
item: ZappEntry;
|
|
21
18
|
index: number;
|
|
22
19
|
shouldScrollHorizontally: (arg1: [any]) => boolean | null | undefined;
|
|
23
20
|
shouldScrollVertically: (...args: any) => boolean | null | undefined;
|
|
@@ -33,10 +30,9 @@ type Props = {
|
|
|
33
30
|
id: string;
|
|
34
31
|
};
|
|
35
32
|
selected?: boolean;
|
|
36
|
-
CellRenderer: React.
|
|
37
|
-
item:
|
|
38
|
-
|
|
39
|
-
}> & { hasFocusableInside: (item: Record<string, string>) => boolean };
|
|
33
|
+
CellRenderer: React.FunctionComponent<any> & {
|
|
34
|
+
hasFocusableInside: (item: ZappEntry) => boolean;
|
|
35
|
+
};
|
|
40
36
|
preferredFocus: boolean;
|
|
41
37
|
navigator: {
|
|
42
38
|
push: (arg1: Record<any, any>) => void;
|
|
@@ -276,7 +272,7 @@ export class CellComponent extends React.Component<Props, State> {
|
|
|
276
272
|
|
|
277
273
|
if (isFocused) {
|
|
278
274
|
const accessibilityManager = AccessibilityManager.getInstance();
|
|
279
|
-
accessibilityManager.readText({ text: item.title });
|
|
275
|
+
accessibilityManager.readText({ text: String(item.title) });
|
|
280
276
|
}
|
|
281
277
|
|
|
282
278
|
return (
|
|
@@ -36,10 +36,9 @@ type Props = {
|
|
|
36
36
|
component_type: string;
|
|
37
37
|
};
|
|
38
38
|
selected: boolean;
|
|
39
|
-
CellRenderer: React.
|
|
40
|
-
item: any;
|
|
41
|
-
|
|
42
|
-
}> & { hasFocusableInside: (item: any) => boolean };
|
|
39
|
+
CellRenderer: React.FunctionComponent<any> & {
|
|
40
|
+
hasFocusableInside: (item: any) => boolean;
|
|
41
|
+
};
|
|
43
42
|
preferredFocus: boolean;
|
|
44
43
|
navigator: {
|
|
45
44
|
push: (arg1: Record<any, any>) => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as React from "react";
|
|
1
2
|
import { renderHook } from "@testing-library/react-hooks";
|
|
2
3
|
|
|
3
4
|
import {
|
|
@@ -9,6 +10,42 @@ import {
|
|
|
9
10
|
import * as redux from "react-redux";
|
|
10
11
|
import * as layoutPresets from "@applicaster/zapp-react-native-redux/hooks/useLayoutPresets";
|
|
11
12
|
import * as pipesFeeds from "@applicaster/zapp-react-native-redux/hooks/useZappPipesFeeds";
|
|
13
|
+
import { NavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NavigationContext";
|
|
14
|
+
import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
|
|
15
|
+
|
|
16
|
+
import { Provider } from "react-redux";
|
|
17
|
+
import configureStore from "redux-mock-store";
|
|
18
|
+
|
|
19
|
+
const homeStack = {
|
|
20
|
+
route: "/home",
|
|
21
|
+
state: {
|
|
22
|
+
screen: { id: "123" },
|
|
23
|
+
entry: { id: "abc" },
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const mainStackNavigator = {
|
|
28
|
+
getStackForPathname: jest.fn().mockReturnValue(homeStack),
|
|
29
|
+
modalState: {
|
|
30
|
+
screen: {
|
|
31
|
+
id: "modal-1",
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const store = configureStore()({});
|
|
37
|
+
|
|
38
|
+
const wrapper = ({ children }) => (
|
|
39
|
+
<Provider store={store}>
|
|
40
|
+
<NavigationContext.Provider
|
|
41
|
+
value={{ ...mainStackNavigator, currentRoute: homeStack.route }}
|
|
42
|
+
>
|
|
43
|
+
<PathnameContext.Provider value={homeStack.route}>
|
|
44
|
+
{children}
|
|
45
|
+
</PathnameContext.Provider>
|
|
46
|
+
</NavigationContext.Provider>
|
|
47
|
+
</Provider>
|
|
48
|
+
);
|
|
12
49
|
|
|
13
50
|
describe("getTransformedPreset should return the passed components if smartComponents is empty", () => {
|
|
14
51
|
describe("getTransformedPreset function", () => {
|
|
@@ -94,9 +131,13 @@ describe("getTransformedPreset should return the passed components if smartCompo
|
|
|
94
131
|
},
|
|
95
132
|
};
|
|
96
133
|
|
|
134
|
+
const mockUrlsMap = {
|
|
135
|
+
[mockSmartComp.id]: mockSmartComp.data.source,
|
|
136
|
+
};
|
|
137
|
+
|
|
97
138
|
it("should return the component itself if its component_type is not SMART_COMPONENT_TYPE", () => {
|
|
98
139
|
expect(
|
|
99
|
-
enrichComponent(mockComp, 0, mockFeeds, mockLayoutPresets)
|
|
140
|
+
enrichComponent(mockComp, 0, mockFeeds, mockLayoutPresets, mockUrlsMap)
|
|
100
141
|
).toEqual([mockComp]);
|
|
101
142
|
});
|
|
102
143
|
|
|
@@ -106,8 +147,18 @@ describe("getTransformedPreset should return the passed components if smartCompo
|
|
|
106
147
|
data: { source: "missing_source" },
|
|
107
148
|
};
|
|
108
149
|
|
|
150
|
+
const missing_source_urls_map = {
|
|
151
|
+
[missing_source_comp.id]: missing_source_comp.data.source,
|
|
152
|
+
};
|
|
153
|
+
|
|
109
154
|
expect(
|
|
110
|
-
enrichComponent(
|
|
155
|
+
enrichComponent(
|
|
156
|
+
missing_source_comp,
|
|
157
|
+
0,
|
|
158
|
+
mockFeeds,
|
|
159
|
+
mockLayoutPresets,
|
|
160
|
+
missing_source_urls_map
|
|
161
|
+
)
|
|
111
162
|
).toEqual(null);
|
|
112
163
|
});
|
|
113
164
|
|
|
@@ -116,7 +167,8 @@ describe("getTransformedPreset should return the passed components if smartCompo
|
|
|
116
167
|
mockSmartComp,
|
|
117
168
|
0,
|
|
118
169
|
mockFeeds,
|
|
119
|
-
mockLayoutPresets
|
|
170
|
+
mockLayoutPresets,
|
|
171
|
+
mockUrlsMap
|
|
120
172
|
);
|
|
121
173
|
|
|
122
174
|
expect(Array.isArray(result)).toBe(true);
|
|
@@ -262,7 +314,9 @@ describe("getTransformedPreset should return the passed components if smartCompo
|
|
|
262
314
|
|
|
263
315
|
mockUseLayoutPresets.mockReturnValue({});
|
|
264
316
|
|
|
265
|
-
const { result } = renderHook(() => useCurationAPI(mockComponents)
|
|
317
|
+
const { result } = renderHook(() => useCurationAPI(mockComponents), {
|
|
318
|
+
wrapper,
|
|
319
|
+
});
|
|
266
320
|
|
|
267
321
|
// if there are no smart components, it should return the original array
|
|
268
322
|
expect(result.current).toEqual(mockComponents);
|
|
@@ -313,7 +367,9 @@ describe("getTransformedPreset should return the passed components if smartCompo
|
|
|
313
367
|
|
|
314
368
|
mockUseLayoutPresets.mockReturnValue(mockLayoutPresets);
|
|
315
369
|
|
|
316
|
-
const { result } = renderHook(() => useCurationAPI(mockComponents)
|
|
370
|
+
const { result } = renderHook(() => useCurationAPI(mockComponents), {
|
|
371
|
+
wrapper,
|
|
372
|
+
});
|
|
317
373
|
|
|
318
374
|
expect(result.current).toEqual(mockTransformedComponents);
|
|
319
375
|
});
|
|
@@ -383,7 +439,9 @@ describe("getTransformedPreset should return the passed components if smartCompo
|
|
|
383
439
|
|
|
384
440
|
mockUseLayoutPresets.mockReturnValue(mockLayoutPresets);
|
|
385
441
|
|
|
386
|
-
const { result } = renderHook(() => useCurationAPI(mockComponents)
|
|
442
|
+
const { result } = renderHook(() => useCurationAPI(mockComponents), {
|
|
443
|
+
wrapper,
|
|
444
|
+
});
|
|
387
445
|
|
|
388
446
|
expect(result.current).toEqual(mockTransformedComponents);
|
|
389
447
|
});
|
|
@@ -434,7 +492,9 @@ describe("getTransformedPreset should return the passed components if smartCompo
|
|
|
434
492
|
const mockUseLayoutPresets = jest.spyOn(layoutPresets, "useLayoutPresets");
|
|
435
493
|
mockUseLayoutPresets.mockReturnValue(mockLayoutPresets);
|
|
436
494
|
|
|
437
|
-
const { result } = renderHook(() => useCurationAPI(mockComponents)
|
|
495
|
+
const { result } = renderHook(() => useCurationAPI(mockComponents), {
|
|
496
|
+
wrapper,
|
|
497
|
+
});
|
|
438
498
|
|
|
439
499
|
expect(result.current).toEqual(mockTransformedComponents);
|
|
440
500
|
});
|
|
@@ -9,6 +9,18 @@ import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
|
9
9
|
import { isEmptyOrNil } from "@applicaster/zapp-react-native-utils/cellUtils";
|
|
10
10
|
import { Categories } from "./logger";
|
|
11
11
|
import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
12
|
+
import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
13
|
+
import {
|
|
14
|
+
ZappPipesEntryContext,
|
|
15
|
+
ZappPipesScreenContext,
|
|
16
|
+
ZappPipesSearchContext,
|
|
17
|
+
} from "@applicaster/zapp-react-native-ui-components/Contexts";
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
getInflatedDataSourceUrl,
|
|
21
|
+
getSearchContext,
|
|
22
|
+
} from "@applicaster/zapp-react-native-utils/reactHooks/feed/useInflatedUrl";
|
|
23
|
+
|
|
12
24
|
import { produce } from "immer";
|
|
13
25
|
// types reference
|
|
14
26
|
|
|
@@ -20,6 +32,7 @@ type LayoutPresets = PresetsMapping["presets_mappings"];
|
|
|
20
32
|
|
|
21
33
|
const SMART_COMPONENT_TYPE = "quick-brick-smart-component";
|
|
22
34
|
const SOURCE_PATH = ["data", "source"];
|
|
35
|
+
const MAPPING_PATH = ["data", "mapping"];
|
|
23
36
|
|
|
24
37
|
const isSmartComponent = (component) =>
|
|
25
38
|
component.component_type === SMART_COMPONENT_TYPE;
|
|
@@ -58,13 +71,14 @@ export const enrichComponent = (
|
|
|
58
71
|
comp: ZappUIComponent,
|
|
59
72
|
index: number,
|
|
60
73
|
feeds: Feeds,
|
|
61
|
-
layoutPresets: LayoutPresets
|
|
74
|
+
layoutPresets: LayoutPresets,
|
|
75
|
+
urlsMap: { [key: string]: string }
|
|
62
76
|
): ZappUIComponent[] | null => {
|
|
63
77
|
if (!isSmartComponent(comp)) {
|
|
64
78
|
return [comp];
|
|
65
79
|
}
|
|
66
80
|
|
|
67
|
-
const presets = prop<string[]>(
|
|
81
|
+
const presets = prop<string[]>(urlsMap[comp.id], feeds);
|
|
68
82
|
|
|
69
83
|
if (presets && presets.data && presets.data.entry) {
|
|
70
84
|
return presets.data.entry
|
|
@@ -113,11 +127,35 @@ export const useCurationAPI = (
|
|
|
113
127
|
[components]
|
|
114
128
|
);
|
|
115
129
|
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
130
|
+
const { pathname } = useRoute();
|
|
131
|
+
const [entryContext] = ZappPipesEntryContext.useZappPipesContext(pathname);
|
|
132
|
+
const [searchContext] = ZappPipesSearchContext.useZappPipesContext();
|
|
133
|
+
const [screenContext] = ZappPipesScreenContext.useZappPipesContext();
|
|
134
|
+
|
|
135
|
+
const urlsMap = useMemo<{ [key: string]: string }>(() => {
|
|
136
|
+
const map = {};
|
|
137
|
+
|
|
138
|
+
smartComponents?.forEach?.((component) => {
|
|
139
|
+
const url = path(SOURCE_PATH, component);
|
|
140
|
+
const mapping = path(MAPPING_PATH, component);
|
|
141
|
+
|
|
142
|
+
map[component.id] = mapping
|
|
143
|
+
? getInflatedDataSourceUrl({
|
|
144
|
+
source: url,
|
|
145
|
+
contexts: {
|
|
146
|
+
entry: entryContext,
|
|
147
|
+
screen: screenContext,
|
|
148
|
+
search: getSearchContext(searchContext, mapping),
|
|
149
|
+
},
|
|
150
|
+
mapping,
|
|
151
|
+
})
|
|
152
|
+
: url;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
return map;
|
|
156
|
+
}, [smartComponents, entryContext, screenContext, searchContext]);
|
|
157
|
+
|
|
158
|
+
const urls = useMemo<string[]>(() => Object.values(urlsMap), [urlsMap]);
|
|
121
159
|
|
|
122
160
|
useEffect(() => {
|
|
123
161
|
urls.forEach((url, index) => {
|
|
@@ -138,11 +176,17 @@ export const useCurationAPI = (
|
|
|
138
176
|
if (!components) return [];
|
|
139
177
|
|
|
140
178
|
return components.reduce((acc, comp, index) => {
|
|
141
|
-
const enrichedComp = enrichComponent(
|
|
179
|
+
const enrichedComp = enrichComponent(
|
|
180
|
+
comp,
|
|
181
|
+
index,
|
|
182
|
+
feeds,
|
|
183
|
+
layoutPresets,
|
|
184
|
+
urlsMap
|
|
185
|
+
);
|
|
142
186
|
|
|
143
187
|
return enrichedComp ? [...acc, ...enrichedComp] : acc;
|
|
144
188
|
}, [] as Array<ZappUIComponent>);
|
|
145
|
-
}, [components, feeds, layoutPresets]);
|
|
189
|
+
}, [components, feeds, layoutPresets, urlsMap]);
|
|
146
190
|
|
|
147
191
|
return getFinalComponents(
|
|
148
192
|
enrichedComponents,
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { requireNativeComponent, View } from "react-native";
|
|
2
2
|
import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/Platform";
|
|
3
3
|
|
|
4
|
+
// @TODO define the types
|
|
4
5
|
export const FocusableGroupNative = isAppleTV()
|
|
5
|
-
? requireNativeComponent("FocusableGroupViewModule"
|
|
6
|
+
? requireNativeComponent<any>("FocusableGroupViewModule")
|
|
6
7
|
: View;
|
|
7
8
|
|
|
9
|
+
// @TODO define the types
|
|
8
10
|
export const FocusableItemNative = isAppleTV()
|
|
9
|
-
? requireNativeComponent("FocusableViewModule"
|
|
11
|
+
? requireNativeComponent<any>("FocusableViewModule")
|
|
10
12
|
: View;
|
|
@@ -5,18 +5,18 @@ import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
|
5
5
|
|
|
6
6
|
type ComponentProps = {
|
|
7
7
|
component: {
|
|
8
|
-
id: string
|
|
9
|
-
rules: { item_limit: number
|
|
10
|
-
component_type: string
|
|
8
|
+
id: string;
|
|
9
|
+
rules: { item_limit: number; component_cells_selectable: boolean };
|
|
10
|
+
component_type: string;
|
|
11
11
|
styles: {
|
|
12
|
-
cell_style: string
|
|
13
|
-
header: { visible: boolean }
|
|
14
|
-
component_cells_selectable: boolean
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
zappPipesData: { url: string
|
|
18
|
-
selected: boolean
|
|
19
|
-
assets: { menu_button: string }
|
|
12
|
+
cell_style: string;
|
|
13
|
+
header: { visible: boolean };
|
|
14
|
+
component_cells_selectable: boolean;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
zappPipesData: { url: string; data: { title: string } };
|
|
18
|
+
selected: boolean;
|
|
19
|
+
assets: { menu_button: string };
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
function withAnalytics(Component) {
|
package/README.md
CHANGED
|
@@ -78,17 +78,6 @@ export default MyAwesomeComponent;
|
|
|
78
78
|
export { MyAwesomeComponent } from "./MyAwesomeComponent";
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
We provide flow types for component props - please use it to make sure your component will be compliant
|
|
82
|
-
|
|
83
|
-
```javascript
|
|
84
|
-
import * as React from "react";
|
|
85
|
-
import type { ZappComponentProps } from "../../flow-types"; // in the root of the project
|
|
86
|
-
|
|
87
|
-
export class MyComponent extends React.Component<ZappComponentProps> {
|
|
88
|
-
/* ... */
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
|
-
|
|
92
81
|
## Connecting my component to Zapp Pipes
|
|
93
82
|
|
|
94
83
|
Zapp App components rely on [Zapp-Pipes](https://github.com/applicaster/zapp-pipes) to load data.
|
|
@@ -100,10 +89,9 @@ In order to connect your component to ZappPipes, you simply need to use the `Zap
|
|
|
100
89
|
import * as React from "react";
|
|
101
90
|
import { View, Text } from "react-native";
|
|
102
91
|
import { zappPipesDataConnector } from "../ZappPipesDataConnector";
|
|
103
|
-
import type { ZappComponentProps } from "../../flow-types";
|
|
104
92
|
|
|
105
93
|
@zappPipesDataConnector
|
|
106
|
-
export class MyComponent extends React.Component
|
|
94
|
+
export class MyComponent extends React.Component {
|
|
107
95
|
renderComponent = (data) => {
|
|
108
96
|
return (
|
|
109
97
|
<View>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-ui-components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.0-alpha.1552112220",
|
|
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",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"redux-mock-store": "^1.5.3"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@applicaster/applicaster-types": "
|
|
38
|
-
"@applicaster/zapp-react-native-bridge": "
|
|
39
|
-
"@applicaster/zapp-react-native-redux": "
|
|
40
|
-
"@applicaster/zapp-react-native-utils": "
|
|
37
|
+
"@applicaster/applicaster-types": "13.0.0-alpha.1552112220",
|
|
38
|
+
"@applicaster/zapp-react-native-bridge": "13.0.0-alpha.1552112220",
|
|
39
|
+
"@applicaster/zapp-react-native-redux": "13.0.0-alpha.1552112220",
|
|
40
|
+
"@applicaster/zapp-react-native-utils": "13.0.0-alpha.1552112220",
|
|
41
41
|
"promise": "^8.3.0",
|
|
42
42
|
"react-router-native": "^5.1.2",
|
|
43
43
|
"url": "^0.11.0",
|