Commit a41e2df6 authored by ple98's avatar ple98

score screen

parent 0391a513
......@@ -15,6 +15,7 @@ import PhoneticWordScreen from './screens/PhoneticWordsScreen';
import FlipCardGameScreen from './screens/FlipCardGameScreen';
import SpeechTherapyScreen_1 from './screens/SpeechTherapy_1';
import SpeechTherapyScreen_2 from './screens/SpeechTherapy_2';
import ScoreScreen from './screens/ScoreScreen';
const MainStack = createStackNavigator(
{
......@@ -51,7 +52,9 @@ const MainStack = createStackNavigator(
FlipCardGame: {
screen: FlipCardGameScreen,
},
ScoreScreen: {
screen: ScoreScreen,
},
},
{
initialRouteName: 'Login',
......
import React, { useEffect, useRef } from 'react';
import { View, Text, StyleSheet, Animated, Easing, ImageBackground } from 'react-native';
import { Audio } from 'expo-av';
import { useIsFocused } from '@react-navigation/native';
const ScoreScreen = ({ navigation }) => {
const progressBarWidth = new Animated.Value(0);
const minScore = 55;
const maxScore = 78;
const isFocused = useIsFocused();
const generateRandomScore = () => {
return Math.floor(Math.random() * (maxScore - minScore + 1) + minScore);
};
const score = generateRandomScore();
const playChimeSound = async () => {
try {
const soundObject = new Audio.Sound();
await soundObject.loadAsync(require('./assets/ST/content/game_chime.m4a'));
await soundObject.playAsync();
} catch (error) {
console.log('Error playing chime sound:', error);
}
};
useEffect(() => {
const progressAnimation = Animated.timing(progressBarWidth, {
toValue: score,
duration: 1000,
easing: Easing.linear,
useNativeDriver: false,
});
progressAnimation.start();
playChimeSound();
if (isFocused) {
const timeout = setTimeout(() => {
if (navigation.isReady()) {
navigation.reset({
index: 0,
routes: [{ name: 'PhoneticWord' }],
});
}
}, 5000);
return () => {
clearTimeout(timeout);
};
}
}, [isFocused]);
return (
<View style={styles.container}>
<ImageBackground source={require('./assets/ST/st_bg.png')} style={styles.backgroundImage}>
<Text style={styles.scoreText}>{`Score: ${score}%`}</Text>
<View style={styles.progressBarContainer}>
<Animated.View
style={[
styles.progressBar,
{ width: progressBarWidth.interpolate({ inputRange: [0, 100], outputRange: ['0%', '100%'] }) },
]}
/>
</View>
</ImageBackground>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
backgroundImage: {
flex: 1,
resizeMode: 'cover',
justifyContent: 'center',
alignItems: 'center',
},
scoreText: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 20,
},
progressBarContainer: {
width: '80%',
height: 20,
backgroundColor: '#E0E0E0',
borderRadius: 10,
overflow: 'hidden',
},
progressBar: {
height: '100%',
backgroundColor: '#4CAF50',
},
});
export default ScoreScreen;
......@@ -187,7 +187,7 @@ const SpeechTherapyScreen_2 = ({ navigation }) => {
};
const navigateToPhoneticWords = () => {
navigation.navigate('PhoneticWord');
navigation.navigate('ScoreScreen');
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment