@applicaster/zapp-react-native-ui-components 14.0.7-rc.2 → 14.0.9-alpha.2354002522

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,16 +1,18 @@
1
- import { useLayoutEffect } from "react";
1
+ import React, { useLayoutEffect } from "react";
2
2
 
3
3
  import {
4
4
  allowedOrientationsForScreen,
5
- getOrientation,
6
5
  ORIENTATIONS,
6
+ getOrientation,
7
7
  useGetScreenOrientation,
8
8
  } from "@applicaster/zapp-react-native-utils/appUtils/orientationHelper";
9
9
  import { usePrevious } from "@applicaster/zapp-react-native-utils/reactHooks/utils";
10
10
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
11
11
  import { findPluginByType } from "@applicaster/zapp-react-native-utils/pluginUtils";
12
12
  import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
13
- import { zappHookModalStore } from "../../Contexts/ZappHookModalContext";
13
+
14
+ import { ZappHookModalContext } from "../../Contexts";
15
+ import { HookModalContextT } from "../../Contexts/ZappHookModalContext";
14
16
 
15
17
  /**
16
18
  * This function calls the native module needed to set orientation
@@ -87,6 +89,10 @@ type Props = {
87
89
  };
88
90
 
89
91
  export function useScreenOrientationHandler({ screenData, isActive }: Props) {
92
+ const { isHooksExecutionInProgress } = React.useContext<HookModalContextT>(
93
+ ZappHookModalContext.ReactContext
94
+ );
95
+
90
96
  const prevIsActive = usePrevious(isActive);
91
97
 
92
98
  const newOrientation = useNewOrientationForScreenData({
@@ -99,9 +105,6 @@ export function useScreenOrientationHandler({ screenData, isActive }: Props) {
99
105
  return;
100
106
  }
101
107
 
102
- // TODO: make sure it can be static getter and subscription is not needed
103
- const { isHooksExecutionInProgress } = zappHookModalStore.getState();
104
-
105
108
  // If modal hook presented we need to skip
106
109
  // Change orientation for presenter screen
107
110
  if (isHooksExecutionInProgress) {
@@ -113,7 +116,7 @@ export function useScreenOrientationHandler({ screenData, isActive }: Props) {
113
116
 
114
117
  setOrientation(newOrientation);
115
118
  }
116
- }, [newOrientation, prevIsActive, isActive]);
119
+ }, [newOrientation, isHooksExecutionInProgress, prevIsActive, isActive]);
117
120
  }
118
121
 
119
122
  export function useOrientationHandler({ screenData }: OrientationHookArgs) {
@@ -1,4 +1,4 @@
1
- import { create } from "zustand";
1
+ import React, { useCallback } from "react";
2
2
 
3
3
  type HookModalState = {
4
4
  path: string;
@@ -10,12 +10,11 @@ export type HookModalContextT = {
10
10
  setIsHooksExecutionInProgress: (hookExecutionState?: boolean) => void;
11
11
  isRunningInBackground: boolean;
12
12
  isPresentationFullScreen: boolean;
13
- setIsRunningInBackground: () => void;
14
- setIsPresentingFullScreen: () => void;
13
+ setIsRunningInBackground: (hookBackgroundProcessState?: boolean) => void;
14
+ setIsPresentingFullScreen: (hookBackgroundProcessState?: boolean) => void;
15
15
  state: HookModalState;
16
16
  setState: (state: HookModalState) => void;
17
17
  resetState: () => void;
18
- hookPresentationMode: HookPresentationMode;
19
18
  };
20
19
 
21
20
  const initialState = {
@@ -25,43 +24,68 @@ const initialState = {
25
24
 
26
25
  type HookPresentationMode = "background" | "fullScreen";
27
26
 
28
- // Use useZappHookModalStore() in React components (hooks)
29
- // Use zappHookModalStore.getState() in non-React functions (utility functions, etc.)
30
- export const useZappHookModalStore = create<HookModalContextT>()((set) => ({
31
- state: initialState,
27
+ const ReactContext = React.createContext<HookModalContextT>({
32
28
  isHooksExecutionInProgress: false,
33
- hookPresentationMode: null as HookPresentationMode,
34
- isRunningInBackground: false,
35
- isPresentationFullScreen: false,
29
+ setIsHooksExecutionInProgress: () => {},
30
+ isRunningInBackground: null,
31
+ setIsRunningInBackground: () => {},
32
+ setIsPresentingFullScreen: () => {},
33
+ isPresentationFullScreen: null,
34
+ state: initialState,
35
+ setState: () => null,
36
+ resetState: () => null,
37
+ });
38
+
39
+ const Provider = ({ children }: { children: React.ReactNode }) => {
40
+ const [state, setState] = React.useState<HookModalState>(initialState);
41
+
42
+ const [hookPresentationMode, setHookPresentationMode] =
43
+ React.useState<HookPresentationMode>(null);
36
44
 
37
- setState: (newState: HookModalState) => {
38
- set({ state: newState });
39
- },
45
+ const resetState = useCallback(() => {
46
+ setState(initialState);
47
+ }, [setState]);
40
48
 
41
- setIsHooksExecutionInProgress: (hookExecutionState?: boolean) => {
42
- set({ isHooksExecutionInProgress: hookExecutionState ?? false });
43
- },
49
+ const [isHooksExecutionInProgress, setIsHooksExecutionInProgress] =
50
+ React.useState(false);
44
51
 
45
- setIsRunningInBackground: () => {
46
- set({
47
- hookPresentationMode: "background",
48
- isRunningInBackground: true,
49
- isPresentationFullScreen: false,
50
- });
51
- },
52
+ const setIsRunningInBackground = () => {
53
+ setHookPresentationMode("background");
54
+ };
52
55
 
53
- setIsPresentingFullScreen: () => {
54
- set({
55
- hookPresentationMode: "fullScreen",
56
- isRunningInBackground: false,
57
- isPresentationFullScreen: true,
58
- });
59
- },
56
+ const setIsPresentingFullScreen = () => {
57
+ setHookPresentationMode("fullScreen");
58
+ };
60
59
 
61
- resetState: () => {
62
- set({ state: initialState });
63
- },
64
- }));
60
+ return (
61
+ <ReactContext.Provider
62
+ value={{
63
+ isRunningInBackground: hookPresentationMode === "background",
64
+ setIsRunningInBackground,
65
+ setIsPresentingFullScreen,
66
+ isPresentationFullScreen: hookPresentationMode === "fullScreen",
67
+ isHooksExecutionInProgress,
68
+ setIsHooksExecutionInProgress,
69
+ state,
70
+ setState,
71
+ resetState,
72
+ }}
73
+ >
74
+ {children}
75
+ </ReactContext.Provider>
76
+ );
77
+ };
78
+
79
+ const withProvider = (Component) => {
80
+ const WithProvider = (props) => {
81
+ return (
82
+ <Provider>
83
+ <Component {...props} />
84
+ </Provider>
85
+ );
86
+ };
87
+
88
+ return WithProvider;
89
+ };
65
90
 
66
- // Export an alias for clearer non-React usage (utility functions, etc.)
67
- export const zappHookModalStore = useZappHookModalStore;
91
+ export const ZappHookModalContext = { withProvider, ReactContext };
package/Contexts/index.ts CHANGED
@@ -12,6 +12,8 @@ export { HorizontalScrollContext } from "./HorizontalScrollContext";
12
12
 
13
13
  export { RiverOffsetContext } from "./RiverOffsetContext";
14
14
 
15
+ export { ZappHookModalContext } from "./ZappHookModalContext";
16
+
15
17
  export { MeasurementContext } from "./MeasurementContext";
16
18
 
17
19
  export * from "./ZappPipesContext";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "14.0.7-rc.2",
3
+ "version": "14.0.9-alpha.2354002522",
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": "14.0.7-rc.2",
32
- "@applicaster/zapp-react-native-bridge": "14.0.7-rc.2",
33
- "@applicaster/zapp-react-native-redux": "14.0.7-rc.2",
34
- "@applicaster/zapp-react-native-utils": "14.0.7-rc.2",
31
+ "@applicaster/applicaster-types": "14.0.9-alpha.2354002522",
32
+ "@applicaster/zapp-react-native-bridge": "14.0.9-alpha.2354002522",
33
+ "@applicaster/zapp-react-native-redux": "14.0.9-alpha.2354002522",
34
+ "@applicaster/zapp-react-native-utils": "14.0.9-alpha.2354002522",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "url": "^0.11.0",