@applicaster/zapp-react-native-ui-components 15.0.0-rc.26 → 15.0.0-rc.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,11 @@
1
1
  import * as React from "react";
2
- import { StyleSheet, View, ViewStyle } from "react-native";
2
+ import { View, ViewStyle } from "react-native";
3
3
  import { Edge, SafeAreaView } from "react-native-safe-area-context";
4
4
  import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
5
5
  import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
6
6
  import { playerDimensionsHack } from "./utils";
7
- import { getTabletWidth } from "@applicaster/zapp-react-native-utils/playerUtils";
8
- import {
9
- DimensionsT,
10
- Configuration,
11
- getEdges,
12
- getBaseDimensions,
13
- calculateAspectRatio,
14
- getPlayerDimensions,
15
- getContainerDimensions,
16
- } from "./playerWrapperUtils";
7
+ import { DimensionsT, Configuration, getEdges } from "./playerWrapperUtils";
8
+ import { defaultStyles, useStyle } from "./playerWrapperStyle";
17
9
 
18
10
  type Props = {
19
11
  entry: ZappEntry;
@@ -30,10 +22,6 @@ type Props = {
30
22
  playerContent: (styles: ViewStyle) => React.ReactNode;
31
23
  };
32
24
 
33
- const defaultStyles = StyleSheet.create({
34
- playerContainer: { position: "relative", alignSelf: "center", zIndex: 200 },
35
- });
36
-
37
25
  const PlayerWrapperComponent = (props: Props) => {
38
26
  const {
39
27
  entry,
@@ -47,47 +35,21 @@ const PlayerWrapperComponent = (props: Props) => {
47
35
  playerContent,
48
36
  } = props;
49
37
 
38
+ const styles = useStyle({
39
+ style,
40
+ inline,
41
+ isModal,
42
+ isTabletPortrait,
43
+ configuration,
44
+ pip,
45
+ });
46
+
50
47
  const isTablet = useIsTablet();
51
48
 
52
49
  const isInlineModal = inline && isModal;
53
50
 
54
- const isTabletLandscape = !isTV() && isTablet && !isTabletPortrait;
55
-
56
- const tabletWidth = getTabletWidth(
57
- configuration.tablet_landscape_sidebar_width,
58
- style
59
- );
60
-
61
- const baseDimensions: DimensionsT = React.useMemo(
62
- () => getBaseDimensions(isInlineModal, isTabletLandscape, tabletWidth),
63
- [isInlineModal, isTabletLandscape, tabletWidth]
64
- );
65
-
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]
74
- );
75
-
76
- const containerDimensions: DimensionsT = React.useMemo(
77
- () => getContainerDimensions(baseDimensions, playerDimensions.aspectRatio),
78
- [baseDimensions, playerDimensions.aspectRatio]
79
- );
80
-
81
51
  const WrapperView = React.useMemo(() => (isTV() ? View : SafeAreaView), []);
82
52
 
83
- const childrenStyles = React.useMemo(
84
- () => ({
85
- ...playerDimensions,
86
- ...playerDimensionsHack,
87
- }),
88
- [playerDimensions]
89
- );
90
-
91
53
  return (
92
54
  <WrapperView
93
55
  edges={getEdges(isTablet, isInlineModal) as readonly Edge[]}
@@ -98,11 +60,11 @@ const PlayerWrapperComponent = (props: Props) => {
98
60
  style={[
99
61
  defaultStyles.playerContainer,
100
62
  playerDimensionsHack,
101
- containerDimensions,
63
+ styles.containerDimensions,
102
64
  containerStyle,
103
65
  ]}
104
66
  >
105
- {playerContent(childrenStyles)}
67
+ {playerContent(styles.childrenStyles)}
106
68
  </View>
107
69
  </WrapperView>
108
70
  );
@@ -46,6 +46,7 @@ jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
46
46
 
47
47
  jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
48
48
  isTV: jest.fn(() => false),
49
+ isAndroidPlatform: jest.fn(() => false),
49
50
  isApplePlatform: jest.fn(() => true),
50
51
  platformSelect: jest.fn((props) => props.android),
51
52
  }));
@@ -33,8 +33,12 @@ const MODAL_SIZE_FOR_LANDSCAPE: Size = {
33
33
  height: "100%",
34
34
  };
35
35
 
36
+ const SAFE_AREA_BREAKING_API_VERSION = 35;
37
+
36
38
  const isOldAndroidDevice =
37
- isAndroidPlatform() && !isAndroidVersionAtLeast(35) && !isAndroidTablet();
39
+ isAndroidPlatform() &&
40
+ !isAndroidVersionAtLeast(SAFE_AREA_BREAKING_API_VERSION) &&
41
+ !isAndroidTablet();
38
42
 
39
43
  export const useModalSize = (): Size => {
40
44
  const frame = useSafeAreaFrame();
@@ -0,0 +1,70 @@
1
+ import * as React from "react";
2
+ import { StyleSheet, ViewStyle } from "react-native";
3
+ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
4
+ import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
5
+ import { playerDimensionsHack } from "./utils";
6
+ import { getTabletWidth } from "@applicaster/zapp-react-native-utils/playerUtils";
7
+ import {
8
+ getBaseDimensions,
9
+ calculateAspectRatio,
10
+ getPlayerDimensions,
11
+ getContainerDimensions,
12
+ } from "./playerWrapperUtils";
13
+
14
+ export const defaultStyles = StyleSheet.create({
15
+ playerContainer: { position: "relative", alignSelf: "center", zIndex: 200 },
16
+ });
17
+
18
+ export const useStyle = ({
19
+ style,
20
+ inline,
21
+ isModal,
22
+ isTabletPortrait,
23
+ configuration,
24
+ pip,
25
+ }) => {
26
+ const isTablet = useIsTablet();
27
+
28
+ const isInlineModal = inline && isModal;
29
+
30
+ const isTabletLandscape = !isTV() && isTablet && !isTabletPortrait;
31
+
32
+ const tabletWidth = getTabletWidth(
33
+ configuration.tablet_landscape_sidebar_width,
34
+ style
35
+ );
36
+
37
+ const baseDimensions: ViewStyle = React.useMemo(
38
+ () => getBaseDimensions(isInlineModal, isTabletLandscape, tabletWidth),
39
+ [isInlineModal, isTabletLandscape, tabletWidth]
40
+ );
41
+
42
+ const aspectRatio = React.useMemo(
43
+ () => calculateAspectRatio(isInlineModal, pip),
44
+ // ignoring insets - only initial needed
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ [isInlineModal, pip]
47
+ );
48
+
49
+ return React.useMemo(() => {
50
+ const playerDimensions: ViewStyle = getPlayerDimensions(
51
+ baseDimensions,
52
+ aspectRatio
53
+ );
54
+
55
+ const containerDimensions: ViewStyle = getContainerDimensions(
56
+ baseDimensions,
57
+ aspectRatio
58
+ );
59
+
60
+ const childrenStyles = {
61
+ ...playerDimensions,
62
+ ...playerDimensionsHack,
63
+ };
64
+
65
+ return StyleSheet.create({
66
+ containerDimensions,
67
+ childrenStyles,
68
+ });
69
+ }, [baseDimensions, aspectRatio]);
70
+ };
@@ -1,4 +1,4 @@
1
- import { Dimensions, Platform } from "react-native";
1
+ import { Dimensions, DimensionValue, Platform, ViewStyle } from "react-native";
2
2
  import { Edge } from "react-native-safe-area-context";
3
3
 
4
4
  export type DimensionsT = {
@@ -13,6 +13,10 @@ export type Configuration = {
13
13
  tablet_landscape_player_container_background_color?: string;
14
14
  };
15
15
 
16
+ // This is safe, remembering screen dimensions once as they do not change during runtime
17
+ // TODO: consider sharing screen orientation as a shared function for the app
18
+ const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("screen");
19
+
16
20
  export const getWindowDimensions = () => {
17
21
  const { width, height } = Dimensions.get("window");
18
22
 
@@ -32,8 +36,8 @@ export const getMinWindowDimension = () => {
32
36
  };
33
37
 
34
38
  export const getScreenAspectRatio = () => {
35
- const longEdge = getMaxWindowDimension();
36
- const shortEdge = getMinWindowDimension();
39
+ const longEdge = Math.max(SCREEN_WIDTH, SCREEN_HEIGHT);
40
+ const shortEdge = Math.min(SCREEN_WIDTH, SCREEN_HEIGHT);
37
41
 
38
42
  return longEdge / shortEdge;
39
43
  };
@@ -56,8 +60,8 @@ export const getEdges = (
56
60
  export const getBaseDimensions = (
57
61
  isInlineModal: boolean,
58
62
  isTabletLandscape: boolean,
59
- tabletWidth: number | string
60
- ): DimensionsT => ({
63
+ tabletWidth: DimensionValue
64
+ ): ViewStyle => ({
61
65
  width: isInlineModal && isTabletLandscape ? tabletWidth : "100%",
62
66
  height: undefined,
63
67
  });
@@ -70,18 +74,18 @@ export const calculateAspectRatio = (
70
74
  };
71
75
 
72
76
  export const getPlayerDimensions = (
73
- baseDimensions: DimensionsT,
77
+ baseDimensions: ViewStyle,
74
78
  aspectRatio: number
75
- ): DimensionsT => ({
76
- ...baseDimensions,
79
+ ): ViewStyle => ({
80
+ ...(baseDimensions as any),
77
81
  width: baseDimensions.width,
78
82
  aspectRatio,
79
83
  });
80
84
 
81
85
  export const getContainerDimensions = (
82
- baseDimensions: DimensionsT,
83
- playerAspectRatio?: number
84
- ): DimensionsT => ({
86
+ baseDimensions: ViewStyle,
87
+ aspectRatio?: string | number
88
+ ): ViewStyle => ({
85
89
  ...baseDimensions,
86
- aspectRatio: playerAspectRatio,
90
+ aspectRatio,
87
91
  });
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.26",
3
+ "version": "15.0.0-rc.28",
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.26",
32
- "@applicaster/zapp-react-native-bridge": "15.0.0-rc.26",
33
- "@applicaster/zapp-react-native-redux": "15.0.0-rc.26",
34
- "@applicaster/zapp-react-native-utils": "15.0.0-rc.26",
31
+ "@applicaster/applicaster-types": "15.0.0-rc.28",
32
+ "@applicaster/zapp-react-native-bridge": "15.0.0-rc.28",
33
+ "@applicaster/zapp-react-native-redux": "15.0.0-rc.28",
34
+ "@applicaster/zapp-react-native-utils": "15.0.0-rc.28",
35
35
  "promise": "^8.3.0",
36
36
  "url": "^0.11.0",
37
37
  "uuid": "^3.3.2"
@@ -1,60 +0,0 @@
1
- import React from "react";
2
- import { Animated, ViewStyle } from "react-native";
3
-
4
- import {
5
- useModalAnimationContext,
6
- PlayerAnimationStateEnum,
7
- } from "@applicaster/zapp-react-native-ui-components/Components/VideoModal/ModalAnimation";
8
-
9
- type Props = {
10
- style: ViewStyle[];
11
- children: React.ReactNode;
12
- };
13
-
14
- export const AnimatedPlayerModalWrapper = (props: Props) => {
15
- const {
16
- playerAnimationState,
17
- animatedValues: { lastScrollY, dragScrollY, translateYOffset },
18
- modalSnapPoints,
19
- setStartComponentsAnimation,
20
- } = useModalAnimationContext();
21
-
22
- const interpolateConfig: Animated.InterpolationConfigType = React.useMemo(
23
- () => ({
24
- inputRange: modalSnapPoints,
25
- outputRange: modalSnapPoints,
26
- extrapolate: "clamp",
27
- }),
28
- [modalSnapPoints]
29
- );
30
-
31
- let translateY;
32
-
33
- if (playerAnimationState === PlayerAnimationStateEnum.drag_player) {
34
- translateY = translateYOffset.interpolate(interpolateConfig);
35
- } else {
36
- const reverseLastScrollY = Animated.multiply(
37
- new Animated.Value(-1),
38
- lastScrollY
39
- );
40
-
41
- translateY = Animated.add(
42
- translateYOffset,
43
- Animated.add(dragScrollY, reverseLastScrollY)
44
- ).interpolate(interpolateConfig);
45
- }
46
-
47
- React.useEffect(() => {
48
- (playerAnimationState === PlayerAnimationStateEnum.minimize ||
49
- playerAnimationState === PlayerAnimationStateEnum.maximize) &&
50
- setStartComponentsAnimation(true);
51
- }, [playerAnimationState]);
52
-
53
- return (
54
- <Animated.View
55
- style={[props.style, { transform: [{ translateY: translateY }] }]}
56
- >
57
- {props.children}
58
- </Animated.View>
59
- );
60
- };