Skip to content
This repository was archived by the owner on Dec 3, 2022. It is now read-only.

Commit 0712009

Browse files
committed
Added some files that were left behind
1 parent 6994f95 commit 0712009

File tree

4 files changed

+121
-4
lines changed

4 files changed

+121
-4
lines changed

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
# VSCode
99
.vscode/
10-
tsconfig.json
1110
jsconfig.json
1211

1312
# Xcode
@@ -49,9 +48,6 @@ buck-out/
4948
android/app/libs
5049
android/keystores/debug.keystore
5150

52-
# Build
53-
dist/
54-
5551
# Test
5652
coverage/
5753
.jest/

dist/Hooks.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export declare function useNavigation(): {};
2+
export declare function useNavigationParam(paramName: any): any;
3+
export declare function useNavigationState(): any;
4+
export declare function useNavigationKey(): any;
5+
export declare function useNavigationEvents(handleEvt: any): void;
6+
export declare function useFocusState(): {
7+
isFocused: boolean;
8+
isBlurring: boolean;
9+
isBlurred: boolean;
10+
isFocusing: boolean;
11+
};

dist/Hooks.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"use strict";
2+
var __assign = (this && this.__assign) || function () {
3+
__assign = Object.assign || function(t) {
4+
for (var s, i = 1, n = arguments.length; i < n; i++) {
5+
s = arguments[i];
6+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7+
t[p] = s[p];
8+
}
9+
return t;
10+
};
11+
return __assign.apply(this, arguments);
12+
};
13+
Object.defineProperty(exports, "__esModule", { value: true });
14+
var react_1 = require("react");
15+
var core_1 = require("@react-navigation/core");
16+
function useNavigation() {
17+
return react_1.useContext(core_1.NavigationContext);
18+
}
19+
exports.useNavigation = useNavigation;
20+
function useNavigationParam(paramName) {
21+
return useNavigation().getParam(paramName);
22+
}
23+
exports.useNavigationParam = useNavigationParam;
24+
function useNavigationState() {
25+
return useNavigation().state;
26+
}
27+
exports.useNavigationState = useNavigationState;
28+
function useNavigationKey() {
29+
return useNavigation().state.key;
30+
}
31+
exports.useNavigationKey = useNavigationKey;
32+
function useNavigationEvents(handleEvt) {
33+
var navigation = useNavigation();
34+
react_1.useEffect(function () {
35+
var subsA = navigation.addListener('action', handleEvt);
36+
var subsWF = navigation.addListener('willFocus', handleEvt);
37+
var subsDF = navigation.addListener('didFocus', handleEvt);
38+
var subsWB = navigation.addListener('willBlur', handleEvt);
39+
var subsDB = navigation.addListener('didBlur', handleEvt);
40+
return function () {
41+
subsA.remove();
42+
subsWF.remove();
43+
subsDF.remove();
44+
subsWB.remove();
45+
subsDB.remove();
46+
};
47+
},
48+
// For TODO consideration: If the events are tied to the navigation object and the key
49+
// identifies the nav object, then we should probably pass [navigation.state.key] here, to
50+
// make sure react doesn't needlessly detach and re-attach this effect. In practice this
51+
// seems to cause troubles
52+
undefined);
53+
}
54+
exports.useNavigationEvents = useNavigationEvents;
55+
var emptyFocusState = {
56+
isFocused: false,
57+
isBlurring: false,
58+
isBlurred: false,
59+
isFocusing: false,
60+
};
61+
var didFocusState = __assign({}, emptyFocusState, { isFocused: true });
62+
var willBlurState = __assign({}, emptyFocusState, { isBlurring: true });
63+
var didBlurState = __assign({}, emptyFocusState, { isBlurred: true });
64+
var willFocusState = __assign({}, emptyFocusState, { isFocusing: true });
65+
var getInitialFocusState = function (isFocused) {
66+
return isFocused ? didFocusState : didBlurState;
67+
};
68+
function focusStateOfEvent(eventName) {
69+
switch (eventName) {
70+
case 'didFocus':
71+
return didFocusState;
72+
case 'willFocus':
73+
return willFocusState;
74+
case 'willBlur':
75+
return willBlurState;
76+
case 'didBlur':
77+
return didBlurState;
78+
default:
79+
return null;
80+
}
81+
}
82+
function useFocusState() {
83+
var navigation = useNavigation();
84+
var isFocused = navigation.isFocused();
85+
var _a = react_1.useState(getInitialFocusState(isFocused)), focusState = _a[0], setFocusState = _a[1];
86+
function handleEvt(e) {
87+
var newState = focusStateOfEvent(e.type);
88+
newState && setFocusState(newState);
89+
}
90+
useNavigationEvents(handleEvt);
91+
return focusState;
92+
}
93+
exports.useFocusState = useFocusState;

tsconfig.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "commonjs",
5+
"lib": ["es2017", "es7", "es6", "dom"],
6+
"declaration": true,
7+
"outDir": "dist",
8+
"strict": true,
9+
"esModuleInterop": true
10+
},
11+
"include": ["src"],
12+
"exclude": [
13+
"dist",
14+
".jest",
15+
"node_modules"
16+
]
17+
}

0 commit comments

Comments
 (0)