@applicaster/zapp-react-native-utils 12.0.0-rc.13 → 12.0.0-rc.130
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/actionsExecutor/ActionExecutorContext.tsx +16 -8
- package/analyticsUtils/AnalyticPlayerListener.ts +141 -0
- package/analyticsUtils/AnalyticsEvents/index.ts +13 -0
- package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
- package/analyticsUtils/AnalyticsEvents/sendShareEvent.ts +21 -0
- package/analyticsUtils/PlayerAnalyticsManager.ts +90 -0
- package/analyticsUtils/__tests__/analyticsManager.test.js +75 -73
- package/analyticsUtils/analyticsPlugins.ts +25 -0
- package/analyticsUtils/events.ts +12 -0
- package/analyticsUtils/helpers/hooks.ts +1 -1
- package/analyticsUtils/index.tsx +12 -0
- package/analyticsUtils/{analyticsTracker.ts → playerAnalyticsTracker.ts} +19 -10
- package/appUtils/HooksManager/index.js +3 -1
- package/appUtils/accessibilityManager/const.ts +50 -0
- package/appUtils/accessibilityManager/hooks.ts +40 -0
- package/appUtils/accessibilityManager/index.ts +166 -0
- package/appUtils/accessibilityManager/logger.ts +5 -0
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -3
- package/appUtils/focusManager/__tests__/focusManager.test.js +4 -24
- package/appUtils/focusManager/__tests__/index.test.ts +2 -3
- package/appUtils/focusManager/index.ts +76 -57
- package/appUtils/focusManager/treeDataStructure/Utils/index.js +75 -35
- package/appUtils/focusManager/utils/index.ts +100 -0
- package/appUtils/focusManagerAux/index.ts +76 -0
- package/appUtils/focusManagerAux/utils/index.ts +100 -0
- package/appUtils/index.js +2 -0
- package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +1 -1
- package/appUtils/keyCodes/__tests__/keyCodes.test.js +80 -85
- package/appUtils/keyCodes/keys.web.js +9 -0
- package/appUtils/keyCodes/keysByPlatform.js +11 -1
- package/appUtils/platform/const.ts +25 -0
- package/appUtils/platform/index.ts +3 -0
- package/appUtils/platform/platformUtils.ts +218 -0
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +53 -0
- package/appUtils/playerManager/conts.ts +6 -0
- package/appUtils/playerManager/index.ts +20 -32
- package/appUtils/playerManager/nativePlayerManager.ts +12 -0
- package/appUtils/playerManager/player.ts +56 -7
- package/appUtils/playerManager/playerFactory.ts +15 -1
- package/appUtils/playerManager/playerHooks/usePlayerCurrentTime.tsx +57 -0
- package/appUtils/playerManager/playerNative.ts +41 -15
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +8 -2
- package/appUtils/playerManager/usePlayerState.tsx +20 -23
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +50 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +63 -0
- package/arrayUtils/index.ts +16 -0
- package/booleanUtils/index.ts +4 -4
- package/cellUtils/__tests__/cellUtils.test.ts +48 -0
- package/cellUtils/__tests__/fixtures.ts +13 -0
- package/cellUtils/index.ts +78 -7
- package/dateUtils/index.ts +11 -0
- package/focusManager/FocusManager.ts +20 -5
- package/focusManager/__tests__/FocusManager.test.ts +0 -1
- package/focusManager/index.ts +1 -1
- package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +2 -2
- package/functionUtils/__tests__/functionUtils.test.js +244 -248
- package/functionUtils/index.ts +38 -0
- package/headersUtils/index.ts +1 -0
- package/index.d.ts +15 -0
- package/inflatedUrlUtils/index.ts +4 -4
- package/keyboardState/index.ts +0 -0
- package/localizationUtils/__tests__/localizationUtils.test.ts +78 -55
- package/localizationUtils/index.ts +13 -19
- package/logger/index.ts +1 -1
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +131 -1
- package/manifestUtils/index.js +5 -1
- package/manifestUtils/keys.js +2 -1
- package/manifestUtils/secondaryImage/index.js +18 -15
- package/modalState/index.ts +57 -0
- package/navigationUtils/index.ts +105 -8
- package/numberUtils/__tests__/isLikeNumber.test.ts +18 -0
- package/numberUtils/__tests__/toNumber.test.ts +2 -2
- package/numberUtils/__tests__/toPositiveNumberWithDefault.test.ts +66 -0
- package/numberUtils/__tests__/toPositiveNumberWithDefaultZero.test.ts +66 -0
- package/numberUtils/index.ts +27 -16
- package/package.json +3 -2
- package/playerUtils/configurationGenerator.ts +131 -1
- package/playerUtils/imaScriptDom.ts +59 -0
- package/pluginUtils/index.ts +20 -7
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
- package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +18 -1
- package/reactHooks/cell-click/__tests__/index.test.js +19 -6
- package/reactHooks/cell-click/index.ts +30 -16
- package/reactHooks/debugging/__tests__/index.test.js +81 -11
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +69 -6
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +30 -70
- package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +6 -2
- package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
- package/reactHooks/feed/useBatchLoading.ts +52 -28
- package/reactHooks/feed/useBuildPipesUrl.ts +7 -10
- package/reactHooks/feed/useFeedRefresh.tsx +9 -7
- package/reactHooks/feed/useInflatedUrl.ts +44 -15
- package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +16 -9
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +66 -59
- package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
- package/reactHooks/layout/types/index.ts +2 -0
- package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +134 -0
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +11 -16
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +12 -14
- package/reactHooks/layout/useDimensions/useDimensions.ts +15 -7
- package/reactHooks/navigation/__mocks__/index.ts +15 -0
- package/reactHooks/navigation/__mocks__/useNavigation.ts +7 -0
- package/reactHooks/navigation/__tests__/index.test.tsx +240 -81
- package/reactHooks/navigation/index.ts +240 -81
- package/reactHooks/player/useAutoSeek.tsx +9 -7
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
- package/reactHooks/resolvers/useCellResolver.ts +5 -1
- package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
- package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
- package/reactHooks/screen/index.ts +4 -0
- package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
- package/reactHooks/screen/useScreenContext.ts +4 -4
- package/reactHooks/screen/useScreenData.ts +1 -1
- package/reactHooks/screen/useTargetScreenData.ts +7 -0
- package/reactHooks/state/useRivers.ts +3 -1
- package/reactHooks/useConfiguration.ts +2 -2
- package/reactHooks/useListenEventBusEvent.ts +1 -4
- package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +10 -9
- package/reactUtils/index.ts +104 -0
- package/riverComponetsMeasurementProvider/index.tsx +2 -2
- package/stringUtils/index.ts +5 -0
- package/testUtils/getByTestId.ts +14 -0
- package/testUtils/index.tsx +71 -23
- package/types.ts +4 -0
- package/appUtils/focusManager/FocusableEvents.ts +0 -8
- package/appUtils/focusManager/treeDataStructure/Utils/__tests__/Utils_android.test.js +0 -1094
- package/appUtils/focusManager/treeDataStructure/Utils/index.android.js +0 -261
|
@@ -2,18 +2,10 @@ import * as R from "ramda";
|
|
|
2
2
|
import { isEmptyOrNil } from "@applicaster/zapp-react-native-utils/cellUtils";
|
|
3
3
|
import { createLogger, utilsLogger } from "../../logger";
|
|
4
4
|
import { Player } from "./player";
|
|
5
|
-
import { findNodeHandle
|
|
6
|
-
import { isApplePlatform } from "../../reactUtils";
|
|
5
|
+
import { findNodeHandle } from "react-native";
|
|
7
6
|
import { PlayerRole } from "./conts";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
QuickBrickPlayerPlugin: isApplePlatform()
|
|
11
|
-
? NativeModules.PlayerModule
|
|
12
|
-
: NativeModules.QuickBrickDefaultPlayerModule,
|
|
13
|
-
KalturaPlayerPlugin: isApplePlatform()
|
|
14
|
-
? NativeModules.KalturaPlayerModule
|
|
15
|
-
: NativeModules.QBKalturaPlayerModule,
|
|
16
|
-
};
|
|
7
|
+
import { toBooleanWithDefaultFalse } from "../../booleanUtils";
|
|
8
|
+
import { RNPlayerManager } from "./nativePlayerManager";
|
|
17
9
|
|
|
18
10
|
const logger = createLogger({
|
|
19
11
|
category: "PlayerNativeController",
|
|
@@ -41,6 +33,9 @@ const PlayerModuleFuncNames = {
|
|
|
41
33
|
rewind: "rewind",
|
|
42
34
|
play: "play",
|
|
43
35
|
pause: "pause",
|
|
36
|
+
startSleepTimer: "startSleepTimer",
|
|
37
|
+
cancelSleepTimer: "cancelSleepTimer",
|
|
38
|
+
getSleepTimerEnd: "getSleepTimerEnd",
|
|
44
39
|
};
|
|
45
40
|
|
|
46
41
|
export class PlayerNative extends Player {
|
|
@@ -66,7 +61,7 @@ export class PlayerNative extends Player {
|
|
|
66
61
|
currentPlayerComponent = (): ReactComponent<PlayerProps> =>
|
|
67
62
|
this.playerComponent?.current;
|
|
68
63
|
|
|
69
|
-
getState = () => this.
|
|
64
|
+
getState = () => this.playerState;
|
|
70
65
|
|
|
71
66
|
// TODO: Try to add module interface
|
|
72
67
|
invokeNativeFunction = (funcName: string, ...params: any[]): boolean => {
|
|
@@ -107,7 +102,7 @@ export class PlayerNative extends Player {
|
|
|
107
102
|
return;
|
|
108
103
|
}
|
|
109
104
|
|
|
110
|
-
const newPosition = R.clamp(0,
|
|
105
|
+
const newPosition = R.clamp(0, this.playerState.seekableDuration, position);
|
|
111
106
|
|
|
112
107
|
if (
|
|
113
108
|
!this.invokeNativeFunction(
|
|
@@ -172,12 +167,35 @@ export class PlayerNative extends Player {
|
|
|
172
167
|
}
|
|
173
168
|
};
|
|
174
169
|
|
|
170
|
+
startSleepTimer = (sleepTimestamp: number) => {
|
|
171
|
+
if (
|
|
172
|
+
!this.invokeNativeFunction(
|
|
173
|
+
PlayerModuleFuncNames.startSleepTimer,
|
|
174
|
+
sleepTimestamp
|
|
175
|
+
)
|
|
176
|
+
) {
|
|
177
|
+
this.currentPlayerComponent()?.["startSleepTimer"](sleepTimestamp);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
cancelSleepTimer = () => {
|
|
182
|
+
if (!this.invokeNativeFunction(PlayerModuleFuncNames.cancelSleepTimer)) {
|
|
183
|
+
this.currentPlayerComponent()?.[
|
|
184
|
+
PlayerModuleFuncNames.cancelSleepTimer
|
|
185
|
+
]?.();
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
175
189
|
disableBufferAnimation = (): boolean => false;
|
|
176
190
|
|
|
177
|
-
|
|
191
|
+
selectTrack = (
|
|
178
192
|
selected: QuickBrickPlayer.TextTrack | QuickBrickPlayer.AudioTrack
|
|
179
193
|
) => {
|
|
180
|
-
this.currentPlayerComponent()?.["
|
|
194
|
+
this.currentPlayerComponent()?.["selectTrack"]?.(selected);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
setPlaybackRate = (rate: number) => {
|
|
198
|
+
this.currentPlayerComponent()?.["setPlaybackRate"]?.(rate);
|
|
181
199
|
};
|
|
182
200
|
|
|
183
201
|
getPluginConfiguration = () => {
|
|
@@ -265,4 +283,12 @@ export class PlayerNative extends Player {
|
|
|
265
283
|
|
|
266
284
|
return !(isFullScreenAudioPlayer && this.isAudioItem());
|
|
267
285
|
};
|
|
286
|
+
|
|
287
|
+
supportsNativeControls = (): boolean =>
|
|
288
|
+
toBooleanWithDefaultFalse(this.getConfig()?.["supports_native_controls"]);
|
|
289
|
+
|
|
290
|
+
supportNativeCast = (): boolean =>
|
|
291
|
+
toBooleanWithDefaultFalse(
|
|
292
|
+
this.playerPluginId === "quick-brick-player-brightcove"
|
|
293
|
+
);
|
|
268
294
|
}
|
|
@@ -4,6 +4,7 @@ import { useEffect } from "react";
|
|
|
4
4
|
import { playerManager } from "./index";
|
|
5
5
|
import { useValidatePlayerConfig } from "../../playerUtils/useValidatePlayerConfig";
|
|
6
6
|
import { PlayerRole } from "./conts";
|
|
7
|
+
import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/Platform";
|
|
7
8
|
|
|
8
9
|
// TODO: Rename to ControllerType
|
|
9
10
|
export const usePlayerControllerSetup = ({
|
|
@@ -34,10 +35,14 @@ export const usePlayerControllerSetup = ({
|
|
|
34
35
|
useValidatePlayerConfig(config);
|
|
35
36
|
|
|
36
37
|
useEffect(() => {
|
|
38
|
+
const newConfig = isAppleTV()
|
|
39
|
+
? { supports_native_controls: true, ...config }
|
|
40
|
+
: config;
|
|
41
|
+
|
|
37
42
|
const newPlayerController = new ControllerType({
|
|
38
43
|
player: ref,
|
|
39
44
|
listener: props as any,
|
|
40
|
-
config,
|
|
45
|
+
config: newConfig,
|
|
41
46
|
playerId,
|
|
42
47
|
entry,
|
|
43
48
|
playerPluginId: pluginId,
|
|
@@ -45,7 +50,7 @@ export const usePlayerControllerSetup = ({
|
|
|
45
50
|
});
|
|
46
51
|
|
|
47
52
|
setPlayerController(newPlayerController);
|
|
48
|
-
}, [playerId, entry?.id]);
|
|
53
|
+
}, [playerId, entry?.id, ref.current]);
|
|
49
54
|
|
|
50
55
|
React.useEffect(() => {
|
|
51
56
|
if (!playerController) {
|
|
@@ -67,6 +72,7 @@ export const usePlayerControllerSetup = ({
|
|
|
67
72
|
|
|
68
73
|
return () => {
|
|
69
74
|
playerManager.unregisterPlayer(playerId);
|
|
75
|
+
playerController.destroy?.();
|
|
70
76
|
};
|
|
71
77
|
}, [playerId, playerController]);
|
|
72
78
|
|
|
@@ -9,28 +9,35 @@ type PlayerState = {
|
|
|
9
9
|
isLive: boolean;
|
|
10
10
|
isPaused: boolean;
|
|
11
11
|
isBuffering: boolean;
|
|
12
|
+
isReadyToPlay: boolean;
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
export const usePlayerState = (
|
|
15
16
|
listenerId: string,
|
|
16
17
|
playerId?: string
|
|
17
18
|
): PlayerState => {
|
|
18
|
-
const [
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
const [state, setState] = React.useState<PlayerState>({
|
|
20
|
+
currentTime: null,
|
|
21
|
+
duration: null,
|
|
22
|
+
seekableDuration: null,
|
|
23
|
+
isLive: null,
|
|
24
|
+
isPaused: null,
|
|
25
|
+
isBuffering: false,
|
|
26
|
+
isReadyToPlay: false,
|
|
27
|
+
});
|
|
24
28
|
|
|
25
29
|
const player: Player = usePlayer(playerId);
|
|
26
30
|
|
|
27
31
|
const onPlayerChangeState = React.useCallback(() => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
setState({
|
|
33
|
+
currentTime: player.getContentPosition(),
|
|
34
|
+
duration: player.getDuration(),
|
|
35
|
+
seekableDuration: player.getSeekableDuration(),
|
|
36
|
+
isLive: player.isLive(),
|
|
37
|
+
isPaused: player.isPaused(),
|
|
38
|
+
isBuffering: player.isBuffering(),
|
|
39
|
+
isReadyToPlay: player.isReadyToPlay(),
|
|
40
|
+
});
|
|
34
41
|
}, [player]);
|
|
35
42
|
|
|
36
43
|
React.useEffect(() => {
|
|
@@ -52,15 +59,5 @@ export const usePlayerState = (
|
|
|
52
59
|
}
|
|
53
60
|
}, [player]);
|
|
54
61
|
|
|
55
|
-
return
|
|
56
|
-
() => ({
|
|
57
|
-
currentTime,
|
|
58
|
-
duration,
|
|
59
|
-
seekableDuration,
|
|
60
|
-
isLive,
|
|
61
|
-
isPaused,
|
|
62
|
-
isBuffering,
|
|
63
|
-
}),
|
|
64
|
-
[currentTime, duration, seekableDuration, isLive, isPaused, isBuffering]
|
|
65
|
-
);
|
|
62
|
+
return state;
|
|
66
63
|
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { OverlaysObserver } from "./OverlayObserver/OverlaysObserver";
|
|
3
|
+
import { useFeedLoader } from "../../reactHooks";
|
|
4
|
+
import { usePlayer } from "./usePlayer";
|
|
5
|
+
|
|
6
|
+
export const useTitleSummaryOverlay = (
|
|
7
|
+
feedUrl,
|
|
8
|
+
entry,
|
|
9
|
+
isLive = false,
|
|
10
|
+
interval: number
|
|
11
|
+
) => {
|
|
12
|
+
const player = usePlayer();
|
|
13
|
+
const [title, setTitle] = useState<string | number>(entry?.title || "");
|
|
14
|
+
const [summary, setSummary] = useState<string | number>(entry?.summary || "");
|
|
15
|
+
|
|
16
|
+
// Hook to load feed data
|
|
17
|
+
const { data: feedData, reloadData } = useFeedLoader({ feedUrl });
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (player && feedUrl && isLive) {
|
|
21
|
+
const observer = new OverlaysObserver({ player });
|
|
22
|
+
|
|
23
|
+
observer.setFeedDataHandlers(feedUrl, reloadData, interval, (entry) => {
|
|
24
|
+
setTitle(entry?.title || "");
|
|
25
|
+
setSummary(entry?.summary || "");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const subscription = observer
|
|
29
|
+
.getTitleSummaryObservable()
|
|
30
|
+
.subscribe(({ title, summary }) => {
|
|
31
|
+
setTitle(title);
|
|
32
|
+
setSummary(summary);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return () => {
|
|
36
|
+
subscription.unsubscribe();
|
|
37
|
+
observer.clearFeedDataInterval();
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}, [player, feedUrl, reloadData, isLive]);
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (isLive && feedData?.entry?.[0]) {
|
|
44
|
+
setTitle(feedData.entry[0].title || "");
|
|
45
|
+
setSummary(feedData.entry[0].summary || "");
|
|
46
|
+
}
|
|
47
|
+
}, [feedData]);
|
|
48
|
+
|
|
49
|
+
return { title, summary };
|
|
50
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { isFilledArray } from "..";
|
|
2
|
+
|
|
3
|
+
describe("isFilledArray", () => {
|
|
4
|
+
it("non-empty array is not empty", () => {
|
|
5
|
+
const value = [1, 2, 3];
|
|
6
|
+
|
|
7
|
+
expect(isFilledArray(value)).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("empty array is empty", () => {
|
|
11
|
+
const value = [];
|
|
12
|
+
|
|
13
|
+
expect(isFilledArray(value)).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("number is not array", () => {
|
|
17
|
+
const value = 123;
|
|
18
|
+
|
|
19
|
+
expect(isFilledArray(value)).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("string is not array", () => {
|
|
23
|
+
const value = "vfnjdk";
|
|
24
|
+
|
|
25
|
+
expect(isFilledArray(value)).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("empty string is not array", () => {
|
|
29
|
+
const value = "";
|
|
30
|
+
|
|
31
|
+
expect(isFilledArray(value)).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("NaN is not array", () => {
|
|
35
|
+
const value = "";
|
|
36
|
+
|
|
37
|
+
expect(isFilledArray(value)).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("object is not array", () => {
|
|
41
|
+
const value = { test: 1 };
|
|
42
|
+
|
|
43
|
+
expect(isFilledArray(value)).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("empty object is not array", () => {
|
|
47
|
+
const value = {};
|
|
48
|
+
|
|
49
|
+
expect(isFilledArray(value)).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("undefined is not array", () => {
|
|
53
|
+
const value = undefined;
|
|
54
|
+
|
|
55
|
+
expect(isFilledArray(value)).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("null is not array", () => {
|
|
59
|
+
const value = null;
|
|
60
|
+
|
|
61
|
+
expect(isFilledArray(value)).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
});
|
package/arrayUtils/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable unused-imports/no-unused-vars */
|
|
2
2
|
import * as R from "ramda";
|
|
3
|
+
import { invariant } from "@applicaster/zapp-react-native-utils/errorUtils";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* shifts an array by the given offset. a negative offset will take items
|
|
@@ -95,3 +96,18 @@ export const makeListOfIndexes = (size: number): number[] =>
|
|
|
95
96
|
export const makeListOf = (value: unknown, size: number): number[] => {
|
|
96
97
|
return Array(size).fill(value);
|
|
97
98
|
};
|
|
99
|
+
|
|
100
|
+
/** Checks if a value is a non-empty array */
|
|
101
|
+
export function isFilledArray(value: unknown): boolean {
|
|
102
|
+
return R.is(Array, value) && R.length(value) > 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// get random item from the list
|
|
106
|
+
export const sample = (xs: unknown[]): unknown => {
|
|
107
|
+
invariant(R.is(Array, xs), `input value is not a array: ${xs}`);
|
|
108
|
+
invariant(isFilledArray(xs), `input array is empty: ${xs}`);
|
|
109
|
+
|
|
110
|
+
const index = Math.floor(Math.random() * xs.length);
|
|
111
|
+
|
|
112
|
+
return xs[index];
|
|
113
|
+
};
|
package/booleanUtils/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { is, toLower } from "ramda";
|
|
2
2
|
|
|
3
3
|
export const toBoolean = (value: any): boolean | undefined => {
|
|
4
|
-
if (
|
|
4
|
+
if (is(Boolean, value)) {
|
|
5
5
|
return value;
|
|
6
6
|
}
|
|
7
7
|
|
|
@@ -17,12 +17,12 @@ export const toBooleanWithDefaultTrue = toBooleanWithDefault(true);
|
|
|
17
17
|
|
|
18
18
|
export const toBooleanWithDefaultFalse = toBooleanWithDefault(false);
|
|
19
19
|
|
|
20
|
-
export const isTrue = (value:
|
|
20
|
+
export const isTrue = (value: unknown): boolean => {
|
|
21
21
|
if (value === true) {
|
|
22
22
|
return true;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
if (
|
|
25
|
+
if (is(String, value) && toLower(value) === "true") {
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
castAndFallbackColor,
|
|
15
15
|
compact,
|
|
16
16
|
getValue,
|
|
17
|
+
getColorFromData,
|
|
17
18
|
} from "../";
|
|
18
19
|
|
|
19
20
|
import {
|
|
@@ -388,3 +389,50 @@ describe("getValue", () => {
|
|
|
388
389
|
expect(getValue({ value })(value)).toBeNull();
|
|
389
390
|
});
|
|
390
391
|
});
|
|
392
|
+
|
|
393
|
+
describe("getColorFromData", () => {
|
|
394
|
+
it("should return value directly if valid color", () => {
|
|
395
|
+
const result = getColorFromData({
|
|
396
|
+
data: entry,
|
|
397
|
+
valueFromLayout: "#123456",
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
expect(result).toBe("#123456");
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
it("should return valid rgba color name", () => {
|
|
404
|
+
const result = getColorFromData({
|
|
405
|
+
data: entry,
|
|
406
|
+
valueFromLayout: "rgba(255, 255, 255, 0)",
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
expect(result).toBe("rgba(255, 255, 255, 0)");
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it("should return path value if path value is set and is valid color", () => {
|
|
413
|
+
const result = getColorFromData({
|
|
414
|
+
data: entry,
|
|
415
|
+
valueFromLayout: "background_color",
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
expect(result).toBe("#123456");
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it("should return path value if path value is set, nested and is valid color", () => {
|
|
422
|
+
const result = getColorFromData({
|
|
423
|
+
data: entry,
|
|
424
|
+
valueFromLayout: "extensions.background_color",
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
expect(result).toBe("#123456");
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
it("should return valueFromLayout if path does not exist", () => {
|
|
431
|
+
const result = getColorFromData({
|
|
432
|
+
data: entry,
|
|
433
|
+
valueFromLayout: "invalid_color",
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
expect(result).toBe("invalid_color");
|
|
437
|
+
});
|
|
438
|
+
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/* eslint-disable max-len */
|
|
2
2
|
|
|
3
|
+
export const defaultColor = "#ffffff";
|
|
4
|
+
|
|
3
5
|
export const entry = {
|
|
4
6
|
type: {
|
|
5
7
|
value: "video",
|
|
@@ -26,7 +28,9 @@ export const entry = {
|
|
|
26
28
|
type: "video/mp4",
|
|
27
29
|
src: "https://wino-feed.s3.amazonaws.com/movieFeed/Ford+v+Ferrari.mp4",
|
|
28
30
|
},
|
|
31
|
+
background_color: "#123456",
|
|
29
32
|
extensions: {
|
|
33
|
+
background_color: "#123456",
|
|
30
34
|
free: false,
|
|
31
35
|
duration: 9000,
|
|
32
36
|
section: "New Releases",
|
|
@@ -46,7 +50,11 @@ export const componentStyle = {
|
|
|
46
50
|
horizontal_list_cell_width: "400",
|
|
47
51
|
cell_plugin_configuration_id: "267bd05a-08bd-4675-bdd3-9b73899773f0",
|
|
48
52
|
horizontal_list_scaled_switch: false,
|
|
53
|
+
background_color: "#123456",
|
|
49
54
|
component_background_color: "rgba(255, 255, 255, 0)",
|
|
55
|
+
background_color_1: "extensions.background_color",
|
|
56
|
+
background_color_2: "invalidColorKey",
|
|
57
|
+
background_color_3: "extensions.invalidColorKeyPath",
|
|
50
58
|
component_padding_left: "",
|
|
51
59
|
horizontal_list_next_offset: 20,
|
|
52
60
|
component_margin_bottom: "",
|
|
@@ -93,6 +101,11 @@ export const VAL = {
|
|
|
93
101
|
upper: "STRING",
|
|
94
102
|
width: 400,
|
|
95
103
|
height: 225,
|
|
104
|
+
colorKey: "background_color",
|
|
105
|
+
colorKeyRgba: "component_background_color",
|
|
106
|
+
colorKeyPath: "background_color_1",
|
|
107
|
+
invalidColorKey: "background_color_2",
|
|
108
|
+
invalidColorKeyPath: "background_color_3",
|
|
96
109
|
};
|
|
97
110
|
|
|
98
111
|
export const TRANSFORM = {
|
package/cellUtils/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
import dayjs from "dayjs";
|
|
3
|
+
import validateColor from "validate-color";
|
|
3
4
|
|
|
4
5
|
import { toNumberWithDefault, toNumberWithDefaultZero } from "../numberUtils";
|
|
5
6
|
import { transformColorCode as fixColorHexCode } from "../transform";
|
|
@@ -30,13 +31,12 @@ export const getKeyForLabel = (dataKey, customKey) => {
|
|
|
30
31
|
* This method will return true if the argument passed to it is either empty or nil
|
|
31
32
|
* The method prevents zero from being evaluated as falsey in an || condition
|
|
32
33
|
* i.e. - NaN, null, {}, "", [], should all return true
|
|
33
|
-
* @param {*} argument - argument passed to it could be any type
|
|
34
34
|
* @returns {Boolean} returns true if empty or nil
|
|
35
|
+
* @param value
|
|
35
36
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
37
|
+
|
|
38
|
+
export const isEmptyOrNil = (value: any): boolean =>
|
|
39
|
+
Number.isNaN(value) || value == null || R.isEmpty(value);
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* This method is used to find the appropriate label for any given text field.
|
|
@@ -181,8 +181,8 @@ export const getHeight = (width, aspectRatio) => {
|
|
|
181
181
|
* @returns {string} duration
|
|
182
182
|
*/
|
|
183
183
|
|
|
184
|
-
export const getDurationInMinutes = (seconds
|
|
185
|
-
if (seconds
|
|
184
|
+
export const getDurationInMinutes = (seconds?: number): string => {
|
|
185
|
+
if (!seconds) return "00:00";
|
|
186
186
|
const minutes = Math.floor(Number(seconds) / 60);
|
|
187
187
|
const secondsReminder = Math.floor(Number(seconds)) % 60;
|
|
188
188
|
const pad = (num: number): string => `${num < 10 ? "0" : ""}${num}`;
|
|
@@ -319,6 +319,7 @@ export const ifElseFocusedSelected = (
|
|
|
319
319
|
* @param {Object} stylesObj styles object with keys from zapp { button_icon_width: "10" }
|
|
320
320
|
* @returns {*} value, returns any type that can be used as styles
|
|
321
321
|
*/
|
|
322
|
+
|
|
322
323
|
export const getValue = (stylesObj) => (key) => {
|
|
323
324
|
return R.propOr(null, key, stylesObj);
|
|
324
325
|
};
|
|
@@ -343,6 +344,19 @@ export const ifElseFocused = R.curry(
|
|
|
343
344
|
state === "focused" ? focusedValue : defaultValue
|
|
344
345
|
);
|
|
345
346
|
|
|
347
|
+
export const ifElseSelected = R.curry(
|
|
348
|
+
(state: string, selectedValue, defaultValue) => {
|
|
349
|
+
switch (state) {
|
|
350
|
+
case "selected":
|
|
351
|
+
return selectedValue;
|
|
352
|
+
case "focused_selected":
|
|
353
|
+
return selectedValue;
|
|
354
|
+
default:
|
|
355
|
+
return defaultValue;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
);
|
|
359
|
+
|
|
346
360
|
/**
|
|
347
361
|
* Map textAlign values to their corresponding alignSelf values
|
|
348
362
|
* This is so that we could use the same field for both properties
|
|
@@ -430,3 +444,60 @@ export const toResizeMode = (
|
|
|
430
444
|
resizeMode: "contain",
|
|
431
445
|
};
|
|
432
446
|
};
|
|
447
|
+
|
|
448
|
+
type GetColorFromData = {
|
|
449
|
+
data: Record<string, any>;
|
|
450
|
+
valueFromLayout: string;
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
export const getColorFromData = ({
|
|
454
|
+
data,
|
|
455
|
+
valueFromLayout,
|
|
456
|
+
}: GetColorFromData): string => {
|
|
457
|
+
// Temporary hack to fix color validation when alpha is floating point number
|
|
458
|
+
// https://github.com/dreamyguy/validate-color/issues/44
|
|
459
|
+
if (validateColor(valueFromLayout.replace(".00", ""))) {
|
|
460
|
+
return valueFromLayout;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const pathValue = R.path(valueFromLayout.split("."), data);
|
|
464
|
+
|
|
465
|
+
if (pathValue && validateColor(pathValue)) {
|
|
466
|
+
return pathValue;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
return valueFromLayout;
|
|
470
|
+
};
|
|
471
|
+
|
|
472
|
+
export const getImageStyles = ({
|
|
473
|
+
image,
|
|
474
|
+
value,
|
|
475
|
+
}: {
|
|
476
|
+
image: any;
|
|
477
|
+
value: any;
|
|
478
|
+
}) => {
|
|
479
|
+
return {
|
|
480
|
+
width: image.imageContentWidth,
|
|
481
|
+
height: image.imageContentHeight,
|
|
482
|
+
aspectRatio: image.aspectRatio,
|
|
483
|
+
borderRadius: toNumberWithDefaultZero(value("image_corner_radius")),
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
export const getImageContainerPaddingStyles = ({ value }: { value: any }) => {
|
|
488
|
+
return {
|
|
489
|
+
paddingTop: value("image_padding_top"),
|
|
490
|
+
paddingBottom: value("image_padding_bottom"),
|
|
491
|
+
paddingLeft: value("image_padding_left"),
|
|
492
|
+
paddingRight: value("image_padding_right"),
|
|
493
|
+
};
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
export const getImageContainerMarginStyles = ({ value }: { value: any }) => {
|
|
497
|
+
return {
|
|
498
|
+
marginTop: value("image_margin_top"),
|
|
499
|
+
marginBottom: value("image_margin_bottom"),
|
|
500
|
+
marginLeft: value("image_margin_left"),
|
|
501
|
+
marginRight: value("image_margin_right"),
|
|
502
|
+
};
|
|
503
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import utc from "dayjs/plugin/utc";
|
|
3
|
+
import timezone from "dayjs/plugin/timezone";
|
|
4
|
+
import isoWeek from "dayjs/plugin/isoWeek";
|
|
5
|
+
|
|
6
|
+
// Extend dayjs with plugins
|
|
7
|
+
dayjs.extend(utc);
|
|
8
|
+
dayjs.extend(timezone);
|
|
9
|
+
dayjs.extend(isoWeek);
|
|
10
|
+
|
|
11
|
+
export { dayjs };
|
|
@@ -18,6 +18,7 @@ class FocusManager {
|
|
|
18
18
|
private static instance: FocusManager;
|
|
19
19
|
|
|
20
20
|
private _focusedId: string | null = null;
|
|
21
|
+
private _prevFocusedId: string | null = null;
|
|
21
22
|
public previousNavigationDirection: FocusManager.Android.NavDir = null;
|
|
22
23
|
|
|
23
24
|
/**
|
|
@@ -47,10 +48,22 @@ class FocusManager {
|
|
|
47
48
|
return focusedRef?.current;
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
get prevFocused() {
|
|
52
|
+
const focusedRef = this.prevFocusedId
|
|
53
|
+
? FocusManager.findFocusable(this.prevFocusedId)
|
|
54
|
+
: { current: null };
|
|
55
|
+
|
|
56
|
+
return focusedRef?.current;
|
|
57
|
+
}
|
|
58
|
+
|
|
50
59
|
get focusedId() {
|
|
51
60
|
return FocusManager.instance._focusedId;
|
|
52
61
|
}
|
|
53
62
|
|
|
63
|
+
get prevFocusedId() {
|
|
64
|
+
return FocusManager.instance._prevFocusedId;
|
|
65
|
+
}
|
|
66
|
+
|
|
54
67
|
public static getInstance(): FocusManager {
|
|
55
68
|
if (!FocusManager.instance) {
|
|
56
69
|
FocusManager.instance = new FocusManager();
|
|
@@ -151,9 +164,8 @@ class FocusManager {
|
|
|
151
164
|
}
|
|
152
165
|
|
|
153
166
|
private setFocusLocal(nextFocus: FocusManager.TouchableReactRef) {
|
|
167
|
+
FocusManager.instance._prevFocusedId = FocusManager.instance._focusedId;
|
|
154
168
|
FocusManager.instance._focusedId = nextFocus?.current?.props?.id ?? null;
|
|
155
|
-
|
|
156
|
-
this.eventHandler?.invokeHandler?.(FOCUS_EVENTS.FOCUS, nextFocus);
|
|
157
169
|
}
|
|
158
170
|
|
|
159
171
|
private setPreviousNavigationDirection(
|
|
@@ -217,8 +229,11 @@ class FocusManager {
|
|
|
217
229
|
|
|
218
230
|
FocusManager.instance.setFocus(nextNextFocus, options);
|
|
219
231
|
} else {
|
|
220
|
-
FocusManager.instance.blurPrevious(options);
|
|
221
232
|
FocusManager.instance.setFocusLocal(nextFocus);
|
|
233
|
+
|
|
234
|
+
FocusManager.instance.blurPrevious(options);
|
|
235
|
+
this.eventHandler?.invokeHandler?.(FOCUS_EVENTS.FOCUS, nextFocus);
|
|
236
|
+
|
|
222
237
|
FocusManager.instance.setPreviousNavigationDirection(options ?? null);
|
|
223
238
|
|
|
224
239
|
nextFocus?.current?.onFocus?.(nextFocus.current, options ?? {});
|
|
@@ -227,8 +242,8 @@ class FocusManager {
|
|
|
227
242
|
|
|
228
243
|
blurPrevious(options?: FocusManager.Android.CallbackOptions) {
|
|
229
244
|
if (options) {
|
|
230
|
-
FocusManager.instance.
|
|
231
|
-
FocusManager.instance.
|
|
245
|
+
FocusManager.instance.prevFocused?.onBlur?.(
|
|
246
|
+
FocusManager.instance.prevFocused,
|
|
232
247
|
options
|
|
233
248
|
);
|
|
234
249
|
}
|
|
@@ -156,7 +156,6 @@ describe("FocusManager", () => {
|
|
|
156
156
|
child1.current.onBlur.mockClear();
|
|
157
157
|
focusManager.setFocus(child1.current.props.id);
|
|
158
158
|
focusManager.blurPrevious({ direction: "down" });
|
|
159
|
-
expect(child1.current.onBlur).toBeCalled();
|
|
160
159
|
});
|
|
161
160
|
|
|
162
161
|
it("focusManager - focus shouldn't change if nextFocus has blockFocus", () => {
|
package/focusManager/index.ts
CHANGED
|
@@ -86,7 +86,7 @@ export const isFocusable = (component: ZappEntry | ZappUIComponent | any) =>
|
|
|
86
86
|
|
|
87
87
|
type Props = {
|
|
88
88
|
component: ZappUIComponent;
|
|
89
|
-
zappPipesData
|
|
89
|
+
zappPipesData?: ZappPipesData;
|
|
90
90
|
} & Record<string, any>;
|
|
91
91
|
|
|
92
92
|
export const useIsFocusable = (props: Props): void => {
|