@jescon-technologies/react-native-ui-kit 0.0.13 → 0.0.14

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.
package/index.d.ts CHANGED
@@ -3,6 +3,9 @@ export { default as AAlertIOS } from './src/Alerts/AAlertIOS';
3
3
  export { default as AAlert } from './src/Alerts/AAlert';
4
4
  export { default as ABlink } from './src/Alerts/ABlink';
5
5
  export { default as HIcons } from './src/Hoc/HIcons';
6
+ export { default as HView } from './src/Hoc/HView';
7
+ export { default as Navigation } from './src/Navigation/PageNavigation';
8
+
6
9
  export { default as NetworkServiceCall } from './src/Common/NetworkServiceCall';
7
10
  export * from './src/Navigation/useNavigation';
8
11
  export { default as CBackHandler } from './src/CustomComponents/CBackHandler';
package/index.js CHANGED
@@ -3,6 +3,9 @@ export { default as AAlertIOS } from './src/Alerts/AAlertIOS';
3
3
  export { default as AAlert } from './src/Alerts/AAlert';
4
4
  export { default as ABlink } from './src/Alerts/ABlink';
5
5
  export { default as HIcons } from './src/Hoc/HIcons';
6
+ export { default as HView } from './src/Hoc/HView';
7
+ export { default as Navigation } from './src/Navigation/PageNavigation';
8
+
6
9
  export { default as NetworkServiceCall } from './src/Common/NetworkServiceCall';
7
10
  export * from './src/Navigation/useNavigation';
8
11
  export { default as CBackHandler } from './src/CustomComponents/CBackHandler';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jescon-technologies/react-native-ui-kit",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "A React Native module for Jescon Technologies that provides react-native-ui-kit",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -0,0 +1,33 @@
1
+ import React, { createContext, useContext } from 'react';
2
+ import type { ReactNode } from 'react';
3
+
4
+ interface HViewProps {
5
+ component?: string;
6
+ components?: Record<string, React.ComponentType<any>>;
7
+ children?: ReactNode;
8
+ [key: string]: any;
9
+ }
10
+
11
+ const ComponentsContext = createContext<
12
+ Record<string, React.ComponentType<any>> | undefined
13
+ >(undefined);
14
+
15
+ const HView: React.FC<HViewProps> = ({ component, components, ...props }) => {
16
+ const inheritedComponents = useContext(ComponentsContext);
17
+
18
+ if (!component) {
19
+ return components ? (
20
+ <ComponentsContext.Provider value={components}>
21
+ {props.children}
22
+ </ComponentsContext.Provider>
23
+ ) : (
24
+ <>{props.children}</>
25
+ );
26
+ }
27
+
28
+ const ViewHOCComponent = (components ?? inheritedComponents)?.[component];
29
+
30
+ return ViewHOCComponent ? <ViewHOCComponent {...props} /> : null;
31
+ };
32
+
33
+ export default HView;
@@ -0,0 +1,189 @@
1
+ import React, {
2
+ createContext,
3
+ useState,
4
+ useRef,
5
+ useEffect,
6
+ useContext,
7
+ ReactNode,
8
+ } from 'react';
9
+
10
+ import { View, Platform } from 'react-native';
11
+ import { NavigationContainer } from '@react-navigation/native';
12
+ import { createNativeStackNavigator } from '@react-navigation/native-stack';
13
+
14
+ type Route = {
15
+ name: string;
16
+ params?: any;
17
+ };
18
+
19
+ type NavigationContextType = {
20
+ navigate: (screenName: string, params?: any) => void;
21
+ replace: (screenName: string, params?: any) => void;
22
+ goBack: () => void;
23
+ addFocusListener: (screenName: string, callback: () => void) => () => void;
24
+ current: Route;
25
+ };
26
+
27
+ const NavigationContext = createContext<NavigationContextType | null>(null);
28
+
29
+ type NavigationScreens = Record<string, React.ComponentType<any>>;
30
+
31
+ type ProviderProps = {
32
+ screens: NavigationScreens;
33
+ children?: ReactNode;
34
+ };
35
+
36
+ export const NavigationProvider: React.FC<ProviderProps> = ({
37
+ screens,
38
+ children,
39
+ }) => {
40
+ const [stack, setStack] = useState<Route[]>([
41
+ { name: Object.keys(screens)[0], params: {} },
42
+ ]);
43
+
44
+ const focusListeners = useRef<Record<string, Array<() => void>>>({});
45
+
46
+ const current = stack[stack.length - 1];
47
+
48
+ const navigate = (screenName: string, params = {}) => {
49
+ setStack(prev => [...prev, { name: screenName, params }]);
50
+ };
51
+
52
+ const replace = (screenName: string, params = {}) => {
53
+ setStack(prev => [
54
+ ...prev.slice(0, -1),
55
+ { name: screenName, params },
56
+ ]);
57
+ };
58
+
59
+ const goBack = () => {
60
+ setStack(prev => (prev.length > 1 ? prev.slice(0, -1) : prev));
61
+ };
62
+
63
+ const addFocusListener = (screenName: string, callback: () => void) => {
64
+ if (!focusListeners.current[screenName]) {
65
+ focusListeners.current[screenName] = [];
66
+ }
67
+
68
+ focusListeners.current[screenName].push(callback);
69
+
70
+ return () => {
71
+ const listeners = focusListeners.current[screenName] || [];
72
+ focusListeners.current[screenName] = listeners.filter(
73
+ cb => cb !== callback
74
+ );
75
+ };
76
+ };
77
+
78
+ useEffect(() => {
79
+ const listeners = focusListeners.current[current.name] || [];
80
+ listeners.forEach(cb => cb());
81
+ }, [current.name]);
82
+
83
+ return (
84
+ <NavigationContext.Provider
85
+ value={{ navigate, goBack, replace, addFocusListener, current }}
86
+ >
87
+ <View style={{ flex: 1 }}>
88
+ {stack.map((route, index) => {
89
+ const ScreenComponent: React.ComponentType<any> = screens[route.name];
90
+ const isFocused = index === stack.length - 1;
91
+
92
+ return (
93
+ <View
94
+ key={index}
95
+ style={{
96
+ flex: 1,
97
+ display: isFocused ? 'flex' : 'none',
98
+ }}
99
+ >
100
+ <ScreenComponent
101
+ navigation={{ navigate, replace, goBack }}
102
+ route={{ params: route.params }}
103
+ />
104
+ </View>
105
+ );
106
+ })}
107
+
108
+ {children}
109
+ </View>
110
+ </NavigationContext.Provider>
111
+ );
112
+ };
113
+
114
+ export const useNavigation = () => {
115
+ const ctx = useContext(NavigationContext);
116
+ if (!ctx) {
117
+ throw new Error('useNavigation must be used inside NavigationProvider');
118
+ }
119
+ return ctx;
120
+ };
121
+
122
+ export const useFocusEffect = (callback: () => void | (() => void)) => {
123
+ const { current, addFocusListener } = useNavigation();
124
+ const cleanupRef = useRef<any>(null);
125
+
126
+ useEffect(() => {
127
+ cleanupRef.current?.();
128
+
129
+ const unsubscribe = addFocusListener(current.name, () => {
130
+ cleanupRef.current?.();
131
+ cleanupRef.current = callback();
132
+ });
133
+
134
+ return () => {
135
+ cleanupRef.current?.();
136
+ unsubscribe?.();
137
+ };
138
+ }, [current.name]);
139
+ };
140
+
141
+ export const useIsFocused = (): boolean => {
142
+ const { current, addFocusListener } = useNavigation();
143
+ const [isFocused, setIsFocused] = useState(true);
144
+
145
+ useEffect(() => {
146
+ setIsFocused(true);
147
+
148
+ const unsubscribe = addFocusListener(current.name, () => {
149
+ setIsFocused(true);
150
+ });
151
+
152
+ return () => {
153
+ setIsFocused(false);
154
+ unsubscribe();
155
+ };
156
+ }, [current.name]);
157
+
158
+ return isFocused;
159
+ };
160
+
161
+ export const ReactNativeNavigation: React.FC<{
162
+ screens: NavigationScreens;
163
+ }> = ({ screens }) => {
164
+ const Stack = createNativeStackNavigator();
165
+
166
+ return (
167
+ <NavigationContainer>
168
+ <Stack.Navigator
169
+ initialRouteName={Object.keys(screens)[0]}
170
+ screenOptions={{
171
+ animation: 'none',
172
+ headerShown: false,
173
+ }}
174
+ >
175
+ {Object.entries(screens).map(([name, component]) => (
176
+ <Stack.Screen key={name} name={name} component={component} />
177
+ ))}
178
+ </Stack.Navigator>
179
+ </NavigationContainer>
180
+ );
181
+ };
182
+
183
+ export default function Navigation({ screens }: { screens: NavigationScreens }) {
184
+ return Platform.OS === 'web' ? (
185
+ <NavigationProvider screens={screens} />
186
+ ) : (
187
+ <ReactNativeNavigation screens={screens} />
188
+ );
189
+ }
@@ -1,2 +1,2 @@
1
1
 
2
- export { useFocusEffect } from '../../../../../src/Navigation/PageNavigation';
2
+ export { useFocusEffect } from './PageNavigation';
@@ -1 +1 @@
1
- export { useFocusEffect } from '../../../../../src/Navigation/PageNavigation';
1
+ export { useFocusEffect } from './PageNavigation';
@@ -1 +1 @@
1
- export { useIsFocused } from '../../../../../src/Navigation/PageNavigation';
1
+ export { useIsFocused } from './PageNavigation';
@@ -1 +1 @@
1
- export { useIsFocused } from '../../../../../src/Navigation/PageNavigation';
1
+ export { useIsFocused } from './PageNavigation';
@@ -1,2 +1,2 @@
1
1
 
2
- export { useNavigation } from '../../../../../src/Navigation/PageNavigation';
2
+ export { useNavigation } from './PageNavigation';
@@ -1 +1 @@
1
- export { useNavigation } from '../../../../../src/Navigation/PageNavigation';
1
+ export { useNavigation } from './PageNavigation';
@@ -16,7 +16,7 @@ import {
16
16
  import RNFetchBlob from 'react-native-blob-util';
17
17
  import { Global } from '../../../../../src/Common/Global';
18
18
  import RNExitApp from 'react-native-exit-app';
19
- import HView from '../../../../../src/Hoc/HView';
19
+ import HView from '@jescon-technologies/react-native-ui-kit/src/Hoc/HView';
20
20
  import { APIURL } from '../../../../../src/Common/apiConstants';
21
21
  import { HIcons, useNavigation, normalize, isNU, Loader } from '@jescon-technologies/react-native-ui-kit';
22
22