react-native-auto-positioned-popup 1.2.14 → 1.2.17
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/lib/AutoPositionedPopup.d.ts.map +1 -1
- package/lib/AutoPositionedPopup.js +257 -307
- package/lib/AutoPositionedPopup.js.map +1 -1
- package/lib/AutoPositionedPopup.style.d.ts.map +1 -1
- package/lib/AutoPositionedPopup.style.js +2 -0
- package/lib/AutoPositionedPopup.style.js.map +1 -1
- package/lib/KeyboardManager.d.ts.map +1 -1
- package/lib/KeyboardManager.js +14 -6
- package/lib/KeyboardManager.js.map +1 -1
- package/lib/RootViewContext.d.ts.map +1 -1
- package/lib/RootViewContext.js +19 -8
- package/lib/RootViewContext.js.map +1 -1
- package/lib/constants.js +13 -0
- package/package.json +4 -4
- package/src/AutoPositionedPopup.style.ts +2 -0
- package/src/AutoPositionedPopup.tsx +292 -342
- package/src/KeyboardManager.tsx +14 -6
- package/src/RootViewContext.tsx +19 -8
package/src/KeyboardManager.tsx
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import React, { useEffect, useState, useRef } from 'react';
|
|
2
2
|
import { Keyboard, EmitterSubscription, Platform } from 'react-native';
|
|
3
3
|
|
|
4
|
+
// DEBUG FLAG: Set to false to disable all console logs for better performance
|
|
5
|
+
const KEYBOARD_DEBUG = false;
|
|
6
|
+
const debugLog = (...args: any[]) => {
|
|
7
|
+
if (KEYBOARD_DEBUG) {
|
|
8
|
+
console.log(...args);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
4
12
|
// Debounce function
|
|
5
13
|
const debounce = (func: Function, delay: number) => {
|
|
6
14
|
let timer: NodeJS.Timeout;
|
|
@@ -25,13 +33,13 @@ export const useKeyboardStatus = () => {
|
|
|
25
33
|
|
|
26
34
|
// ✅ FIX: Check state before debounce
|
|
27
35
|
if (currentKeyboardStatusRef.current === value) {
|
|
28
|
-
|
|
36
|
+
debugLog('KeyboardManager: Skip - Keyboard state unchanged (before debounce)', { value, timeSinceLastUpdate });
|
|
29
37
|
return;
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
// ✅ FIX: Skip if the same value is already pending
|
|
33
41
|
if (pendingValueRef.current === value) {
|
|
34
|
-
|
|
42
|
+
debugLog('KeyboardManager: Skip - Same value already in processing queue', { value });
|
|
35
43
|
return;
|
|
36
44
|
}
|
|
37
45
|
|
|
@@ -47,12 +55,12 @@ export const useKeyboardStatus = () => {
|
|
|
47
55
|
debounce((value: boolean, currentTime: number, timeSinceLastUpdate: number) => {
|
|
48
56
|
// ✅ FIX: Check state again (in case state was updated during debounce)
|
|
49
57
|
if (currentKeyboardStatusRef.current === value) {
|
|
50
|
-
|
|
58
|
+
debugLog('KeyboardManager: Skip - Keyboard state unchanged (after debounce)', { value, timeSinceLastUpdate });
|
|
51
59
|
pendingValueRef.current = null;
|
|
52
60
|
return;
|
|
53
61
|
}
|
|
54
62
|
|
|
55
|
-
|
|
63
|
+
debugLog('KeyboardManager: Setting keyboard status to', value, {
|
|
56
64
|
previousValue: currentKeyboardStatusRef.current,
|
|
57
65
|
timeSinceLastUpdate
|
|
58
66
|
});
|
|
@@ -78,7 +86,7 @@ export const useKeyboardStatus = () => {
|
|
|
78
86
|
() => {
|
|
79
87
|
// ✅ FIX: Add protection at event listener level - skip if keyboard is already open
|
|
80
88
|
if (currentKeyboardStatusRef.current === true) {
|
|
81
|
-
|
|
89
|
+
debugLog('KeyboardManager: Skip keyboardDidShow event - Keyboard is already open');
|
|
82
90
|
return;
|
|
83
91
|
}
|
|
84
92
|
debouncedSetKeyboardShown(true);
|
|
@@ -89,7 +97,7 @@ export const useKeyboardStatus = () => {
|
|
|
89
97
|
() => {
|
|
90
98
|
// ✅ FIX: Add protection at event listener level - skip if keyboard is already closed
|
|
91
99
|
if (currentKeyboardStatusRef.current === false) {
|
|
92
|
-
|
|
100
|
+
debugLog('KeyboardManager: Skip keyboardDidHide event - Keyboard is already closed');
|
|
93
101
|
return;
|
|
94
102
|
}
|
|
95
103
|
debouncedSetKeyboardShown(false);
|
package/src/RootViewContext.tsx
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import React, {ReactNode, createContext, useContext, useEffect, useMemo, useRef, useState} from 'react';
|
|
2
2
|
import {Pressable, View, ViewStyle, Keyboard} from 'react-native';
|
|
3
3
|
|
|
4
|
+
// DEBUG FLAG: Set to false to disable all console logs for better performance
|
|
5
|
+
const ROOTVIEW_DEBUG = false;
|
|
6
|
+
const debugLog = (...args: any[]) => {
|
|
7
|
+
if (ROOTVIEW_DEBUG) {
|
|
8
|
+
console.log(...args);
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
4
12
|
interface DynamicViewBase {
|
|
5
13
|
id: string;
|
|
6
14
|
style: ViewStyle;
|
|
@@ -35,13 +43,13 @@ export const RootViewProvider: React.FC<RootViewProviderProps> = ({children}) =>
|
|
|
35
43
|
const [searchQuery, setSearchQuery] = useState<string>('');
|
|
36
44
|
const viewRefs = useRef<Record<string, View>>({});
|
|
37
45
|
useEffect(() => {
|
|
38
|
-
|
|
46
|
+
debugLog('react-native-auto-positioned-popup RootViewProvider rootViews changed:', rootViews);
|
|
39
47
|
}, [rootViews]);
|
|
40
48
|
const addRootView = (view: DynamicViewBase): void => {
|
|
41
49
|
// const id = `dynamic-view-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
42
50
|
const newView: DynamicViewBase = {...view};
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
debugLog('react-native-auto-positioned-popup RootViewProvider addRootView rootViews=', rootViews);
|
|
52
|
+
debugLog('react-native-auto-positioned-popup RootViewProvider addRootView newView=', newView);
|
|
45
53
|
setRootViews((prev) => [...prev, newView]);
|
|
46
54
|
};
|
|
47
55
|
|
|
@@ -60,7 +68,7 @@ export const RootViewProvider: React.FC<RootViewProviderProps> = ({children}) =>
|
|
|
60
68
|
* @param _rootViews
|
|
61
69
|
*/
|
|
62
70
|
const removeRootView = (id?: string, force?: boolean, _rootViews?: DynamicViewBase[]): void => {
|
|
63
|
-
|
|
71
|
+
debugLog('react-native-auto-positioned-popup RootViewProvider removeRootView=', {id, force, rootViews, _rootViews});
|
|
64
72
|
// Ensure keyboard is dismissed when force removing all root views
|
|
65
73
|
if (force) {
|
|
66
74
|
// Dismiss keyboard first
|
|
@@ -70,14 +78,14 @@ export const RootViewProvider: React.FC<RootViewProviderProps> = ({children}) =>
|
|
|
70
78
|
// 100ms gives touch event system enough time to process pending events before views are removed
|
|
71
79
|
setTimeout(() => {
|
|
72
80
|
setRootViews((prev) => []);
|
|
73
|
-
|
|
81
|
+
debugLog('react-native-auto-positioned-popup RootViewProvider removeRootView setRootViews(prev => []) force=true');
|
|
74
82
|
}, 100);
|
|
75
83
|
return;
|
|
76
84
|
}
|
|
77
85
|
if (rootViews.length > 0 && id) {
|
|
78
86
|
setRootViews((prev) => prev.filter((view) => view.id !== id));
|
|
79
87
|
// else {
|
|
80
|
-
//
|
|
88
|
+
// debugLog('RootViewProvider removeRootView setRootViews(prev => [])')
|
|
81
89
|
// setRootViews(prev => [])
|
|
82
90
|
// }
|
|
83
91
|
} else if (_rootViews && _rootViews.length > 0 && id) {
|
|
@@ -86,10 +94,13 @@ export const RootViewProvider: React.FC<RootViewProviderProps> = ({children}) =>
|
|
|
86
94
|
};
|
|
87
95
|
|
|
88
96
|
const setRootViewNativeStyle = (id: string, style: ViewStyle): void => {
|
|
97
|
+
debugLog('RootViewContext setRootViewNativeStyle called=', {id, style});
|
|
89
98
|
const target = viewRefs.current[id];
|
|
99
|
+
debugLog('RootViewContext setRootViewNativeStyle target exists=', !!target);
|
|
90
100
|
if (target) {
|
|
91
101
|
// @ts-ignore - React Native setNativeProps
|
|
92
102
|
target.setNativeProps({style});
|
|
103
|
+
debugLog('RootViewContext setRootViewNativeStyle applied style=', style);
|
|
93
104
|
}
|
|
94
105
|
};
|
|
95
106
|
|
|
@@ -112,7 +123,7 @@ export const RootViewProvider: React.FC<RootViewProviderProps> = ({children}) =>
|
|
|
112
123
|
{children}
|
|
113
124
|
{rootViews.map(
|
|
114
125
|
({id, style, component, useModal, onModalClose, centerDisplay}: DynamicViewBase): React.JSX.Element => {
|
|
115
|
-
|
|
126
|
+
debugLog('react-native-auto-positioned-popup RootViewProvider rootViews.map=', {id, style, component, useModal, centerDisplay});
|
|
116
127
|
return !useModal ? (
|
|
117
128
|
<View
|
|
118
129
|
key={id}
|
|
@@ -141,7 +152,7 @@ export const RootViewProvider: React.FC<RootViewProviderProps> = ({children}) =>
|
|
|
141
152
|
centerDisplay && {justifyContent: 'center', alignItems: 'center'},
|
|
142
153
|
]}
|
|
143
154
|
onPress={() => {
|
|
144
|
-
|
|
155
|
+
debugLog('react-native-auto-positioned-popup RootViewProvider Pressable onPress rootViews=', rootViews);
|
|
145
156
|
removeRootView(id, true);
|
|
146
157
|
onModalClose && onModalClose();
|
|
147
158
|
}}
|