fix new game button
This commit is contained in:
parent
4f45da5ab5
commit
3a83bf1cd5
@ -1,11 +1,10 @@
|
||||
import * as React from 'react';
|
||||
import { View, Button, Text, useWindowDimensions, Alert } from 'react-native';
|
||||
import { View, Text, useWindowDimensions, Alert, Pressable } from 'react-native';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { GameScreenProps } from '../types';
|
||||
import { useState } from 'react';
|
||||
import { Game, GameUsersConnectionInfo } from '../models/Game';
|
||||
import BoardViewModel from '../viewmodel/BoardViewModel';
|
||||
import { Link } from '@react-navigation/native';
|
||||
import { MancalaGame, Pit } from 'mancala.js';
|
||||
import { v4 } from 'uuid';
|
||||
import PitAnimator from '../animation/PitAnimator';
|
||||
@ -22,6 +21,7 @@ import LoadingComponent from '../components/LoadingComponent';
|
||||
import UserStatus from '../components/UserStatus';
|
||||
import BoardToolbar from '../components/board/BoardToolbar';
|
||||
import BoardView from '../components/board/BoardView';
|
||||
import CircularPanel from '../components/CircularPanel';
|
||||
export function GameScreen({ navigation, route }: GameScreenProps) {
|
||||
|
||||
const { context, gameId, userKey } = route.params;
|
||||
@ -212,23 +212,25 @@ export function GameScreen({ navigation, route }: GameScreenProps) {
|
||||
}, []);
|
||||
|
||||
const updateHeaderButton = () => {
|
||||
console.info(game?.mancalaGame.state)
|
||||
const isGameEnded = game?.mancalaGame.state === "ended" || leftPlayer;
|
||||
navigation.setOptions({
|
||||
headerRight: () => (
|
||||
<Button onPress={() => {
|
||||
if (game?.mancalaGame.state !== "ended") {
|
||||
onLeaveGameClick();
|
||||
} else {
|
||||
<Pressable onPress={() => {
|
||||
if (isGameEnded) {
|
||||
onNewGameClick();
|
||||
} else {
|
||||
onLeaveGameClick();
|
||||
}
|
||||
}} title={game?.mancalaGame.state !== "ended" ? t('Leave') : t('NewGame')} />
|
||||
}}>
|
||||
<CircularPanel color={context.themeManager.theme?.background} children={<Text style={{ color: context.themeManager.theme.textColor }}>{isGameEnded ? t('NewGame') : t('Leave')}</Text>} />
|
||||
</Pressable>
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
updateHeaderButton();
|
||||
}, [navigation, game]);
|
||||
}, [navigation, game, userKeyWhoLeave]);
|
||||
|
||||
const textColorOnAppBar = getColorByBrightness(
|
||||
context.themeManager.theme.appBarBgColor,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user