@applicaster/zapp-react-native-ui-components 16.0.0-rc.6 → 16.0.0-rc.7

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.
@@ -0,0 +1,42 @@
1
+ import React from "react";
2
+ import { View, ViewStyle } from "react-native";
3
+
4
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
5
+ import {
6
+ selectRemoteConfigurations,
7
+ useAppSelector,
8
+ } from "@applicaster/zapp-react-native-redux";
9
+
10
+ import { getBackgroundImageUrl } from "../Layout/utils";
11
+
12
+ const baseBackgroundStyles = (imageUrl, backgroundColor) =>
13
+ ({
14
+ position: "absolute",
15
+ left: 0,
16
+ top: 0,
17
+ right: 0,
18
+ bottom: 0,
19
+ zIndex: -1,
20
+ backgroundSize: "cover",
21
+ background: imageUrl
22
+ ? `url(${imageUrl}) no-repeat top center ${backgroundColor}`
23
+ : backgroundColor,
24
+ }) as ViewStyle;
25
+
26
+ export const BackgroundImage = ({ children }: React.PropsWithChildren) => {
27
+ const theme = useTheme();
28
+
29
+ const remoteConfigurations = useAppSelector(selectRemoteConfigurations);
30
+
31
+ const backgroundColor = theme.app_background_color;
32
+ const backgroundImageUrl = getBackgroundImageUrl(remoteConfigurations);
33
+
34
+ return (
35
+ <View
36
+ id="background"
37
+ style={baseBackgroundStyles(backgroundImageUrl, backgroundColor)}
38
+ >
39
+ {children}
40
+ </View>
41
+ );
42
+ };
@@ -0,0 +1,28 @@
1
+ import * as React from "react";
2
+ import {
3
+ View,
4
+ StyleSheet,
5
+ ImageURISource,
6
+ ImageBackground,
7
+ } from "react-native";
8
+
9
+ import { ASSETS } from "@applicaster/zapp-react-native-ui-components/Helpers";
10
+
11
+ const imageSource: ImageURISource = {
12
+ uri: ASSETS.APP_BACKGROUND_IMAGE,
13
+ };
14
+
15
+ const styles = StyleSheet.create({
16
+ container: { flex: 1 },
17
+ backgroundImage: { width: "100%", height: "100%" },
18
+ });
19
+
20
+ export function BackgroundImage({ children }: React.PropsWithChildren) {
21
+ return (
22
+ <View style={styles.container}>
23
+ <ImageBackground style={styles.backgroundImage} source={imageSource}>
24
+ {children}
25
+ </ImageBackground>
26
+ </View>
27
+ );
28
+ }
@@ -0,0 +1,24 @@
1
+ import * as React from "react";
2
+ import { View, StyleSheet, ImageURISource } from "react-native";
3
+
4
+ import { QBImage as Image } from "@applicaster/zapp-react-native-ui-components/Components/Image";
5
+ import { ASSETS } from "@applicaster/zapp-react-native-ui-components/Helpers";
6
+
7
+ const imageSource: ImageURISource = {
8
+ uri: ASSETS.APP_BACKGROUND_IMAGE,
9
+ };
10
+
11
+ const styles = StyleSheet.create({
12
+ container: { flex: 1 },
13
+ backgroundImage: { width: "100%", height: "100%" },
14
+ });
15
+
16
+ export function BackgroundImage({ children }: React.PropsWithChildren) {
17
+ return (
18
+ <View style={styles.container}>
19
+ <Image style={styles.backgroundImage} source={imageSource}>
20
+ {children}
21
+ </Image>
22
+ </View>
23
+ );
24
+ }
@@ -0,0 +1 @@
1
+ export { BackgroundImage } from "./BackgroundImage";
@@ -2,7 +2,6 @@
2
2
 
3
3
  exports[`Layout TV renders 1`] = `
4
4
  <View
5
- backgroundColor="#000000"
6
5
  testID="background-component"
7
6
  >
8
7
  <View
@@ -1,6 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { useAppSelector } from "@applicaster/zapp-react-native-redux/hooks";
3
3
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
4
+ import { selectAppReady } from "@applicaster/zapp-react-native-redux";
4
5
 
5
6
  import { LayoutContainer } from "./LayoutContainer";
6
7
  import { ScreenContainer } from "./ScreenContainer";
@@ -9,8 +10,6 @@ import { ScreenLayoutContextProvider } from "./ScreenLayoutContextProvider";
9
10
  import { PathnameContext } from "../../../Contexts/PathnameContext";
10
11
  import { ScreenDataContext } from "../../../Contexts/ScreenDataContext";
11
12
  import { ScreenContextProvider } from "../../../Contexts/ScreenContext";
12
- import { LayoutBackground } from "./LayoutBackground";
13
- import { selectAppReady } from "@applicaster/zapp-react-native-redux";
14
13
 
15
14
  type Components = {
16
15
  NavBar: React.ComponentType<any>;
@@ -39,7 +38,7 @@ const Layout = ({ Components, ComponentsExtraProps, children }: Props) => {
39
38
  return (
40
39
  <LayoutContainer>
41
40
  <ScreenLayoutContextProvider>
42
- <LayoutBackground Background={Components.Background}>
41
+ <Components.Background>
43
42
  <ScreenDataContext.Provider value={navigator.data}>
44
43
  <PathnameContext.Provider value={navigator.currentRoute}>
45
44
  <ScreenContextProvider pathname={navigator.currentRoute}>
@@ -52,7 +51,7 @@ const Layout = ({ Components, ComponentsExtraProps, children }: Props) => {
52
51
  </ScreenContextProvider>
53
52
  </PathnameContext.Provider>
54
53
  </ScreenDataContext.Provider>
55
- </LayoutBackground>
54
+ </Components.Background>
56
55
  </ScreenLayoutContextProvider>
57
56
  </LayoutContainer>
58
57
  );
@@ -4,7 +4,6 @@ import { useAppSelector } from "@applicaster/zapp-react-native-redux/hooks";
4
4
 
5
5
  import { ScreenLayoutContextProvider } from "./ScreenLayoutContextProvider";
6
6
  import { StackNavigator } from "../../Navigator";
7
- import { LayoutBackground } from "./LayoutBackground";
8
7
  import { selectAppReady } from "@applicaster/zapp-react-native-redux";
9
8
 
10
9
  type Components = {
@@ -25,9 +24,9 @@ const Layout = ({ Components }: Props) => {
25
24
 
26
25
  return (
27
26
  <ScreenLayoutContextProvider>
28
- <LayoutBackground Background={Components.Background}>
27
+ <Components.Background>
29
28
  <StackNavigator Components={Components} />
30
- </LayoutBackground>
29
+ </Components.Background>
31
30
  </ScreenLayoutContextProvider>
32
31
  );
33
32
  };
@@ -0,0 +1,34 @@
1
+ import * as React from "react";
2
+ import { Animated, StyleSheet } from "react-native";
3
+
4
+ import { BackgroundImage } from "@applicaster/zapp-react-native-ui-components/Components/BackgroundImage";
5
+
6
+ const styles = StyleSheet.create({
7
+ container: {
8
+ ...StyleSheet.absoluteFillObject,
9
+ position: "absolute",
10
+ },
11
+ });
12
+
13
+ export const Overlay = ({
14
+ opacity,
15
+ backgroundColor,
16
+ }: {
17
+ opacity: Animated.Value;
18
+ backgroundColor: string;
19
+ }) => {
20
+ return (
21
+ <Animated.View
22
+ style={[
23
+ styles.container,
24
+ {
25
+ opacity,
26
+ backgroundColor,
27
+ },
28
+ ]}
29
+ testID="animated-component"
30
+ >
31
+ <BackgroundImage />
32
+ </Animated.View>
33
+ );
34
+ };
@@ -0,0 +1,88 @@
1
+ import React from "react";
2
+ import { Animated } from "react-native";
3
+ import { render } from "@testing-library/react-native";
4
+
5
+ jest.mock(
6
+ "@applicaster/zapp-react-native-ui-components/Components/BackgroundImage",
7
+ () => {
8
+ const { Text } = require("react-native");
9
+
10
+ return {
11
+ BackgroundImage: () => (
12
+ <Text testID="background-image">BackgroundImage</Text>
13
+ ),
14
+ };
15
+ }
16
+ );
17
+
18
+ import { Overlay } from "../Overlay";
19
+
20
+ const flattenStyle = (style: unknown): Record<string, unknown> => {
21
+ if (!style) {
22
+ return {};
23
+ }
24
+
25
+ if (Array.isArray(style)) {
26
+ return style.reduce<Record<string, unknown>>(
27
+ (acc, item) => ({ ...acc, ...flattenStyle(item) }),
28
+ {}
29
+ );
30
+ }
31
+
32
+ if (typeof style === "object") {
33
+ return style as Record<string, unknown>;
34
+ }
35
+
36
+ return {};
37
+ };
38
+
39
+ describe("Overlay", () => {
40
+ it("renders the animated overlay container", () => {
41
+ const opacity = new Animated.Value(1);
42
+
43
+ const { getByTestId } = render(
44
+ <Overlay opacity={opacity} backgroundColor="#000000" />
45
+ );
46
+
47
+ expect(getByTestId("animated-component")).toBeTruthy();
48
+ });
49
+
50
+ it("applies opacity and backgroundColor to the overlay", () => {
51
+ const opacity = new Animated.Value(0.5);
52
+
53
+ const { getByTestId } = render(
54
+ <Overlay opacity={opacity} backgroundColor="#ff0000" />
55
+ );
56
+
57
+ const style = flattenStyle(getByTestId("animated-component").props.style);
58
+
59
+ expect(style.backgroundColor).toBe("#ff0000");
60
+ expect(style.opacity).toBe(0.5);
61
+ });
62
+
63
+ it("positions the overlay with absolute fill layout", () => {
64
+ const opacity = new Animated.Value(1);
65
+
66
+ const { getByTestId } = render(
67
+ <Overlay opacity={opacity} backgroundColor="#000000" />
68
+ );
69
+
70
+ const style = flattenStyle(getByTestId("animated-component").props.style);
71
+
72
+ expect(style.position).toBe("absolute");
73
+ expect(style.top).toBe(0);
74
+ expect(style.left).toBe(0);
75
+ expect(style.right).toBe(0);
76
+ expect(style.bottom).toBe(0);
77
+ });
78
+
79
+ it("renders BackgroundImage inside the overlay", () => {
80
+ const opacity = new Animated.Value(1);
81
+
82
+ const { getByTestId } = render(
83
+ <Overlay opacity={opacity} backgroundColor="#000000" />
84
+ );
85
+
86
+ expect(getByTestId("background-image")).toBeTruthy();
87
+ });
88
+ });
@@ -1,8 +1,10 @@
1
1
  import * as React from "react";
2
- import { Animated, StyleSheet } from "react-native";
2
+ import { Animated } from "react-native";
3
+
3
4
  import { isFirstComponentScreenPicker } from "@applicaster/zapp-react-native-utils/componentsUtils";
4
5
  import { useRefWithInitialValue } from "@applicaster/zapp-react-native-utils/reactHooks/state/useRefWithInitialValue";
5
6
  import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
7
+ import { Overlay } from "./Overlay";
6
8
 
7
9
  import { ScreenRevealManager } from "./ScreenRevealManager";
8
10
  import {
@@ -10,13 +12,6 @@ import {
10
12
  emitScreenRevealManagerIsNotReadyToShow,
11
13
  } from "./utils";
12
14
 
13
- const styles = StyleSheet.create({
14
- container: {
15
- ...StyleSheet.absoluteFillObject,
16
- position: "absolute",
17
- },
18
- });
19
-
20
15
  export const TIMEOUT = 300; // 300 ms
21
16
 
22
17
  const HIDDEN = 0; // opacity = 0
@@ -93,17 +88,11 @@ export const withScreenRevealManager = (Component) => {
93
88
  onLoadFailedFromScreenRevealManager={managerRef.current.onLoadFailed}
94
89
  />
95
90
  {isShowOverlay ? (
96
- <Animated.View
97
- style={[
98
- styles.container,
99
- {
100
- opacity: opacityRef.current,
101
- // TODO: we should support background image as well, but for now we will use background color from theme
102
- backgroundColor:
103
- props.backgroundColor ?? theme.app_background_color,
104
- },
105
- ]}
106
- testID="animated-component"
91
+ <Overlay
92
+ opacity={opacityRef.current}
93
+ backgroundColor={
94
+ props.backgroundColor ?? theme.app_background_color
95
+ }
107
96
  />
108
97
  ) : null}
109
98
  </>
package/Helpers/index.js CHANGED
@@ -1,5 +1,11 @@
1
+ import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
2
+
1
3
  export const ASSETS = {
2
- APP_BACKGROUND_IMAGE: "app_background_image",
4
+ APP_BACKGROUND_IMAGE: platformSelect({
5
+ tvos: "app_background_image",
6
+ android_tv: "tv_app_background",
7
+ amazon: "tv_app_background",
8
+ }),
3
9
  };
4
10
 
5
11
  export const ANALYTICS_CORE_EVENTS = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "16.0.0-rc.6",
3
+ "version": "16.0.0-rc.7",
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": "16.0.0-rc.6",
32
- "@applicaster/zapp-react-native-bridge": "16.0.0-rc.6",
33
- "@applicaster/zapp-react-native-redux": "16.0.0-rc.6",
34
- "@applicaster/zapp-react-native-utils": "16.0.0-rc.6",
31
+ "@applicaster/applicaster-types": "16.0.0-rc.7",
32
+ "@applicaster/zapp-react-native-bridge": "16.0.0-rc.7",
33
+ "@applicaster/zapp-react-native-redux": "16.0.0-rc.7",
34
+ "@applicaster/zapp-react-native-utils": "16.0.0-rc.7",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "url": "^0.11.0",
@@ -1,31 +0,0 @@
1
- import React from "react";
2
- import { getBackgroundImageUrl } from "../utils";
3
- import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
4
- import {
5
- selectRemoteConfigurations,
6
- useAppSelector,
7
- } from "@applicaster/zapp-react-native-redux";
8
-
9
- export const LayoutBackground = ({
10
- Background,
11
- children,
12
- }: {
13
- Background: React.ComponentType<any>;
14
- children: React.ReactNode;
15
- }) => {
16
- const theme = useTheme();
17
-
18
- const remoteConfigurations = useAppSelector(selectRemoteConfigurations);
19
-
20
- const backgroundColor = theme.app_background_color;
21
- const backgroundImageUrl = getBackgroundImageUrl(remoteConfigurations);
22
-
23
- return (
24
- <Background
25
- backgroundColor={backgroundColor}
26
- backgroundImageUrl={backgroundImageUrl}
27
- >
28
- {children}
29
- </Background>
30
- );
31
- };