-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavigation.js
69 lines (57 loc) · 1.51 KB
/
Navigation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React, { useState, useRef, useEffect } from "react";
import { View } from "react-native";
import Touchable from "./Touchable.js";
import Header from "./Header.js"
import Image from "./Image.js";
const Navigation = ({ initalStack }) => {
console.log("Child", initalStack);
const backButton = () => {
return (
<Touchable
onPress={() => {
popView()
}}
style={{ paddingRight: 20 }}
>
<Image
style={{ width: 27, height: 27 }}
source={{
uri: "file:///app/KPPMainApp/res/KPPUIChrome/BackArrow.svg",
}}
/>
</Touchable>
);
};
const [navigationStack, setNavigationStack] = useState(initalStack);
const renderCurrentView = () => {
console.log(navigationStack[navigationStack.length - 1].view);
return React.cloneElement(
navigationStack[navigationStack.length - 1].view,
{
pushView: pushView,
popView: popView,
}
);
};
const currentTitle = () => {
return navigationStack[navigationStack.length - 1].title;
};
const pushView = (view) => {
setNavigationStack([...navigationStack, view]);
};
const popView = () => {
if (navigationStack.length > 1) {
setNavigationStack(navigationStack.slice(0, -1));
}
};
return (
<View>
<Header
headerButtonRight={navigationStack.length > 1 ? backButton() : <></>}
title={currentTitle()}
/>
{renderCurrentView()}
</View>
);
};
export default Navigation;