@applicaster/zapp-react-native-ui-components 12.0.0-rc.72 → 12.0.0-rc.74

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.
@@ -12,7 +12,7 @@ jest.mock("../../../Screen/TV/index.web", () => ({
12
12
  Screen: View,
13
13
  }));
14
14
 
15
- const Layout = require("..").default;
15
+ const Layout = require("../index.web").default;
16
16
 
17
17
  const mockStore = configureStore()({
18
18
  appState: { appReady: true },
@@ -1,32 +1,129 @@
1
1
  import * as React from "react";
2
- import { pathOr } from "ramda";
3
-
2
+ import * as R from "ramda";
4
3
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
4
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
5
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
6
+
7
+ import {
8
+ getNavigationProps,
9
+ resolveNavigationPlugin,
10
+ routeIsPlayerScreen,
11
+ } from "@applicaster/zapp-react-native-utils/navigationUtils";
12
+
13
+ import { getBackgroundImageUrl } from "../utils";
14
+ import { LayoutContainer } from "./LayoutContainer";
15
+ import { NavBarContainer } from "./NavBarContainer";
16
+ import { ScreenContainer } from "./ScreenContainer";
5
17
 
6
18
  import { ScreenLayoutContextProvider } from "./ScreenLayoutContextProvider";
7
- import { StackNavigator } from "../../Navigator";
19
+ import { isApplePlatform } from "@applicaster/zapp-react-native-utils/reactUtils";
20
+ import { PathnameContext } from "../../../Contexts/PathnameContext";
21
+ import { useNavbarState } from "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext";
22
+ import { ScreenDataContext } from "../../../Contexts/ScreenDataContext";
8
23
 
9
24
  type Components = {
10
25
  NavBar: React.ComponentType<any>;
11
26
  Background: React.ComponentType<any>;
12
27
  };
13
28
 
29
+ type ComponentsExtraProps = {
30
+ Background?: Record<string, any>;
31
+ NavBar?: Record<string, any>;
32
+ };
33
+
14
34
  type Props = {
15
35
  Components: Components;
36
+ ComponentsExtraProps?: ComponentsExtraProps;
37
+ children: React.ReactNode;
16
38
  };
17
39
 
18
- const Layout = ({ Components }: Props) => {
19
- const { appState } = usePickFromState(["appState"]);
20
- const appReady = pathOr(false, ["appReady"], appState);
40
+ const Layout = ({ Components, ComponentsExtraProps, children }: Props) => {
41
+ const navigator = useNavigation();
42
+ const theme = useTheme();
43
+ const { title, visible } = useNavbarState();
44
+ const { activeRiver, currentRoute } = navigator;
45
+
46
+ const {
47
+ appState: { appReady = false } = {},
48
+ remoteConfigurations,
49
+ plugins = [],
50
+ } = usePickFromState(["appState", "remoteConfigurations", "plugins"]);
51
+
52
+ const navigationProps = getNavigationProps({
53
+ navigator,
54
+ title,
55
+ category: "menu",
56
+ });
57
+
58
+ const backgroundColor = React.useMemo(() => theme.app_background_color, []);
59
+
60
+ const backgroundImageUrl = React.useMemo(
61
+ () => getBackgroundImageUrl(remoteConfigurations),
62
+ [remoteConfigurations]
63
+ );
64
+
65
+ const menuPlugin = React.useMemo(
66
+ () =>
67
+ resolveNavigationPlugin({
68
+ category: "menu",
69
+ navigations: activeRiver?.navigations,
70
+ plugins,
71
+ }) as QuickBrickPlugin,
72
+ []
73
+ );
74
+
75
+ const NavBar = React.useMemo(
76
+ () => Components.NavBar || (menuPlugin.module as React.ComponentType<any>),
77
+ []
78
+ );
79
+
80
+ const [navBarReady, setNavBarReady] = React.useState(false);
81
+
82
+ const navBarContainer = (
83
+ <NavBarContainer isVisible={visible} onReady={setNavBarReady}>
84
+ <NavBar
85
+ ref={ComponentsExtraProps?.NavBar?.ref}
86
+ isVisible={visible && !routeIsPlayerScreen(currentRoute)}
87
+ menuPlugin={menuPlugin}
88
+ navigationProps={navigationProps}
89
+ {...R.omit(["ref"])(ComponentsExtraProps?.NavBar)}
90
+ />
91
+ </NavBarContainer>
92
+ );
93
+
94
+ const isTVOS = isApplePlatform();
21
95
 
22
96
  if (!appReady) {
23
97
  return null;
24
98
  }
25
99
 
26
100
  return (
27
- <ScreenLayoutContextProvider>
28
- <StackNavigator Components={Components} />
29
- </ScreenLayoutContextProvider>
101
+ <LayoutContainer>
102
+ <ScreenLayoutContextProvider>
103
+ <Components.Background
104
+ backgroundColor={backgroundColor}
105
+ backgroundImageUrl={backgroundImageUrl}
106
+ {...R.omit(["ref"])(ComponentsExtraProps?.Background)}
107
+ >
108
+ <ScreenDataContext.Provider value={navigator.data}>
109
+ <PathnameContext.Provider value={navigator.currentRoute}>
110
+ {!isTVOS ? navBarContainer : null}
111
+ {navBarReady ? (
112
+ /**
113
+ Need to re-mount this component on each navigation event
114
+ It's a hack to work around the fact that we don't support
115
+ correct screen rendering in our navigator (shared currentRoute state)
116
+ **/
117
+ <ScreenContainer>{children}</ScreenContainer>
118
+ ) : null}
119
+ {/** Render NavBarContainer over ScreenContainer to let tvOS native
120
+ focus manager works correctly to focus nav bar items first **/}
121
+ {isTVOS ? navBarContainer : null}
122
+ </PathnameContext.Provider>
123
+ </ScreenDataContext.Provider>
124
+ </Components.Background>
125
+ </ScreenLayoutContextProvider>
126
+ </LayoutContainer>
30
127
  );
31
128
  };
32
129
 
@@ -0,0 +1,33 @@
1
+ import * as React from "react";
2
+ import { pathOr } from "ramda";
3
+
4
+ import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
5
+
6
+ import { ScreenLayoutContextProvider } from "./ScreenLayoutContextProvider";
7
+ import { StackNavigator } from "../../Navigator";
8
+
9
+ type Components = {
10
+ NavBar: React.ComponentType<any>;
11
+ Background: React.ComponentType<any>;
12
+ };
13
+
14
+ type Props = {
15
+ Components: Components;
16
+ };
17
+
18
+ const Layout = ({ Components }: Props) => {
19
+ const { appState } = usePickFromState(["appState"]);
20
+ const appReady = pathOr(false, ["appReady"], appState);
21
+
22
+ if (!appReady) {
23
+ return null;
24
+ }
25
+
26
+ return (
27
+ <ScreenLayoutContextProvider>
28
+ <StackNavigator Components={Components} />
29
+ </ScreenLayoutContextProvider>
30
+ );
31
+ };
32
+
33
+ export default Layout;
@@ -1,8 +1,20 @@
1
1
  import * as React from "react";
2
- import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
2
+ import {
3
+ isTV,
4
+ platformSelect,
5
+ } from "@applicaster/zapp-react-native-utils/reactUtils";
3
6
 
4
7
  import Mobile from "./Mobile";
5
- import TV from "./TV";
8
+
9
+ import TVWeb from "./TV/index.web";
10
+ import TVDefault from "./TV/index";
11
+
12
+ const TV = platformSelect({
13
+ samsung_tv: TVWeb,
14
+ lg_tv: TVWeb,
15
+ web: TVWeb,
16
+ default: TVDefault,
17
+ });
6
18
 
7
19
  export default function Layout(props) {
8
20
  if (isTV()) {
@@ -2,6 +2,7 @@ import React, {
2
2
  createContext,
3
3
  ReactNode,
4
4
  useCallback,
5
+ useEffect,
5
6
  useMemo,
6
7
  useRef,
7
8
  } from "react";
@@ -113,6 +114,11 @@ export function ScreenContextProvider({
113
114
  return navBarState;
114
115
  }, []);
115
116
 
117
+ useEffect(() => {
118
+ // purge the getScreenNavBarState store when the pathname changes
119
+ screenNavBarStateRef.current = null;
120
+ }, [pathname]);
121
+
116
122
  const screenNavBarState = getScreenNavBarState()(
117
123
  useShallow((state) => ({
118
124
  visible: state.visible,
@@ -0,0 +1,20 @@
1
+ import React from "react";
2
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
3
+
4
+ export const ScreenDataContext = React.createContext<any>(null);
5
+
6
+ // Use this only to provide initial screenData context, before the Transitioner and Screen is rendered.
7
+ export const withScreenDataContextProvider = (Component: any) => {
8
+ return function ScreenDataContextProvider(props: any) {
9
+ const { activeRiver } = useNavigation();
10
+
11
+ // use only initial activeRiver as this context should only be used for "Home", initial route
12
+ const screenData = React.useMemo(() => ({ screen: activeRiver }), []);
13
+
14
+ return (
15
+ <ScreenDataContext.Provider value={screenData}>
16
+ <Component {...props} />
17
+ </ScreenDataContext.Provider>
18
+ );
19
+ };
20
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "12.0.0-rc.72",
3
+ "version": "12.0.0-rc.74",
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",
@@ -34,10 +34,10 @@
34
34
  "redux-mock-store": "^1.5.3"
35
35
  },
36
36
  "dependencies": {
37
- "@applicaster/applicaster-types": "12.0.0-rc.72",
38
- "@applicaster/zapp-react-native-bridge": "12.0.0-rc.72",
39
- "@applicaster/zapp-react-native-redux": "12.0.0-rc.72",
40
- "@applicaster/zapp-react-native-utils": "12.0.0-rc.72",
37
+ "@applicaster/applicaster-types": "12.0.0-rc.74",
38
+ "@applicaster/zapp-react-native-bridge": "12.0.0-rc.74",
39
+ "@applicaster/zapp-react-native-redux": "12.0.0-rc.74",
40
+ "@applicaster/zapp-react-native-utils": "12.0.0-rc.74",
41
41
  "promise": "^8.3.0",
42
42
  "react-router-native": "^5.1.2",
43
43
  "url": "^0.11.0",
@@ -1,3 +0,0 @@
1
- import React from "react";
2
-
3
- export const ScreenDataContext = React.createContext<any>(null);