-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
82 lines (73 loc) · 2.61 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
import React, { useRef, useState, useEffect } from 'react';
import { StatusBar, Dimensions, Animated, View, TouchableOpacity } from 'react-native';
import Constants from 'expo-constants';
import Circle from './app/Circle';
import Dashboard from './app/Dashboard';
import FinalComponent from './app/FinalComponent';
const { width } = Dimensions.get('window');
const DURATION = 1000;
const TEXT_DURATION = DURATION * 0.8;
const App: React.FC = () => {
const sliderAnimatedValue = useRef(new Animated.Value(0)).current;
const inputRange = [...Array(6).keys()]; // Assuming there are 6 colors in the Circle component
const [circleData, setCircleData] = useState<number[] | null>(null);
const [hideCircle, setHideCircle] = useState<boolean>(false);
const [totalScore, setTotalScore] = useState<number>(0);
const [showFinalComponent, setShowFinalComponent] = useState<boolean>(false);
const [disableClick, setDisableClick] = useState<boolean>(false);
useEffect(() => {
if (circleData !== null) {
const isFilled = circleData.every((num: number) => num !== -1);
if (isFilled) {
setHideCircle(true);
const sum = circleData.reduce((acc: number, curr: number) => acc + curr, 0);
setTotalScore(sum * 10);
}
}
}, [circleData]);
const handlePress = (data: number[]) => {
setCircleData(data);
};
const handleDashboardClick = () => {
setDisableClick(true); // Disable clicking after moving to the final component
setShowFinalComponent(true);
};
const handleScreenClick = () => {
if (!showFinalComponent && hideCircle) {
setShowFinalComponent(true);
setDisableClick(true);
}
};
return (
<>
{!showFinalComponent && (
<TouchableOpacity style={{ flex: 1 }} onPress={handleScreenClick} disabled={disableClick}>
<StatusBar hidden />
{(circleData === null || !hideCircle) && (
<Circle onPress={handlePress} />
)}
{hideCircle && (
<Dashboard totalScore={totalScore}/>
)}
<Animated.View
style={{
flexDirection: 'row',
transform: [
{
translateX: sliderAnimatedValue.interpolate({
inputRange: inputRange.map((i) => i * 2),
outputRange: inputRange.map((i) => -i * width * 2),
}),
},
],
}}
>
{/* Content for the Animated.View */}
</Animated.View>
</TouchableOpacity>
)}
{showFinalComponent && <FinalComponent />}
</>
);
};
export default App;