@applicaster/zapp-react-native-ui-components 12.0.0-rc.12 → 12.0.0-rc.121

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.
Files changed (162) hide show
  1. package/Components/AudioPlayer/AudioPlayer.tsx +9 -1
  2. package/Components/AudioPlayer/__tests__/__snapshots__/audioPlayer.test.js.snap +5 -0
  3. package/Components/AudioPlayer/helpers.tsx +1 -0
  4. package/Components/BaseFocusable/index.tsx +3 -3
  5. package/Components/Cell/Cell.tsx +32 -11
  6. package/Components/Cell/CellWithFocusable.tsx +40 -19
  7. package/Components/Cell/TvOSCellComponent.tsx +5 -9
  8. package/Components/ErrorScreen/index.tsx +1 -1
  9. package/Components/FastImage/index.android.js +1 -1
  10. package/Components/Focusable/Focusable.tsx +6 -1
  11. package/Components/FocusableCell/index.tsx +7 -7
  12. package/Components/FocusableGroup/index.tsx +11 -2
  13. package/Components/FocusableList/FocusableChild.ts +24 -14
  14. package/Components/FocusableList/FocusableItem.tsx +1 -1
  15. package/Components/FocusableList/FocusableListItemWrapper.tsx +76 -0
  16. package/Components/FocusableList/hooks/useCellState.android.ts +3 -1
  17. package/Components/FocusableList/index.tsx +26 -25
  18. package/Components/FreezeWithCallback/Freeze.tsx +31 -0
  19. package/Components/FreezeWithCallback/LICENSE +21 -0
  20. package/Components/FreezeWithCallback/Suspender.tsx +17 -0
  21. package/Components/FreezeWithCallback/__tests__/index.test.tsx +170 -0
  22. package/Components/FreezeWithCallback/index.tsx +3 -0
  23. package/Components/GeneralContentScreen/GeneralContentScreen.tsx +11 -8
  24. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +13 -6
  25. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +1 -1
  26. package/Components/HandlePlayable/HandlePlayable.tsx +4 -1
  27. package/Components/HookRenderer/index.tsx +1 -6
  28. package/Components/Image/Image.android.tsx +3 -25
  29. package/Components/Image/Image.tsx +18 -2
  30. package/Components/Image/utils/index.ts +39 -0
  31. package/Components/Layout/TV/ScreenContainer.tsx +79 -5
  32. package/Components/Layout/TV/ScreenLayoutContextProvider.tsx +2 -2
  33. package/Components/Layout/TV/__tests__/ScreenContainer.test.tsx +38 -28
  34. package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +25 -13
  35. package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +10 -50
  36. package/Components/Layout/TV/__tests__/index.test.tsx +20 -108
  37. package/Components/Layout/TV/index.tsx +15 -84
  38. package/Components/Layout/TV/index.web.tsx +33 -0
  39. package/Components/Layout/index.tsx +15 -11
  40. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +4 -1
  41. package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +86 -117
  42. package/Components/MasterCell/DefaultComponents/CellBadge/index.tsx +21 -8
  43. package/Components/MasterCell/DefaultComponents/DynamicBadge.tsx +4 -2
  44. package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +4 -1
  45. package/Components/MasterCell/DefaultComponents/Image/Image.android.tsx +9 -26
  46. package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +5 -3
  47. package/Components/MasterCell/DefaultComponents/Image/hooks/useImageSize.ts +65 -0
  48. package/Components/MasterCell/DefaultComponents/ImageBorderContainer/index.ts +71 -0
  49. package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +5 -1
  50. package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +37 -2
  51. package/Components/MasterCell/DefaultComponents/SecondaryImage/Image.tsx +3 -2
  52. package/Components/MasterCell/DefaultComponents/Text/index.tsx +14 -2
  53. package/Components/MasterCell/DefaultComponents/Toggle.tsx +5 -1
  54. package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +1 -1
  55. package/Components/MasterCell/DefaultComponents/__tests__/text.test.tsx +24 -9
  56. package/Components/MasterCell/DefaultComponents/index.ts +2 -0
  57. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/index.android.tsx +4 -1
  58. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/index.tsx +10 -2
  59. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/index.ts +6 -10
  60. package/Components/MasterCell/SharedUI/ProgressBar/hooks/useFillInPercent.ts +7 -1
  61. package/Components/MasterCell/dataAdapter.ts +21 -7
  62. package/Components/MasterCell/hooks/useAsyncRendering/index.ts +1 -1
  63. package/Components/MasterCell/index.tsx +5 -3
  64. package/Components/MasterCell/utils/__tests__/insertBetween.test.js +9 -0
  65. package/Components/MasterCell/utils/index.ts +33 -35
  66. package/Components/MeasurmentsPortal/BasicMeasurementsPortal.tsx +11 -7
  67. package/Components/MeasurmentsPortal/MeasurementsPortal.tsx +10 -1
  68. package/Components/ModalComponent/BottomSheetModalContent.tsx +121 -0
  69. package/Components/ModalComponent/Button/Item.tsx +82 -0
  70. package/Components/ModalComponent/Button/ItemIcon.tsx +60 -0
  71. package/Components/ModalComponent/Button/ItemLabel.tsx +101 -0
  72. package/Components/ModalComponent/Button/assets.ts +4 -0
  73. package/Components/ModalComponent/Button/index.tsx +111 -0
  74. package/Components/ModalComponent/Header/CloseButton.tsx +59 -0
  75. package/Components/ModalComponent/Header/Title.tsx +70 -0
  76. package/Components/ModalComponent/Header/assets.ts +4 -0
  77. package/Components/ModalComponent/Header/index.tsx +71 -0
  78. package/Components/ModalComponent/Header/utils.ts +79 -0
  79. package/Components/ModalComponent/index.tsx +38 -0
  80. package/Components/ModalComponent/utils.ts +126 -0
  81. package/Components/Navigator/StackNavigator.tsx +57 -0
  82. package/Components/Navigator/index.ts +1 -0
  83. package/Components/PlayerContainer/PlayerContainer.tsx +66 -31
  84. package/Components/PlayerContainer/ProgramInfo/index.tsx +3 -1
  85. package/Components/PlayerImageBackground/index.tsx +34 -8
  86. package/Components/River/ComponentsMap/ComponentsMap.tsx +97 -2
  87. package/Components/River/RefreshControl.tsx +55 -1
  88. package/Components/River/TV/River.tsx +2 -25
  89. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +1 -1
  90. package/Components/River/__tests__/componentsMap.test.js +7 -0
  91. package/Components/River/useScreenConfiguration.ts +2 -2
  92. package/Components/RouteManager/__tests__/__snapshots__/routeManager.test.js.snap +1 -0
  93. package/Components/RouteManager/__tests__/routeManager.test.js +9 -2
  94. package/Components/RouteManager/index.tsx +4 -2
  95. package/Components/Screen/TV/hooks/index.ts +1 -0
  96. package/Components/Screen/TV/hooks/useInitialFocus.ts +70 -0
  97. package/Components/Screen/TV/index.web.tsx +178 -0
  98. package/Components/Screen/__tests__/Screen.test.tsx +43 -75
  99. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +24 -6
  100. package/Components/Screen/__tests__/navigationHandler.test.ts +1 -178
  101. package/Components/Screen/index.tsx +104 -65
  102. package/Components/Screen/navigationHandler.ts +6 -85
  103. package/Components/Screen/orientationHandler.ts +18 -7
  104. package/Components/Screen/utils.ts +16 -0
  105. package/Components/ScreenResolver/index.tsx +10 -13
  106. package/Components/Tabs/TV/styles.ts +1 -1
  107. package/Components/TrackedView/index.tsx +6 -3
  108. package/Components/Transitioner/Scene.tsx +39 -26
  109. package/Components/Transitioner/Transitioner.tsx +46 -48
  110. package/Components/Transitioner/__tests__/Scene.test.js +7 -0
  111. package/Components/Transitioner/__tests__/__snapshots__/Scene.test.js.snap +12 -4
  112. package/Components/Transitioner/__tests__/__snapshots__/transitioner.test.js.snap +2 -0
  113. package/Components/VideoLive/LiveImageManager.ts +70 -14
  114. package/Components/VideoLive/PlayerLiveImageComponent.tsx +132 -95
  115. package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +45 -3
  116. package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +21 -29
  117. package/Components/VideoModal/ModalAnimation/AnimatedPlayerModalWrapper.tsx +66 -0
  118. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +376 -0
  119. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +165 -0
  120. package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +473 -0
  121. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +182 -0
  122. package/Components/VideoModal/ModalAnimation/index.ts +15 -0
  123. package/Components/VideoModal/ModalAnimation/utils.ts +302 -0
  124. package/Components/VideoModal/PlayerDetails.tsx +6 -3
  125. package/Components/VideoModal/PlayerWrapper.tsx +81 -49
  126. package/Components/VideoModal/VideoModal.tsx +23 -40
  127. package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +0 -2
  128. package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +12 -1
  129. package/Components/VideoModal/__tests__/__snapshots__/PlayerWrapper.test.tsx.snap +312 -166
  130. package/Components/VideoModal/hooks/useModalSize.ts +10 -12
  131. package/Components/VideoModal/utils.ts +8 -5
  132. package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +26 -21
  133. package/Components/Viewport/ViewportTracker/ViewportTracker.tsx +31 -40
  134. package/Components/Viewport/ViewportTracker/__tests__/viewportTracker.test.js +4 -5
  135. package/Components/Viewport/ViewportTracker/index.tsx +1 -0
  136. package/Components/Viewport/utils.js +1 -1
  137. package/Components/ZappFrameworkComponents/BarView/BarView.tsx +4 -3
  138. package/Components/ZappUIComponent/index.tsx +22 -12
  139. package/Components/default-cell-renderer/__tests__/__snapshots__/defaultCellRenderer.test.tsx.snap +4 -4
  140. package/Components/index.js +2 -0
  141. package/Contexts/FocusableGroupContext/FocusableGroupContext.ts +3 -0
  142. package/Contexts/FocusableGroupContext/FocusableGroupContextProvider.tsx +16 -0
  143. package/Contexts/FocusableGroupContext/__tests__/FocusableGroupContextProvider.test.tsx +22 -0
  144. package/Contexts/FocusableGroupContext/__tests__/withFocusableContext.test.tsx +26 -0
  145. package/Contexts/FocusableGroupContext/index.ts +7 -0
  146. package/Contexts/FocusableGroupContext/withFocusableContext.tsx +17 -0
  147. package/Contexts/MenuToggleContext/{index.js → index.ts} +16 -0
  148. package/Contexts/ScreenContext/__tests__/__snapshots__/index.test.tsx.snap +3 -0
  149. package/Contexts/ScreenContext/__tests__/index.test.tsx +27 -0
  150. package/Contexts/ScreenContext/index.tsx +95 -29
  151. package/Contexts/ScreenDataContext/index.tsx +20 -0
  152. package/Contexts/ZappPipesContext/ZappPipesEntryContext.ts +1 -1
  153. package/Decorators/ComponentsMapWrapper/withComponentsMapProvider.tsx +7 -2
  154. package/const.ts +6 -0
  155. package/events/index.ts +1 -0
  156. package/index.js +3 -0
  157. package/package.json +5 -5
  158. package/Components/Layout/TV/TransitionOverlay.tsx +0 -64
  159. package/Components/VideoModal/hooks/usePosition.ts +0 -50
  160. /package/Components/FocusableGroup/{index.android.js → index.android.ts} +0 -0
  161. /package/Components/FocusableGroup/{index.ios.js → index.ios.ts} +0 -0
  162. /package/Contexts/{index.js → index.ts} +0 -0
@@ -1,85 +1,3 @@
1
- import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
2
-
3
- /**
4
- * This function helps to decide wether the navbar should be presented on the screen
5
- * based on route and / or screen Data
6
- *
7
- * Currently the scenarios include
8
- * - players => false
9
- * - search screen plugin => false
10
- * - hooks with `showNavBar: true` or `presentFullScreen` not set to true, defaults to no navbar for hook screens
11
- * - screens with `allow_screen_plugin_presentation` in general property => false
12
- *
13
- * @param {String} route current route of the screen
14
- * @param {Object} screenData payload associated with the currently presented screen
15
- * @returns {Boolean}
16
- */
17
- export function isNavBarVisible(
18
- route,
19
- screenData,
20
- showNavBar,
21
- canGoBack,
22
- videoModalState: QuickBrickVideoModalState | null = null
23
- ) {
24
- /* screenData is not actual navigator.data
25
- * or navigator.screenData,
26
- * but navigator.data.screen */
27
- if (route.includes("playable")) {
28
- return false;
29
- }
30
-
31
- if (
32
- videoModalState?.mode === "FULLSCREEN" &&
33
- videoModalState?.visible === true
34
- ) {
35
- return false;
36
- }
37
-
38
- if (screenData?.type === "qb_search_screen" && !isTV()) {
39
- return false;
40
- }
41
-
42
- /* Match if screen is Hook */
43
- if (route.startsWith("/hooks/")) {
44
- const module = screenData?.module;
45
-
46
- if (module?.presentFullScreen) {
47
- return false;
48
- }
49
-
50
- return module?.showNavBar ?? false;
51
- }
52
-
53
- if (screenData?.hookPlugin) {
54
- const hookPlugin = screenData?.hookPlugin?.module;
55
-
56
- return (
57
- hookPlugin?.showNavBar || hookPlugin?.presentFullScreen !== true || false
58
- );
59
- }
60
-
61
- if (
62
- screenData?.general?.allow_screen_plugin_presentation ||
63
- screenData?.general?.hide_app_nav_bar
64
- ) {
65
- return false;
66
- }
67
-
68
- const hideSecondaryLevel = screenData?.navigations?.some(
69
- (navigation) => navigation.styles?.hide_secondary_level_menu
70
- );
71
-
72
- if (canGoBack && hideSecondaryLevel) {
73
- return false;
74
- }
75
-
76
- if (typeof showNavBar === "boolean" && !showNavBar) {
77
- return false;
78
- }
79
-
80
- return true;
81
- }
82
-
83
1
  /**
84
2
  * This function helps to decide wether the menu should be presented on the screen
85
3
  * based on route and / or screen Data
@@ -87,6 +5,11 @@ export function isNavBarVisible(
87
5
  * is similar to the navbar, except that it covers scenarios where only the navbar (and not)
88
6
  * the menu, will be hidden
89
7
  *
8
+ * - playable screens
9
+ * - qb_search_screen
10
+ * - screen hooks that specify showNavBar or presentFullScreen
11
+ * - screens or nested screens that have allow_screen_plugin_presentation set to true
12
+ *
90
13
  * @param {String} route current route of the screen
91
14
  * @param {Object} screenData payload associated with the currently presented screen
92
15
  * @returns {Boolean}
@@ -103,9 +26,7 @@ export function isMenuVisible(route, screenData) {
103
26
  if (screenData?.hookPlugin) {
104
27
  const hookPlugin = screenData?.hookPlugin?.module;
105
28
 
106
- return (
107
- hookPlugin?.showNavBar || hookPlugin?.presentFullScreen !== true || false
108
- );
29
+ return hookPlugin?.showNavBar || hookPlugin?.presentFullScreen !== true;
109
30
  }
110
31
 
111
32
  if (
@@ -1,14 +1,16 @@
1
1
  import React, { useLayoutEffect } from "react";
2
+
2
3
  import {
3
4
  allowedOrientationsForScreen,
4
5
  ORIENTATIONS,
5
6
  getOrientation,
6
7
  useGetScreenOrientation,
7
8
  } from "@applicaster/zapp-react-native-utils/appUtils/orientationHelper";
8
-
9
+ import { usePrevious } from "@applicaster/zapp-react-native-utils/reactHooks/utils";
9
10
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
10
11
  import { findPluginByType } from "@applicaster/zapp-react-native-utils/pluginUtils";
11
12
  import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
13
+
12
14
  import { ZappHookModalContext } from "../../Contexts";
13
15
  import { HookModalContextT } from "../../Contexts/ZappHookModalContext";
14
16
 
@@ -79,14 +81,23 @@ export function useNewOrientationForScreenData({
79
81
  screenOrientation;
80
82
  }
81
83
 
82
- export function useScreenOrientationHandler({
83
- screenData,
84
- }: OrientationHookArgs) {
84
+ type Props = {
85
+ screenData: {
86
+ screen: {};
87
+ };
88
+ isActive: boolean;
89
+ };
90
+
91
+ export function useScreenOrientationHandler({ screenData, isActive }: Props) {
85
92
  const { isHooksExecutionInProgress } = React.useContext<HookModalContextT>(
86
93
  ZappHookModalContext.ReactContext
87
94
  );
88
95
 
89
- const newOrientation = useNewOrientationForScreenData({ screenData });
96
+ const prevIsActive = usePrevious(isActive);
97
+
98
+ const newOrientation = useNewOrientationForScreenData({
99
+ screenData: screenData.screen,
100
+ });
90
101
 
91
102
  useLayoutEffect(() => {
92
103
  // Null means screen does not have orientation preference, so we can skip rotate
@@ -100,12 +111,12 @@ export function useScreenOrientationHandler({
100
111
  return;
101
112
  }
102
113
 
103
- if (newOrientation !== current) {
114
+ if (!prevIsActive && isActive && newOrientation !== current) {
104
115
  current = newOrientation;
105
116
 
106
117
  setOrientation(newOrientation);
107
118
  }
108
- }, [newOrientation, isHooksExecutionInProgress]);
119
+ }, [newOrientation, isHooksExecutionInProgress, prevIsActive, isActive]);
109
120
  }
110
121
 
111
122
  export function useOrientationHandler({ screenData }: OrientationHookArgs) {
@@ -0,0 +1,16 @@
1
+ import { map, split, replace, compose, trim } from "ramda";
2
+
3
+ function colorIsNotTransparent(color) {
4
+ const layers = compose(
5
+ map(trim),
6
+ split(","),
7
+ replace(")", ""),
8
+ replace("rgba(", "")
9
+ )(color);
10
+
11
+ return Number(layers?.[3]) > 0;
12
+ }
13
+
14
+ export function isValidColor(string) {
15
+ return string && string !== "transparent" && colorIsNotTransparent(string);
16
+ }
@@ -1,6 +1,5 @@
1
1
  import * as React from "react";
2
- import * as R from "ramda";
3
- import { useDispatch } from "react-redux";
2
+ import { path, prop } from "ramda";
4
3
  import {
5
4
  findPluginByType,
6
5
  findPluginByIdentifier,
@@ -15,7 +14,6 @@ import { componentsLogger } from "../../Helpers/logger";
15
14
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
16
15
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
17
16
  import { useScreenAnalytics } from "@applicaster/zapp-react-native-utils/analyticsUtils/helpers/hooks";
18
- import { setAppStateHasFinishedTransitioning } from "@applicaster/zapp-react-native-redux/appState";
19
17
 
20
18
  const logger = componentsLogger.addSubsystem("ScreenResolver");
21
19
 
@@ -32,12 +30,13 @@ type Props = {
32
30
  nextFocusLeft?: React.Ref<any>;
33
31
  nextFocusUp?: React.Ref<any>;
34
32
  };
33
+ groupId?: string;
35
34
  };
36
35
 
37
36
  export function ScreenResolverComponent(props: Props) {
38
37
  useScreenAnalytics(props);
39
38
 
40
- const { screenType, screenId, screenData } = props;
39
+ const { screenType, screenId, screenData, groupId } = props;
41
40
 
42
41
  const { hookPlugin } = screenData || {};
43
42
 
@@ -53,11 +52,8 @@ export function ScreenResolverComponent(props: Props) {
53
52
 
54
53
  const [, setScreenContext] = ZappPipesScreenContext.useZappPipesContext();
55
54
 
56
- const dispatch = useDispatch();
57
-
58
55
  React.useEffect(() => {
59
56
  setScreenContext(rivers[screenId]);
60
- dispatch(setAppStateHasFinishedTransitioning());
61
57
  }, [screenId]);
62
58
 
63
59
  const ScreenPlugin =
@@ -81,6 +77,7 @@ export function ScreenResolverComponent(props: Props) {
81
77
  item={screenData}
82
78
  mode={mode === "PIP" ? "PIP" : "FULLSCREEN"}
83
79
  isModal={false}
80
+ groupId={groupId}
84
81
  />
85
82
  );
86
83
  }
@@ -91,21 +88,21 @@ export function ScreenResolverComponent(props: Props) {
91
88
  <HookRenderer
92
89
  screenData={screenData}
93
90
  focused={props.focused}
94
- parentFocus={props.parentFocus}
91
+ parentFocus={props.parentFocus as ParentFocus}
95
92
  />
96
93
  )
97
94
  );
98
95
  }
99
96
 
100
97
  const ScreenComponent =
101
- R.path(["module", "Component"], ScreenPlugin) ||
102
- R.prop("module", ScreenPlugin) ||
103
- R.prop("Component", ScreenPlugin) ||
98
+ path(["module", "Component"], ScreenPlugin) ||
99
+ prop("module", ScreenPlugin) ||
100
+ prop("Component", ScreenPlugin) ||
104
101
  ScreenPlugin;
105
102
 
106
103
  const configuration =
107
- R.prop("configuration", ScreenPlugin) ||
108
- R.prop("__plugin_configuration", ScreenComponent);
104
+ prop("configuration", ScreenPlugin) ||
105
+ prop("__plugin_configuration", ScreenComponent);
109
106
 
110
107
  if (ScreenComponent) {
111
108
  return (
@@ -78,7 +78,7 @@ export const getStyles = (config): Partial<TVTabsStyles> => {
78
78
  },
79
79
  tvos: {
80
80
  marginTop: -1,
81
- }
81
+ },
82
82
  }),
83
83
  },
84
84
  tabsBackground: {
@@ -17,9 +17,12 @@ type TrackedViewProps = {
17
17
  export const TrackedView = memo(function TrackedView(props: TrackedViewProps) {
18
18
  const children = props.children;
19
19
 
20
- const onPositionUpdated = useCallback((event: TrackedViewNativeProps) => {
21
- props?.onPositionUpdated(event.nativeEvent);
22
- }, []);
20
+ const onPositionUpdated = useCallback(
21
+ (event: TrackedViewNativeProps) => {
22
+ props.onPositionUpdated(event.nativeEvent);
23
+ },
24
+ [props.onPositionUpdated]
25
+ );
23
26
 
24
27
  if (isTV()) {
25
28
  return <View {...(props as any)}>{children}</View>;
@@ -1,12 +1,12 @@
1
1
  import React from "react";
2
- import {
3
- Animated,
4
- useWindowDimensions,
5
- ViewProps,
6
- ViewStyle,
7
- } from "react-native";
2
+ import { Animated, ViewProps, ViewStyle } from "react-native";
8
3
  import { useSafeAreaFrame } from "react-native-safe-area-context";
4
+
5
+ import { useScreenOrientationHandler } from "@applicaster/zapp-react-native-ui-components/Components/Screen/orientationHandler";
6
+
9
7
  import { PathnameContext } from "../../Contexts/PathnameContext";
8
+ import { ScreenDataContext } from "../../Contexts/ScreenDataContext";
9
+ import { ScreenContextProvider } from "../../Contexts/ScreenContext";
10
10
 
11
11
  type Props = {
12
12
  children: any;
@@ -16,6 +16,8 @@ type Props = {
16
16
  animating: boolean;
17
17
  contentStyle: ViewStyle;
18
18
  pathname: string;
19
+ isActive: boolean;
20
+ screenData: NavigationScreenData;
19
21
  };
20
22
 
21
23
  /**
@@ -38,34 +40,45 @@ export function Scene({
38
40
  animating,
39
41
  contentStyle,
40
42
  pathname,
43
+ isActive = false,
44
+ screenData,
41
45
  }: Props) {
46
+ const [initialScreenData, setInitialScreenData] = React.useState(screenData);
47
+
48
+ useScreenOrientationHandler({
49
+ screenData,
50
+ isActive,
51
+ });
52
+
53
+ React.useLayoutEffect(() => {
54
+ if (isActive) {
55
+ setInitialScreenData(screenData);
56
+ }
57
+ }, [screenData, isActive]);
58
+
42
59
  const frame = useSafeAreaFrame();
43
- const { height, width } = useWindowDimensions();
60
+ const isAnimating = animating && overlayStyle;
44
61
 
45
- if (overlayStyle && animating) {
46
- // Safe frame takes too long to update,
47
- // so we can not rely on it there, and use height and width instead.
48
- return (
49
- <Animated.View
50
- pointerEvents={pointerEvents}
51
- style={[style, contentStyle, { height, width }]}
52
- >
53
- <PathnameContext.Provider value={pathname}>
54
- {children}
55
- </PathnameContext.Provider>
56
- <Animated.View style={overlayStyle} />
57
- </Animated.View>
58
- );
59
- }
62
+ const dimensions = isAnimating
63
+ ? {
64
+ width: "100%",
65
+ height: "100%",
66
+ }
67
+ : frame;
60
68
 
61
69
  return (
62
70
  <Animated.View
63
71
  pointerEvents={pointerEvents}
64
- style={[style, contentStyle, frame]}
72
+ style={[style, contentStyle, dimensions]}
65
73
  >
66
- <PathnameContext.Provider value={pathname}>
67
- {children}
68
- </PathnameContext.Provider>
74
+ <ScreenDataContext.Provider value={initialScreenData}>
75
+ <PathnameContext.Provider value={pathname}>
76
+ <ScreenContextProvider pathname={pathname}>
77
+ {children}
78
+ </ScreenContextProvider>
79
+ </PathnameContext.Provider>
80
+ </ScreenDataContext.Provider>
81
+ {isAnimating && <Animated.View style={overlayStyle} />}
69
82
  </Animated.View>
70
83
  );
71
84
  }
@@ -1,13 +1,10 @@
1
1
  import * as React from "react";
2
2
  import { View } from "react-native";
3
- import * as R from "ramda";
3
+ import { update, compose, tail, append, take, identity } from "ramda";
4
4
 
5
5
  import { AnimationManager } from "./AnimationManager";
6
6
  import { Scene } from "./Scene";
7
- import {
8
- getScreenOrientation,
9
- isOrientationCompatible,
10
- } from "@applicaster/zapp-react-native-utils/appUtils/orientationHelper";
7
+
11
8
  import {
12
9
  getSceneByRoute,
13
10
  shouldSkipAnimationForPreviousWebViewScene,
@@ -49,7 +46,7 @@ function prepareScene(children) {
49
46
  */
50
47
  function scenesForBackTransition(props: SceneProps, { scenes }) {
51
48
  return scenes.length > 1
52
- ? R.identity(scenes)
49
+ ? identity(scenes)
53
50
  : [prepareScene(props.children), scenes[0]];
54
51
  }
55
52
 
@@ -113,7 +110,7 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
113
110
  pushTransitionStart() {
114
111
  this.setState(
115
112
  {
116
- scenes: R.append(prepareScene(this.props.children), this.state.scenes),
113
+ scenes: append(prepareScene(this.props.children), this.state.scenes),
117
114
  ...this.animationManager.stateForAction(this.state, NAV_ACTION_PUSH),
118
115
  },
119
116
  () => {
@@ -169,21 +166,23 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
169
166
 
170
167
  transitionWithoutAnimation(resetState) {
171
168
  const { scenes } = this.state;
172
-
173
- const newState = resetState
174
- ? {
175
- scenes: [prepareScene(this.props.children)],
176
- to: {
177
- index: 0,
178
- },
179
- }
180
- : {
181
- scenes: R.update(
182
- scenes.length - 1,
183
- prepareScene(this.props.children),
184
- scenes
185
- ),
186
- };
169
+ const newScene = prepareScene(this.props.children);
170
+ const isLastSceneHook = scenes[scenes.length - 1].key.startsWith("/hook");
171
+
172
+ let newState;
173
+
174
+ if (resetState) {
175
+ newState = {
176
+ scenes: [newScene],
177
+ to: { index: 0 },
178
+ };
179
+ } else if (isLastSceneHook || scenes.length === 1) {
180
+ newState = { scenes: update(scenes.length - 1, newScene, scenes) };
181
+ } else {
182
+ newState = {
183
+ scenes: compose(tail, append(newScene))(scenes),
184
+ };
185
+ }
187
186
 
188
187
  this.setState(newState);
189
188
  }
@@ -226,7 +225,10 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
226
225
  this.shouldSkipAnimationForRoute(previousRoute) ||
227
226
  this.shouldSkipAnimationForRoute(currentRoute)
228
227
  ) {
229
- return this.transitionWithoutAnimation();
228
+ // we are going back, in this case we need to have only one scene using resetState
229
+ const resetState = isGoingBack ? true : undefined;
230
+
231
+ return this.transitionWithoutAnimation(resetState);
230
232
  }
231
233
 
232
234
  switch (this.props.navigator.previousAction) {
@@ -269,7 +271,7 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
269
271
  backTransitionEnd(stepsBack) {
270
272
  this.setState({
271
273
  animating: false,
272
- scenes: R.take(this.state.scenes.length - stepsBack, this.state.scenes),
274
+ scenes: take(this.state.scenes.length - stepsBack, this.state.scenes),
273
275
  });
274
276
  }
275
277
 
@@ -277,33 +279,25 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
277
279
  // so only a single scene should be rendered,
278
280
  // instead of dangerous nulls or duplicates.
279
281
  renderSingleScene({ scenes, to }) {
280
- const { contentStyle, layoutData } = this.props;
281
- const screenData = scenes[to.index]?.children?.props?.screenData;
282
-
283
- const orientation = getScreenOrientation({
284
- screenData,
285
- layoutData,
286
- });
282
+ const { contentStyle } = this.props;
283
+ const screenData = this.props.children.props.screenData;
284
+ const pathname = scenes[to.index].key;
287
285
 
288
- // We prevent rendering of the screen until UI is actually rotated to screen desired orientation.
289
- // This saves unnecessary re-renders and user will not see distorted aspect screen.
290
286
  return (
291
287
  <View style={styles.container}>
292
- {scenes[to.index] &&
293
- isOrientationCompatible({
294
- orientation,
295
- layoutData,
296
- }) && (
297
- <Scene
298
- {...{ style: to.style }}
299
- pathname={scenes[to.index].key}
300
- contentStyle={contentStyle}
301
- key={scenes[to.index].key}
302
- screenUniqueId={scenes[to.index].screenUniqueId}
303
- >
304
- {scenes[to.index].children}
305
- </Scene>
306
- )}
288
+ {scenes[to.index] && (
289
+ <Scene
290
+ {...{ style: to?.style || {} }}
291
+ pathname={pathname}
292
+ isActive={pathname === this.props.navigator.currentRoute}
293
+ contentStyle={contentStyle}
294
+ key={scenes[to.index].key}
295
+ screenUniqueId={scenes[to.index].screenUniqueId}
296
+ screenData={screenData}
297
+ >
298
+ {scenes[to.index].children}
299
+ </Scene>
300
+ )}
307
301
  </View>
308
302
  );
309
303
  }
@@ -319,12 +313,14 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
319
313
  <Scene
320
314
  key={scenes[from.index].key}
321
315
  pathname={scenes[from.index].key}
316
+ isActive={scenes[from.index].key === this.props.navigator.currentRoute}
322
317
  style={from.style}
323
318
  pointerEvents="none"
324
319
  overlayStyle={from.overlayStyle}
325
320
  animating={this.state.animating}
326
321
  contentStyle={contentStyle}
327
322
  screenUniqueId={scenes[from.index].screenUniqueId}
323
+ screenData={scenes[from.index].children.props.screenData}
328
324
  >
329
325
  {scenes[from.index].children}
330
326
  </Scene>
@@ -333,12 +329,14 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
333
329
  const toScene = scenes[to.index] && (
334
330
  <Scene
335
331
  pathname={scenes[to.index].key}
332
+ isActive={scenes[to.index].key === this.props.navigator.currentRoute}
336
333
  key={scenes[to.index].key}
337
334
  style={to.style}
338
335
  overlayStyle={to.overlayStyle}
339
336
  animating={this.state.animating}
340
337
  contentStyle={contentStyle}
341
338
  screenUniqueId={scenes[to.index].screenUniqueId}
339
+ screenData={this.props.children.props.screenData}
342
340
  >
343
341
  {scenes[to.index].children}
344
342
  </Scene>
@@ -16,6 +16,13 @@ jest.mock("react-native-safe-area-context", () => ({
16
16
  })),
17
17
  }));
18
18
 
19
+ jest.mock(
20
+ "@applicaster/zapp-react-native-ui-components/Components/Screen/orientationHandler",
21
+ () => ({
22
+ useScreenOrientationHandler: jest.fn(),
23
+ })
24
+ );
25
+
19
26
  const { Scene } = require("../Scene");
20
27
 
21
28
  const wrapper = shallow(
@@ -21,7 +21,11 @@ exports[`<Scene /> renders correctly 1`] = `
21
21
  ]
22
22
  }
23
23
  >
24
- <ContextProvider />
24
+ <ContextProvider>
25
+ <ContextProvider>
26
+ <ScreenContextProvider />
27
+ </ContextProvider>
28
+ </ContextProvider>
25
29
  </ForwardRef(AnimatedComponentWrapper)>
26
30
  `;
27
31
 
@@ -37,13 +41,17 @@ exports[`<Scene /> renders the overlay while animating 1`] = `
37
41
  "paddingBottom": 49,
38
42
  },
39
43
  Object {
40
- "height": 1334,
41
- "width": 750,
44
+ "height": "100%",
45
+ "width": "100%",
42
46
  },
43
47
  ]
44
48
  }
45
49
  >
46
- <ContextProvider />
50
+ <ContextProvider>
51
+ <ContextProvider>
52
+ <ScreenContextProvider />
53
+ </ContextProvider>
54
+ </ContextProvider>
47
55
  <ForwardRef(AnimatedComponentWrapper)
48
56
  style={
49
57
  Object {
@@ -10,7 +10,9 @@ exports[`<TransitionerComponent /> renders correctly 1`] = `
10
10
  }
11
11
  >
12
12
  <Scene
13
+ isActive={true}
13
14
  screenUniqueId="mocked-uuid"
15
+ style={Object {}}
14
16
  >
15
17
  <View
16
18
  foo="bar"