@applicaster/zapp-react-native-ui-components 15.0.0-rc.23 → 15.0.0-rc.25

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.
@@ -6,10 +6,6 @@ import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
6
6
 
7
7
  type AnimatedInterpolatedStyle = any;
8
8
 
9
- // type AnimatedInterpolatedStyle =
10
- // | Animated.AnimatedInterpolation
11
- // | [{ [Key: string]: Animated.AnimatedInterpolation }];
12
-
13
9
  type AnimationConfig = {
14
10
  duration: number;
15
11
  easing: EasingFunction;
@@ -45,32 +41,57 @@ export function AnimatedInOut({
45
41
  children,
46
42
  }: Props) {
47
43
  const [animatedValue] = React.useState(new Animated.Value(visible ? 1 : 0));
48
- const [animating, setAnimating] = React.useState(undefined);
44
+ const animationRef = React.useRef<Animated.CompositeAnimation | null>(null);
45
+ const delayTimerRef = React.useRef<NodeJS.Timeout | null>(null);
49
46
 
50
47
  const previousVisible = usePrevious(toBooleanWithDefaultFalse(visible));
51
48
 
52
- function startAnimation(toValue, config) {
53
- if (animating) {
54
- animating.reset();
55
- }
56
-
57
- const { duration, easing, delay = 0, onAnimationEnd = noop } = config;
49
+ const startAnimation = React.useCallback(
50
+ (toValue: number, config: AnimationConfig) => {
51
+ if (delayTimerRef.current) {
52
+ clearTimeout(delayTimerRef.current);
53
+ delayTimerRef.current = null;
54
+ }
55
+
56
+ if (animationRef.current) {
57
+ animationRef.current.stop();
58
+ animationRef.current = null;
59
+ }
60
+
61
+ const { duration, easing, delay = 0, onAnimationEnd = noop } = config;
62
+
63
+ const runAnimation = () => {
64
+ animationRef.current = Animated.timing(animatedValue, {
65
+ duration,
66
+ toValue,
67
+ easing,
68
+ useNativeDriver: true,
69
+ });
70
+
71
+ animationRef.current.start(({ finished }) => {
72
+ if (finished) {
73
+ animationRef.current = null;
74
+ onAnimationEnd();
75
+ }
76
+ });
77
+ };
78
+
79
+ if (delay > 0) {
80
+ delayTimerRef.current = setTimeout(runAnimation, delay);
81
+ } else {
82
+ runAnimation();
83
+ }
84
+ },
85
+ [animatedValue]
86
+ );
58
87
 
59
- const compositeAnimation = Animated.timing(animatedValue, {
60
- duration,
61
- toValue,
62
- easing,
63
- delay,
64
- useNativeDriver: true,
65
- }).start(() => {
66
- setAnimating(undefined);
67
- onAnimationEnd();
68
- });
88
+ React.useEffect(() => {
89
+ if (previousVisible === undefined) {
90
+ animatedValue.setValue(visible ? 1 : 0);
69
91
 
70
- setAnimating(compositeAnimation);
71
- }
92
+ return;
93
+ }
72
94
 
73
- React.useEffect(() => {
74
95
  if (!previousVisible && visible) {
75
96
  startAnimation(1.0, getAnimation(animationConfig, "in"));
76
97
  }
@@ -78,7 +99,29 @@ export function AnimatedInOut({
78
99
  if (previousVisible && !visible) {
79
100
  startAnimation(0.0, getAnimation(animationConfig, "out"));
80
101
  }
81
- }, [visible, previousVisible]);
102
+ }, [
103
+ visible,
104
+ previousVisible,
105
+ animatedValue,
106
+ startAnimation,
107
+ animationConfig,
108
+ ]);
109
+
110
+ React.useEffect(() => {
111
+ return () => {
112
+ if (delayTimerRef.current) {
113
+ clearTimeout(delayTimerRef.current);
114
+ delayTimerRef.current = null;
115
+ }
116
+
117
+ if (animationRef.current) {
118
+ animationRef.current.stop();
119
+ animationRef.current = null;
120
+ }
121
+
122
+ animatedValue.stopAnimation();
123
+ };
124
+ }, [animatedValue]);
82
125
 
83
126
  const styles = visible
84
127
  ? getAnimation(animationConfig, "in").styles
@@ -86,7 +129,7 @@ export function AnimatedInOut({
86
129
 
87
130
  return (
88
131
  <Animated.View
89
- renderToHardwareTextureAndroid={animating}
132
+ renderToHardwareTextureAndroid={!!animationRef.current}
90
133
  style={[styles(animatedValue), staticStyles]}
91
134
  >
92
135
  {children}
@@ -1,9 +1,4 @@
1
1
  import * as React from "react";
2
- import * as R from "ramda";
3
- import {
4
- findPluginByType,
5
- findPluginByIdentifier,
6
- } from "@applicaster/zapp-react-native-utils/pluginUtils";
7
2
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
8
3
  import {
9
4
  useDimensions,
@@ -16,6 +11,7 @@ import { PlayerContainer } from "../PlayerContainer";
16
11
  import { useModalSize } from "../VideoModal/hooks";
17
12
  import { ViewStyle } from "react-native";
18
13
  import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
14
+ import { findCastPlugin, getPlayer } from "./utils";
19
15
 
20
16
  type Props = {
21
17
  item: ZappEntry;
@@ -26,62 +22,6 @@ type Props = {
26
22
  groupId?: string;
27
23
  };
28
24
 
29
- const YOUTUBE_PLUGIN_ID = "youtube-player-qb";
30
- const CHROMECAST_PLUGIN_ID = "chromecast_qb";
31
-
32
- const getPlayerWithModuleProperties = (
33
- PlayerModule: ZappPlugin
34
- ): [ZappPlugin, PlayerModuleProperties] => {
35
- const getPlayerModuleProperties = R.ifElse(
36
- R.is(Object) && R.has("Component"),
37
- R.omit(["Component"]),
38
- () => ({})
39
- );
40
-
41
- return [
42
- PlayerModule?.Component || PlayerModule,
43
- getPlayerModuleProperties(PlayerModule),
44
- ];
45
- };
46
-
47
- const getPlayer = (
48
- item: ZappEntry,
49
- state
50
- ): [ZappPlugin, PlayerModuleProperties] => {
51
- const {
52
- plugins,
53
- contentTypes,
54
- rivers,
55
- appData: { layoutVersion },
56
- } = state;
57
-
58
- let PlayerModule;
59
-
60
- if (layoutVersion === "v2") {
61
- const { screen_id } = contentTypes?.[item?.type?.value] || {};
62
- const { type } = rivers?.[screen_id] || {};
63
-
64
- if (type) {
65
- PlayerModule = findPluginByIdentifier(type, plugins)?.module;
66
-
67
- return getPlayerWithModuleProperties(PlayerModule);
68
- }
69
- }
70
-
71
- if (item?.content?.type === "youtube-id") {
72
- PlayerModule = findPluginByIdentifier(YOUTUBE_PLUGIN_ID, plugins)?.module;
73
-
74
- return getPlayerWithModuleProperties(PlayerModule);
75
- }
76
-
77
- PlayerModule = findPluginByType(
78
- "playable",
79
- plugins.filter(({ identifier }) => identifier !== YOUTUBE_PLUGIN_ID)
80
- );
81
-
82
- return getPlayerWithModuleProperties(PlayerModule);
83
- };
84
-
85
25
  type PlayableComponent = {
86
26
  Component: React.ComponentType<any>;
87
27
  };
@@ -99,14 +39,23 @@ export function HandlePlayable({
99
39
  mode,
100
40
  groupId,
101
41
  }: Props): React.ReactElement | null {
102
- const state = usePickFromState();
42
+ const { plugins, contentTypes, rivers, appData } = usePickFromState([
43
+ "plugins",
44
+ "contentTypes",
45
+ "rivers",
46
+ "appData",
47
+ ]);
103
48
 
104
49
  const { closeVideoModal } = useNavigation();
105
50
 
106
- const [Player, playerModuleProperties] = getPlayer(item, state);
51
+ const [Player, playerModuleProperties] = getPlayer(item, {
52
+ plugins,
53
+ contentTypes,
54
+ rivers,
55
+ appData,
56
+ });
107
57
 
108
- const { module: CastPlugin } =
109
- findPluginByIdentifier(CHROMECAST_PLUGIN_ID, state.plugins, true) || {};
58
+ const { module: CastPlugin } = findCastPlugin(plugins);
110
59
 
111
60
  const [playable, setPlayable] =
112
61
  React.useState<Nullable<PlayableComponent>>(null);
@@ -0,0 +1,3 @@
1
+ export const YOUTUBE_PLUGIN_ID = "youtube-player-qb";
2
+
3
+ export const CHROMECAST_PLUGIN_ID = "chromecast_qb";
@@ -0,0 +1,74 @@
1
+ import {
2
+ findPluginByIdentifier,
3
+ findPluginByType,
4
+ } from "@applicaster/zapp-react-native-utils/pluginUtils";
5
+
6
+ import { CHROMECAST_PLUGIN_ID, YOUTUBE_PLUGIN_ID } from "./const";
7
+ import { omit } from "@applicaster/zapp-react-native-utils/utils";
8
+
9
+ const getPlayerModuleProperties = (PlayerModule: ZappPlugin) => {
10
+ if (PlayerModule?.Component && typeof PlayerModule.Component === "object") {
11
+ return omit(["Component"], PlayerModule);
12
+ }
13
+
14
+ return {};
15
+ };
16
+
17
+ export const getPlayerWithModuleProperties = (
18
+ PlayerModule: ZappPlugin
19
+ ): [ZappPlugin, PlayerModuleProperties] => {
20
+ return [
21
+ PlayerModule?.Component || PlayerModule,
22
+ getPlayerModuleProperties(PlayerModule),
23
+ ];
24
+ };
25
+
26
+ export const findCastPlugin = (plugins: ZappPlugin[]) =>
27
+ findPluginByIdentifier(CHROMECAST_PLUGIN_ID, plugins, true) || {};
28
+
29
+ export const findYoutubePlugin = (plugins: ZappPlugin[]) =>
30
+ findPluginByIdentifier(YOUTUBE_PLUGIN_ID, plugins, true) || {};
31
+
32
+ export const getPlayer = (
33
+ item: ZappEntry,
34
+ {
35
+ plugins,
36
+ contentTypes,
37
+ rivers,
38
+ appData: { layoutVersion },
39
+ }: {
40
+ plugins: ZappPlugin[];
41
+ contentTypes: Record<string, any>;
42
+ rivers: Record<string, any>;
43
+ appData: { layoutVersion: string };
44
+ }
45
+ ): [ZappPlugin, PlayerModuleProperties] => {
46
+ let PlayerModule;
47
+
48
+ if (layoutVersion === "v2") {
49
+ const screen_id = contentTypes?.[item?.type?.value]?.screen_id;
50
+ const type = rivers?.[screen_id]?.type;
51
+
52
+ if (type) {
53
+ PlayerModule = findPluginByIdentifier(type, plugins)?.module;
54
+
55
+ return getPlayerWithModuleProperties(PlayerModule);
56
+ }
57
+ }
58
+
59
+ if (item?.content?.type === "youtube-id") {
60
+ PlayerModule = findYoutubePlugin(plugins)?.module;
61
+
62
+ return getPlayerWithModuleProperties(PlayerModule);
63
+ }
64
+
65
+ PlayerModule = findPluginByType(
66
+ "playable",
67
+ (plugins as any[]).filter(
68
+ ({ identifier }: { identifier: string }) =>
69
+ identifier !== YOUTUBE_PLUGIN_ID
70
+ )
71
+ );
72
+
73
+ return getPlayerWithModuleProperties(PlayerModule);
74
+ };
@@ -9,6 +9,7 @@ exports[`PlayerLiveImageComponent should render correctly with default props 1`]
9
9
  <View>
10
10
  <View
11
11
  collapsable={false}
12
+ renderToHardwareTextureAndroid={false}
12
13
  style={
13
14
  {
14
15
  "opacity": 1,
@@ -1,30 +1,19 @@
1
1
  import * as React from "react";
2
- import {
3
- Dimensions,
4
- Platform,
5
- StyleSheet,
6
- View,
7
- ViewStyle,
8
- } from "react-native";
2
+ import { StyleSheet, View, ViewStyle } from "react-native";
9
3
  import { Edge, SafeAreaView } from "react-native-safe-area-context";
10
4
  import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
11
5
  import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
12
6
  import { playerDimensionsHack } from "./utils";
13
7
  import { getTabletWidth } from "@applicaster/zapp-react-native-utils/playerUtils";
14
-
15
- const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("screen");
16
-
17
- type DimensionsT = {
18
- width: number | string;
19
- height: number | string | undefined;
20
- aspectRatio?: number;
21
- };
22
-
23
- type Configuration = {
24
- [key: string]: any;
25
- tablet_landscape_sidebar_width?: string;
26
- tablet_landscape_player_container_background_color?: string;
27
- };
8
+ import {
9
+ DimensionsT,
10
+ Configuration,
11
+ getEdges,
12
+ getBaseDimensions,
13
+ calculateAspectRatio,
14
+ getPlayerDimensions,
15
+ getContainerDimensions,
16
+ } from "./playerWrapperUtils";
28
17
 
29
18
  type Props = {
30
19
  entry: ZappEntry;
@@ -45,32 +34,12 @@ const defaultStyles = StyleSheet.create({
45
34
  playerContainer: { position: "relative", alignSelf: "center", zIndex: 200 },
46
35
  });
47
36
 
48
- const getScreenAspectRatio = () => {
49
- const longEdge = Math.max(SCREEN_WIDTH, SCREEN_HEIGHT);
50
- const shortEdge = Math.min(SCREEN_WIDTH, SCREEN_HEIGHT);
51
-
52
- return longEdge / shortEdge;
53
- };
54
-
55
- const getEdges = (isTablet: boolean, isInlineModal: boolean) => {
56
- if (isTablet) {
57
- return ["top"];
58
- }
59
-
60
- if (!isInlineModal && Platform.OS === "android") {
61
- return [];
62
- }
63
-
64
- return ["top"];
65
- };
66
-
67
37
  const PlayerWrapperComponent = (props: Props) => {
68
38
  const {
69
39
  entry,
70
40
  style,
71
41
  containerStyle,
72
42
  inline,
73
- docked,
74
43
  isModal,
75
44
  isTabletPortrait,
76
45
  configuration,
@@ -90,28 +59,23 @@ const PlayerWrapperComponent = (props: Props) => {
90
59
  );
91
60
 
92
61
  const baseDimensions: DimensionsT = React.useMemo(
93
- () => ({
94
- width: isInlineModal && isTabletLandscape ? tabletWidth : "100%",
95
- height: undefined,
96
- }),
97
- [isInlineModal, tabletWidth, docked]
62
+ () => getBaseDimensions(isInlineModal, isTabletLandscape, tabletWidth),
63
+ [isInlineModal, isTabletLandscape, tabletWidth]
98
64
  );
99
65
 
100
- const playerDimensions: DimensionsT = React.useMemo(
101
- () => ({
102
- ...baseDimensions,
103
- width: baseDimensions.width,
104
- aspectRatio: !isInlineModal && !pip ? getScreenAspectRatio() : 16 / 9,
105
- }),
106
- [baseDimensions, isInlineModal, pip]
66
+ const aspectRatio = React.useMemo(
67
+ () => calculateAspectRatio(isInlineModal, pip),
68
+ [isInlineModal, pip]
69
+ );
70
+
71
+ const playerDimensions = React.useMemo(
72
+ () => getPlayerDimensions(baseDimensions, aspectRatio),
73
+ [baseDimensions, aspectRatio]
107
74
  );
108
75
 
109
76
  const containerDimensions: DimensionsT = React.useMemo(
110
- () => ({
111
- ...baseDimensions,
112
- aspectRatio: playerDimensions.aspectRatio,
113
- }),
114
- [baseDimensions, isInlineModal, docked, playerDimensions.aspectRatio]
77
+ () => getContainerDimensions(baseDimensions, playerDimensions.aspectRatio),
78
+ [baseDimensions, playerDimensions.aspectRatio]
115
79
  );
116
80
 
117
81
  const WrapperView = React.useMemo(() => (isTV() ? View : SafeAreaView), []);
@@ -121,7 +85,7 @@ const PlayerWrapperComponent = (props: Props) => {
121
85
  ...playerDimensions,
122
86
  ...playerDimensionsHack,
123
87
  }),
124
- [containerDimensions, playerDimensionsHack]
88
+ [playerDimensions]
125
89
  );
126
90
 
127
91
  return (
@@ -42,7 +42,7 @@ export const useModalSize = (): Size => {
42
42
  const [modalSize, setModalSize] = React.useState<Size>({
43
43
  width: frame.width,
44
44
  height: isOldAndroidDevice
45
- ? frame.height + StatusBar.currentHeight
45
+ ? frame.height + (StatusBar.currentHeight ?? 0)
46
46
  : frame.height,
47
47
  });
48
48
 
@@ -57,9 +57,10 @@ export const useModalSize = (): Size => {
57
57
 
58
58
  return {
59
59
  width: newSize.width,
60
- height: isOldAndroidDevice
61
- ? newSize.height + StatusBar.currentHeight
62
- : newSize.height,
60
+ height:
61
+ isOldAndroidDevice && newSize.height !== "100%"
62
+ ? newSize.height + (StatusBar.currentHeight ?? 0)
63
+ : newSize.height,
63
64
  };
64
65
  });
65
66
 
@@ -0,0 +1,87 @@
1
+ import { Dimensions, Platform } from "react-native";
2
+ import { Edge } from "react-native-safe-area-context";
3
+
4
+ export type DimensionsT = {
5
+ width: number | string;
6
+ height: number | string | undefined;
7
+ aspectRatio?: number;
8
+ };
9
+
10
+ export type Configuration = {
11
+ [key: string]: any;
12
+ tablet_landscape_sidebar_width?: string;
13
+ tablet_landscape_player_container_background_color?: string;
14
+ };
15
+
16
+ export const getWindowDimensions = () => {
17
+ const { width, height } = Dimensions.get("window");
18
+
19
+ return { width, height };
20
+ };
21
+
22
+ export const getMaxWindowDimension = () => {
23
+ const { width, height } = getWindowDimensions();
24
+
25
+ return Math.max(width, height);
26
+ };
27
+
28
+ export const getMinWindowDimension = () => {
29
+ const { width, height } = getWindowDimensions();
30
+
31
+ return Math.min(width, height);
32
+ };
33
+
34
+ export const getScreenAspectRatio = () => {
35
+ const longEdge = getMaxWindowDimension();
36
+ const shortEdge = getMinWindowDimension();
37
+
38
+ return longEdge / shortEdge;
39
+ };
40
+
41
+ export const getEdges = (
42
+ isTablet: boolean,
43
+ isInlineModal: boolean
44
+ ): readonly Edge[] => {
45
+ if (isTablet) {
46
+ return ["top"];
47
+ }
48
+
49
+ if (!isInlineModal && Platform.OS === "android") {
50
+ return [];
51
+ }
52
+
53
+ return ["top"];
54
+ };
55
+
56
+ export const getBaseDimensions = (
57
+ isInlineModal: boolean,
58
+ isTabletLandscape: boolean,
59
+ tabletWidth: number | string
60
+ ): DimensionsT => ({
61
+ width: isInlineModal && isTabletLandscape ? tabletWidth : "100%",
62
+ height: undefined,
63
+ });
64
+
65
+ export const calculateAspectRatio = (
66
+ isInlineModal: boolean,
67
+ pip?: boolean
68
+ ): number => {
69
+ return !isInlineModal && !pip ? getScreenAspectRatio() : 16 / 9;
70
+ };
71
+
72
+ export const getPlayerDimensions = (
73
+ baseDimensions: DimensionsT,
74
+ aspectRatio: number
75
+ ): DimensionsT => ({
76
+ ...baseDimensions,
77
+ width: baseDimensions.width,
78
+ aspectRatio,
79
+ });
80
+
81
+ export const getContainerDimensions = (
82
+ baseDimensions: DimensionsT,
83
+ playerAspectRatio?: number
84
+ ): DimensionsT => ({
85
+ ...baseDimensions,
86
+ aspectRatio: playerAspectRatio,
87
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "15.0.0-rc.23",
3
+ "version": "15.0.0-rc.25",
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": "15.0.0-rc.23",
32
- "@applicaster/zapp-react-native-bridge": "15.0.0-rc.23",
33
- "@applicaster/zapp-react-native-redux": "15.0.0-rc.23",
34
- "@applicaster/zapp-react-native-utils": "15.0.0-rc.23",
31
+ "@applicaster/applicaster-types": "15.0.0-rc.25",
32
+ "@applicaster/zapp-react-native-bridge": "15.0.0-rc.25",
33
+ "@applicaster/zapp-react-native-redux": "15.0.0-rc.25",
34
+ "@applicaster/zapp-react-native-utils": "15.0.0-rc.25",
35
35
  "promise": "^8.3.0",
36
36
  "url": "^0.11.0",
37
37
  "uuid": "^3.3.2"