@applicaster/zapp-react-native-ui-components 15.0.0-rc.27 → 15.0.0-rc.29
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,23 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
Edge,
|
|
5
|
-
SafeAreaView,
|
|
6
|
-
useSafeAreaInsets,
|
|
7
|
-
} from "react-native-safe-area-context";
|
|
2
|
+
import { View, ViewStyle } from "react-native";
|
|
3
|
+
import { Edge, SafeAreaView } from "react-native-safe-area-context";
|
|
8
4
|
import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
9
5
|
import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
10
6
|
import { playerDimensionsHack } from "./utils";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
DimensionsT,
|
|
14
|
-
Configuration,
|
|
15
|
-
getEdges,
|
|
16
|
-
getBaseDimensions,
|
|
17
|
-
calculateAspectRatio,
|
|
18
|
-
getPlayerDimensions,
|
|
19
|
-
getContainerDimensions,
|
|
20
|
-
} from "./playerWrapperUtils";
|
|
7
|
+
import { DimensionsT, Configuration, getEdges } from "./playerWrapperUtils";
|
|
8
|
+
import { defaultStyles, useStyle } from "./playerWrapperStyle";
|
|
21
9
|
|
|
22
10
|
type Props = {
|
|
23
11
|
entry: ZappEntry;
|
|
@@ -34,10 +22,6 @@ type Props = {
|
|
|
34
22
|
playerContent: (styles: ViewStyle) => React.ReactNode;
|
|
35
23
|
};
|
|
36
24
|
|
|
37
|
-
const defaultStyles = StyleSheet.create({
|
|
38
|
-
playerContainer: { position: "relative", alignSelf: "center", zIndex: 200 },
|
|
39
|
-
});
|
|
40
|
-
|
|
41
25
|
const PlayerWrapperComponent = (props: Props) => {
|
|
42
26
|
const {
|
|
43
27
|
entry,
|
|
@@ -51,51 +35,21 @@ const PlayerWrapperComponent = (props: Props) => {
|
|
|
51
35
|
playerContent,
|
|
52
36
|
} = props;
|
|
53
37
|
|
|
38
|
+
const styles = useStyle({
|
|
39
|
+
style,
|
|
40
|
+
inline,
|
|
41
|
+
isModal,
|
|
42
|
+
isTabletPortrait,
|
|
43
|
+
configuration,
|
|
44
|
+
pip,
|
|
45
|
+
});
|
|
46
|
+
|
|
54
47
|
const isTablet = useIsTablet();
|
|
55
48
|
|
|
56
49
|
const isInlineModal = inline && isModal;
|
|
57
50
|
|
|
58
|
-
const isTabletLandscape = !isTV() && isTablet && !isTabletPortrait;
|
|
59
|
-
|
|
60
|
-
const tabletWidth = getTabletWidth(
|
|
61
|
-
configuration.tablet_landscape_sidebar_width,
|
|
62
|
-
style
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
const baseDimensions: DimensionsT = React.useMemo(
|
|
66
|
-
() => getBaseDimensions(isInlineModal, isTabletLandscape, tabletWidth),
|
|
67
|
-
[isInlineModal, isTabletLandscape, tabletWidth]
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
const insets = useSafeAreaInsets();
|
|
71
|
-
|
|
72
|
-
const aspectRatio = React.useMemo(
|
|
73
|
-
() => calculateAspectRatio(isInlineModal, pip, insets),
|
|
74
|
-
// ignoring insets - only initial needed
|
|
75
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
76
|
-
[isInlineModal, pip]
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
const playerDimensions = React.useMemo(
|
|
80
|
-
() => getPlayerDimensions(baseDimensions, aspectRatio),
|
|
81
|
-
[baseDimensions, aspectRatio]
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
const containerDimensions: DimensionsT = React.useMemo(
|
|
85
|
-
() => getContainerDimensions(baseDimensions, playerDimensions.aspectRatio),
|
|
86
|
-
[baseDimensions, playerDimensions.aspectRatio]
|
|
87
|
-
);
|
|
88
|
-
|
|
89
51
|
const WrapperView = React.useMemo(() => (isTV() ? View : SafeAreaView), []);
|
|
90
52
|
|
|
91
|
-
const childrenStyles = React.useMemo(
|
|
92
|
-
() => ({
|
|
93
|
-
...playerDimensions,
|
|
94
|
-
...playerDimensionsHack,
|
|
95
|
-
}),
|
|
96
|
-
[playerDimensions]
|
|
97
|
-
);
|
|
98
|
-
|
|
99
53
|
return (
|
|
100
54
|
<WrapperView
|
|
101
55
|
edges={getEdges(isTablet, isInlineModal) as readonly Edge[]}
|
|
@@ -106,11 +60,11 @@ const PlayerWrapperComponent = (props: Props) => {
|
|
|
106
60
|
style={[
|
|
107
61
|
defaultStyles.playerContainer,
|
|
108
62
|
playerDimensionsHack,
|
|
109
|
-
containerDimensions,
|
|
63
|
+
styles.containerDimensions,
|
|
110
64
|
containerStyle,
|
|
111
65
|
]}
|
|
112
66
|
>
|
|
113
|
-
{playerContent(childrenStyles)}
|
|
67
|
+
{playerContent(styles.childrenStyles)}
|
|
114
68
|
</View>
|
|
115
69
|
</WrapperView>
|
|
116
70
|
);
|
|
@@ -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() &&
|
|
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,16 +1,6 @@
|
|
|
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
|
-
import {
|
|
5
|
-
isAndroidPlatform,
|
|
6
|
-
isAndroidVersionAtLeast,
|
|
7
|
-
} from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
8
|
-
|
|
9
|
-
const MIN_SUPPORTED_ANDROID_API = 34;
|
|
10
|
-
|
|
11
|
-
export const isOldAndroidDevice =
|
|
12
|
-
isAndroidPlatform() && !isAndroidVersionAtLeast(MIN_SUPPORTED_ANDROID_API);
|
|
13
|
-
|
|
14
4
|
export type DimensionsT = {
|
|
15
5
|
width: number | string;
|
|
16
6
|
height: number | string | undefined;
|
|
@@ -23,6 +13,10 @@ export type Configuration = {
|
|
|
23
13
|
tablet_landscape_player_container_background_color?: string;
|
|
24
14
|
};
|
|
25
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
|
+
|
|
26
20
|
export const getWindowDimensions = () => {
|
|
27
21
|
const { width, height } = Dimensions.get("window");
|
|
28
22
|
|
|
@@ -41,15 +35,11 @@ export const getMinWindowDimension = () => {
|
|
|
41
35
|
return Math.min(width, height);
|
|
42
36
|
};
|
|
43
37
|
|
|
44
|
-
export const getScreenAspectRatio = (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}) => {
|
|
48
|
-
const longEdge = getMaxWindowDimension();
|
|
49
|
-
const shortEdge = getMinWindowDimension();
|
|
38
|
+
export const getScreenAspectRatio = () => {
|
|
39
|
+
const longEdge = Math.max(SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
40
|
+
const shortEdge = Math.min(SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
50
41
|
|
|
51
|
-
|
|
52
|
-
return longEdge / (shortEdge - ((insets?.top ?? 0) + (insets?.bottom ?? 0)));
|
|
42
|
+
return longEdge / shortEdge;
|
|
53
43
|
};
|
|
54
44
|
|
|
55
45
|
export const getEdges = (
|
|
@@ -70,35 +60,32 @@ export const getEdges = (
|
|
|
70
60
|
export const getBaseDimensions = (
|
|
71
61
|
isInlineModal: boolean,
|
|
72
62
|
isTabletLandscape: boolean,
|
|
73
|
-
tabletWidth:
|
|
74
|
-
):
|
|
63
|
+
tabletWidth: DimensionValue
|
|
64
|
+
): ViewStyle => ({
|
|
75
65
|
width: isInlineModal && isTabletLandscape ? tabletWidth : "100%",
|
|
76
66
|
height: undefined,
|
|
77
67
|
});
|
|
78
68
|
|
|
79
69
|
export const calculateAspectRatio = (
|
|
80
70
|
isInlineModal: boolean,
|
|
81
|
-
pip?: boolean
|
|
82
|
-
insets?: { top: number; bottom: number }
|
|
71
|
+
pip?: boolean
|
|
83
72
|
): number => {
|
|
84
|
-
return !isInlineModal && !pip
|
|
85
|
-
? getScreenAspectRatio(isOldAndroidDevice ? insets : undefined)
|
|
86
|
-
: 16 / 9;
|
|
73
|
+
return !isInlineModal && !pip ? getScreenAspectRatio() : 16 / 9;
|
|
87
74
|
};
|
|
88
75
|
|
|
89
76
|
export const getPlayerDimensions = (
|
|
90
|
-
baseDimensions:
|
|
77
|
+
baseDimensions: ViewStyle,
|
|
91
78
|
aspectRatio: number
|
|
92
|
-
):
|
|
93
|
-
...baseDimensions,
|
|
79
|
+
): ViewStyle => ({
|
|
80
|
+
...(baseDimensions as any),
|
|
94
81
|
width: baseDimensions.width,
|
|
95
82
|
aspectRatio,
|
|
96
83
|
});
|
|
97
84
|
|
|
98
85
|
export const getContainerDimensions = (
|
|
99
|
-
baseDimensions:
|
|
100
|
-
|
|
101
|
-
):
|
|
86
|
+
baseDimensions: ViewStyle,
|
|
87
|
+
aspectRatio?: string | number
|
|
88
|
+
): ViewStyle => ({
|
|
102
89
|
...baseDimensions,
|
|
103
|
-
aspectRatio
|
|
90
|
+
aspectRatio,
|
|
104
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.
|
|
3
|
+
"version": "15.0.0-rc.29",
|
|
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.
|
|
32
|
-
"@applicaster/zapp-react-native-bridge": "15.0.0-rc.
|
|
33
|
-
"@applicaster/zapp-react-native-redux": "15.0.0-rc.
|
|
34
|
-
"@applicaster/zapp-react-native-utils": "15.0.0-rc.
|
|
31
|
+
"@applicaster/applicaster-types": "15.0.0-rc.29",
|
|
32
|
+
"@applicaster/zapp-react-native-bridge": "15.0.0-rc.29",
|
|
33
|
+
"@applicaster/zapp-react-native-redux": "15.0.0-rc.29",
|
|
34
|
+
"@applicaster/zapp-react-native-utils": "15.0.0-rc.29",
|
|
35
35
|
"promise": "^8.3.0",
|
|
36
36
|
"url": "^0.11.0",
|
|
37
37
|
"uuid": "^3.3.2"
|