@applicaster/zapp-react-native-ui-components 15.0.0-rc.34 → 15.0.0-rc.35

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,62 +1,155 @@
1
- import React, { useEffect, useMemo } from "react";
1
+ import React, { useMemo } from "react";
2
2
  import { Animated, Dimensions } from "react-native";
3
3
 
4
4
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
5
5
 
6
6
  import { useConfiguration } from "../utils";
7
- import { useIsTabletLandscape } from "@applicaster/zapp-react-native-utils/reactHooks/device/useMemoizedIsTablet";
7
+ import { usePlugins } from "@applicaster/zapp-react-native-redux/hooks";
8
+ import { isMenuVisible } from "../../Screen/navigationHandler";
9
+
10
+ import {
11
+ useSafeAreaFrame,
12
+ useSafeAreaInsets,
13
+ } from "react-native-safe-area-context";
14
+ import {
15
+ isAndroidPlatform,
16
+ isAndroidVersionAtLeast,
17
+ } from "@applicaster/zapp-react-native-utils/reactUtils";
18
+ import { getTabBarHeight } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/getTabBarHeight";
19
+ import { PROGRESS_BAR_HEIGHT } from "./utils";
20
+ import { useIsTablet as getIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
21
+ import { useAppSelector } from "@applicaster/zapp-react-native-redux";
8
22
 
9
23
  export type ModalAnimationContextT = {
10
- yTranslate: React.MutableRefObject<Animated.Value | null>;
24
+ yTranslate: React.MutableRefObject<Animated.AnimatedInterpolation<number>>;
25
+ offsetAnimatedValueRef: React.MutableRefObject<Animated.Value>;
26
+ offset: React.MutableRefObject<number>;
27
+ heightAboveMinimised: number;
28
+ gestureTranslationRef: React.MutableRefObject<Animated.Value>;
11
29
  minimisedHeight: number;
12
30
  };
13
31
 
14
32
  export const ReactContext = React.createContext<ModalAnimationContextT>({
15
33
  yTranslate: React.createRef<Animated.Value | null>(),
34
+ offsetAnimatedValueRef: React.createRef<Animated.Value>(),
35
+ offset: React.createRef<number>(),
36
+ heightAboveMinimised: 0,
37
+ gestureTranslationRef: React.createRef<Animated.Value>(),
16
38
  minimisedHeight: 60,
17
39
  });
18
40
 
41
+ const SAFE_AREA_BREAKING_API_VERSION = 35;
42
+
43
+ export const isOldAndroidDevice =
44
+ isAndroidPlatform() &&
45
+ !isAndroidVersionAtLeast(SAFE_AREA_BREAKING_API_VERSION);
46
+
47
+ const bottomTabBarHeight = getTabBarHeight();
48
+
19
49
  const Provider = ({ children }: { children: React.ReactNode }) => {
50
+ const { height } = Dimensions.get("window");
51
+
20
52
  const yTranslate = React.useRef(
21
- new Animated.Value(Dimensions.get("window").height)
53
+ new Animated.Value(height).interpolate<number>({
54
+ inputRange: [0, height],
55
+ outputRange: [0, height],
56
+ })
22
57
  );
23
58
 
59
+ const { minimised_height: minimisedHeight } = useConfiguration();
60
+
24
61
  const {
25
- videoModalState: { visible },
62
+ videoModalState: { visible, mode },
63
+ currentRoute,
64
+ screenData,
26
65
  } = useNavigation();
27
66
 
28
- const { minimised_height: minimisedHeight } = useConfiguration();
67
+ const isTabletPortrait = useAppSelector(
68
+ (state) => state.appData.isTabletPortrait
69
+ );
70
+
71
+ const plugins = usePlugins();
72
+
73
+ const menuVisible = isMenuVisible(currentRoute, screenData, plugins);
74
+
75
+ const frame = useSafeAreaFrame();
76
+ const insets = useSafeAreaInsets();
77
+
78
+ const [heightAboveMinimised, setHeightAboveMinimised] = React.useState(0);
79
+
80
+ // memoizing heightAboveMinimised value
81
+ const offset = React.useRef(heightAboveMinimised);
82
+
83
+ // Used for memoizing modal y position after start/end of transition
84
+ const offsetAnimatedValueRef = React.useRef(
85
+ new Animated.Value(-offset.current)
86
+ );
87
+
88
+ // Used for gesture handling
89
+ const gestureTranslationRef = React.useRef(new Animated.Value(0));
90
+
91
+ const videoModalStateRef = React.useRef({ visible, mode });
92
+
93
+ React.useEffect(() => {
94
+ videoModalStateRef.current = { visible, mode };
95
+ }, [visible, mode]);
96
+
97
+ const translateY = useMemo(() => {
98
+ const maxRange = heightAboveMinimised;
99
+
100
+ const combined: Animated.AnimatedAddition<number> = Animated.add(
101
+ offsetAnimatedValueRef.current,
102
+ gestureTranslationRef.current
103
+ );
104
+
105
+ return combined.interpolate({
106
+ inputRange: [0, maxRange],
107
+ outputRange: [0, maxRange],
108
+ extrapolate: "clamp",
109
+ });
110
+ }, [visible, heightAboveMinimised]);
111
+
112
+ offset.current = heightAboveMinimised;
113
+ yTranslate.current = translateY;
114
+
115
+ React.useEffect(() => {
116
+ const collapsedHeight =
117
+ minimisedHeight +
118
+ (menuVisible ? bottomTabBarHeight : 0) +
119
+ (isOldAndroidDevice ? 0 : insets.bottom) + // insets.bottom is added to properly display docked modal
120
+ PROGRESS_BAR_HEIGHT;
121
+
122
+ const heightAboveMinimised = frame.height - collapsedHeight;
123
+
124
+ const isLandscape = frame.width > frame.height;
125
+
126
+ const isTablet = getIsTablet();
127
+
128
+ const shouldIgnoreLandscape = isTablet ? isTabletPortrait : true;
29
129
 
30
- const isTabletLandscape = useIsTabletLandscape();
31
- const windowDimensions = Dimensions.get("window");
32
-
33
- useEffect(() => {
34
- // Reset player animation state when video modal is closed
35
- if (!visible) {
36
- if (!isTabletLandscape) {
37
- // restore to portrait ( in portrait mode height is bigger)
38
- if (windowDimensions.height > windowDimensions.width) {
39
- yTranslate.current?.setValue(windowDimensions.height);
40
- }
41
- } else {
42
- yTranslate.current?.setValue(windowDimensions.height);
43
- }
130
+ if (
131
+ heightAboveMinimised !== offset.current &&
132
+ videoModalStateRef.current.mode !== "PIP" &&
133
+ videoModalStateRef.current.mode !== "FULLSCREEN"
134
+ ) {
135
+ if (isLandscape && shouldIgnoreLandscape) return;
136
+ setHeightAboveMinimised(heightAboveMinimised);
137
+ offset.current = heightAboveMinimised;
44
138
  }
45
- }, [
46
- visible,
47
- windowDimensions.height,
48
- isTabletLandscape,
49
- windowDimensions.width,
50
- ]);
139
+ }, [frame.height, insets.bottom, menuVisible, minimisedHeight]);
51
140
 
52
141
  return (
53
142
  <ReactContext.Provider
54
143
  value={useMemo(
55
144
  () => ({
56
145
  yTranslate,
146
+ offsetAnimatedValueRef,
147
+ offset,
148
+ heightAboveMinimised,
57
149
  minimisedHeight,
150
+ gestureTranslationRef,
58
151
  }),
59
- [minimisedHeight]
152
+ [minimisedHeight, heightAboveMinimised]
60
153
  )}
61
154
  >
62
155
  {children}
@@ -139,11 +139,7 @@ const VideoModalComponent = () => {
139
139
 
140
140
  {itemIdHooksFinished === item?.id ? (
141
141
  <View pointerEvents="box-none" style={styles.container}>
142
- <HandlePlayable
143
- item={item}
144
- isModal={mode !== "PIP"}
145
- mode={mode}
146
- />
142
+ <HandlePlayable item={item} isModal mode={mode} />
147
143
  </View>
148
144
  ) : (
149
145
  <View style={styles.loaderContainer}>
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.34",
3
+ "version": "15.0.0-rc.35",
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.34",
32
- "@applicaster/zapp-react-native-bridge": "15.0.0-rc.34",
33
- "@applicaster/zapp-react-native-redux": "15.0.0-rc.34",
34
- "@applicaster/zapp-react-native-utils": "15.0.0-rc.34",
31
+ "@applicaster/applicaster-types": "15.0.0-rc.35",
32
+ "@applicaster/zapp-react-native-bridge": "15.0.0-rc.35",
33
+ "@applicaster/zapp-react-native-redux": "15.0.0-rc.35",
34
+ "@applicaster/zapp-react-native-utils": "15.0.0-rc.35",
35
35
  "promise": "^8.3.0",
36
36
  "url": "^0.11.0",
37
37
  "uuid": "^3.3.2"