esoftplay 0.0.125-c → 0.0.125-d
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,17 +1,79 @@
|
|
|
1
1
|
// withHooks
|
|
2
2
|
// noPage
|
|
3
3
|
|
|
4
|
-
import
|
|
5
|
-
import
|
|
4
|
+
import NavigationContainerRefContext from '@react-navigation/core/src/NavigationContainerRefContext';
|
|
5
|
+
import NavigationContext from '@react-navigation/core/src/NavigationContext';
|
|
6
|
+
import type { NavigationProp } from '@react-navigation/core/src/types';
|
|
7
|
+
import React, { useRef, useState } from 'react';
|
|
8
|
+
import { KeyboardAvoidingView, Platform, View } from 'react-native';
|
|
9
|
+
|
|
6
10
|
|
|
7
11
|
export interface LibKeyboard_avoidProps {
|
|
8
12
|
children?: any,
|
|
9
13
|
style?: any
|
|
10
14
|
}
|
|
11
15
|
export default function m(props: LibKeyboard_avoidProps): any {
|
|
16
|
+
|
|
17
|
+
const isFocussed = useIsFocused();
|
|
18
|
+
|
|
19
|
+
const Custom = isFocussed ? KeyboardAvoidingView : View
|
|
20
|
+
|
|
12
21
|
return (
|
|
13
|
-
<
|
|
22
|
+
<Custom enabled={isFocussed} behavior={Platform.OS == 'android' ? 'height' : 'padding'} style={[{ flex: 1 }, props.style]} >
|
|
14
23
|
{props.children}
|
|
15
|
-
</
|
|
24
|
+
</Custom>
|
|
16
25
|
)
|
|
17
|
-
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Hook to access the navigation prop of the parent screen anywhere.
|
|
31
|
+
*
|
|
32
|
+
* @returns Navigation prop of the parent screen.
|
|
33
|
+
*/
|
|
34
|
+
function useNavigation<T = NavigationProp<ReactNavigation.RootParamList>>(): T {
|
|
35
|
+
const root = React.useContext(NavigationContainerRefContext);
|
|
36
|
+
const navigation = React.useContext(NavigationContext);
|
|
37
|
+
|
|
38
|
+
if (navigation === undefined && root === undefined) {
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
return (navigation ?? root) as unknown as T;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function useIsFocused(): boolean {
|
|
45
|
+
const navigation = useNavigation();
|
|
46
|
+
|
|
47
|
+
const forceTrue = useRef(false)
|
|
48
|
+
|
|
49
|
+
if (navigation == undefined) {
|
|
50
|
+
forceTrue.current = true
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const [isFocused, setIsFocused] = useState(navigation?.isFocused);
|
|
54
|
+
|
|
55
|
+
const valueToReturn = !!navigation?.isFocused?.();
|
|
56
|
+
|
|
57
|
+
if (isFocused !== valueToReturn) {
|
|
58
|
+
setIsFocused(valueToReturn);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
const unsubscribeFocus = navigation?.addListener?.('focus', () =>
|
|
63
|
+
setIsFocused(true)
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const unsubscribeBlur = navigation?.addListener?.('blur', () =>
|
|
67
|
+
setIsFocused(false)
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
return () => {
|
|
71
|
+
unsubscribeFocus?.();
|
|
72
|
+
unsubscribeBlur?.();
|
|
73
|
+
};
|
|
74
|
+
}, [navigation]);
|
|
75
|
+
|
|
76
|
+
React.useDebugValue(valueToReturn);
|
|
77
|
+
|
|
78
|
+
return (forceTrue.current || valueToReturn);
|
|
79
|
+
}
|