|
@@ -17,7 +17,7 @@
|
17
|
17
|
* along with Campus INSAT. If not, see <https://www.gnu.org/licenses/>.
|
18
|
18
|
*/
|
19
|
19
|
|
20
|
|
-import React, { useLayoutEffect, useRef, useState } from 'react';
|
|
20
|
+import React, { useCallback, useLayoutEffect, useRef, useState } from 'react';
|
21
|
21
|
import { StyleSheet, View } from 'react-native';
|
22
|
22
|
import { useTheme } from 'react-native-paper';
|
23
|
23
|
import i18n from 'i18n-js';
|
|
@@ -41,7 +41,7 @@ import {
|
41
|
41
|
getPreferenceObject,
|
42
|
42
|
PreferenceKeys,
|
43
|
43
|
} from '../../../utils/asyncStorage';
|
44
|
|
-import { useNavigation } from '@react-navigation/core';
|
|
44
|
+import { useFocusEffect, useNavigation } from '@react-navigation/core';
|
45
|
45
|
|
46
|
46
|
const styles = StyleSheet.create({
|
47
|
47
|
container: {
|
|
@@ -110,6 +110,13 @@ export default function GameMainScreen() {
|
110
|
110
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
111
|
111
|
}, [navigation]);
|
112
|
112
|
|
|
113
|
+ useFocusEffect(
|
|
114
|
+ useCallback(() => {
|
|
115
|
+ const l = logic.current;
|
|
116
|
+ return () => l.endGame(true);
|
|
117
|
+ }, [])
|
|
118
|
+ );
|
|
119
|
+
|
113
|
120
|
const getRightButton = () => (
|
114
|
121
|
<MaterialHeaderButtons>
|
115
|
122
|
<Item title={'pause'} iconName={'pause'} onPress={togglePause} />
|
|
@@ -146,8 +153,9 @@ export default function GameMainScreen() {
|
146
|
153
|
if (newScores.length > 3) {
|
147
|
154
|
newScores.splice(3, 1);
|
148
|
155
|
}
|
149
|
|
- console.log(newScores);
|
150
|
|
- updatePreferences(PreferenceKeys.gameScores, newScores);
|
|
156
|
+ if (newScores.some((item, i) => item !== savedScores[i])) {
|
|
157
|
+ updatePreferences(PreferenceKeys.gameScores, newScores);
|
|
158
|
+ }
|
151
|
159
|
if (!isRestart) {
|
152
|
160
|
navigation.replace(MainRoutes.GameStart, {
|
153
|
161
|
score: score,
|