-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
116 lines (105 loc) · 2.92 KB
/
App.tsx
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import React, { useState } from 'react';
import { View, StyleSheet, Animated, Dimensions } from 'react-native';
import SplitList from './SplitList';
import ExpenseSplitter from './ExpenseSplitter';
export interface Split {
id: string;
name: string;
people: Person[];
settlements: Settlement[];
createdAt: string;
currency?: string;
}
export interface Person {
name: string;
amount: number;
}
export interface Settlement {
from: string;
to: string;
amount: number;
}
export interface NavigationProps {
navigate: (screenName: string, params?: any) => void;
goBack: () => void;
}
export interface RouteProps {
params: {
splitId?: string;
};
}
const { width } = Dimensions.get('window');
export default function App() {
const [currentScreen, setCurrentScreen] = useState<string>('SplitList');
const [currentSplitId, setCurrentSplitId] = useState<string | null>(null);
const [slideAnim] = useState(new Animated.Value(width));
const [refreshTrigger, setRefreshTrigger] = useState(0);
// Navigation functions that we'll pass to our screens
const navigation: NavigationProps = {
navigate: (screenName: string, params?: any) => {
if (screenName === 'ExpenseSplitter') {
// Slide in the ExpenseSplitter from right
if (params && params.splitId) {
setCurrentSplitId(params.splitId);
}
setCurrentScreen(screenName);
Animated.spring(slideAnim, {
toValue: 0,
useNativeDriver: true,
tension: 70,
friction: 12
}).start();
} else {
// Just switch to SplitList
setCurrentScreen(screenName);
}
},
goBack: () => {
// Slide out the ExpenseSplitter to the right
Animated.spring(slideAnim, {
toValue: width,
useNativeDriver: true,
tension: 70,
friction: 12
}).start(() => {
setCurrentScreen('SplitList');
// Trigger a refresh of the SplitList when returning
setRefreshTrigger(prev => prev + 1);
});
}
};
return (
<View style={styles.container}>
{/* SplitList is always rendered in the background */}
<View style={styles.screenContainer}>
<SplitList navigation={navigation} refreshTrigger={refreshTrigger} />
</View>
{/* ExpenseSplitter slides in from the right */}
{currentScreen === 'ExpenseSplitter' && (
<Animated.View
style={[
styles.overlayContainer,
{ transform: [{ translateX: slideAnim }] }
]}
>
<ExpenseSplitter
navigation={navigation}
route={{ params: { splitId: currentSplitId ?? undefined } }}
/>
</Animated.View>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
screenContainer: {
flex: 1,
},
overlayContainer: {
...StyleSheet.absoluteFillObject,
backgroundColor: '#fff',
}
});