wake lock and prevent double tap screen zoom

This commit is contained in:
Viktor Rådberg
2023-07-12 19:29:06 +02:00
parent 6266a62111
commit 7d04439eb4
4 changed files with 44 additions and 17 deletions

View File

@@ -18,6 +18,7 @@
"material-ui": "^0.20.2", "material-ui": "^0.20.2",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-screen-wake-lock": "^3.0.1",
"react-scripts": "5.0.1", "react-scripts": "5.0.1",
"react-swipeable": "^7.0.1", "react-swipeable": "^7.0.1",
"styled-components": "^6.0.1", "styled-components": "^6.0.1",

View File

@@ -5,7 +5,7 @@ import Play from './Components/Views/Play';
import StartMenu from './Components/Views/StartMenu'; import StartMenu from './Components/Views/StartMenu';
import { InitialSettings } from './Data/getInitialPlayers'; import { InitialSettings } from './Data/getInitialPlayers';
import { GridTemplateAreas } from './Data/getGridTemplateAreas'; import { GridTemplateAreas } from './Data/getGridTemplateAreas';
import styled from 'styled-components'; import styled, { createGlobalStyle } from 'styled-components';
export const initialPlayerOptions = { export const initialPlayerOptions = {
numberOfPlayers: 4, numberOfPlayers: 4,
@@ -14,6 +14,14 @@ export const initialPlayerOptions = {
gridAreas: GridTemplateAreas.FourPlayers, gridAreas: GridTemplateAreas.FourPlayers,
}; };
const GlobalStyles = createGlobalStyle`
html,
body,
#root {
touch-action: manipulation;
}
`;
const RootWrapper2 = styled.div` const RootWrapper2 = styled.div`
max-width: fit-content; max-width: fit-content;
max-height: fit-content; max-height: fit-content;
@@ -57,6 +65,8 @@ const App = () => {
if (players.length > 0 && initialGameSettings) { if (players.length > 0 && initialGameSettings) {
return ( return (
<>
<GlobalStyles />
<RootWrapper> <RootWrapper>
<Play <Play
players={players} players={players}
@@ -64,10 +74,13 @@ const App = () => {
gridAreas={initialGameSettings?.gridAreas} gridAreas={initialGameSettings?.gridAreas}
/> />
</RootWrapper> </RootWrapper>
</>
); );
} }
return ( return (
<>
<GlobalStyles />
<RootWrapper2> <RootWrapper2>
<StartMenu <StartMenu
initialGameSettings={initialGameSettings} initialGameSettings={initialGameSettings}
@@ -75,6 +88,7 @@ const App = () => {
setPlayers={setPlayers} setPlayers={setPlayers}
/> />
</RootWrapper2> </RootWrapper2>
</>
); );
}; };

View File

@@ -1,13 +1,13 @@
import { Checkbox, ToggleButton } from '@mui/material'; import { Checkbox } from '@mui/material';
import { initialPlayerOptions } from '../../App'; import { initialPlayerOptions } from '../../App';
import { createInitialPlayers } from '../../Data/getInitialPlayers'; import { createInitialPlayers } from '../../Data/getInitialPlayers';
import { Player, Rotation } from '../../Types/Player'; import { Player, Rotation } from '../../Types/Player';
import * as S from './PlayerMenu.style'; import * as S from './PlayerMenu.style';
import ExperienceIcon from '../../Icons/ExperienceIcon'; import ExperienceIcon from '../../Icons/ExperienceIcon';
import CommanderTaxIcon from '../../Icons/CommanderTaxIcon';
import PartnerTaxIcon from '../../Icons/PartnerTaxIcon'; import PartnerTaxIcon from '../../Icons/PartnerTaxIcon';
import EnergyIcon from '../../Icons/EnergyIcon'; import EnergyIcon from '../../Icons/EnergyIcon';
import PoisonIcon from '../../Icons/PoisonIcon'; import PoisonIcon from '../../Icons/PoisonIcon';
import { useWakeLock } from 'react-screen-wake-lock';
type SettingsProps = { type SettingsProps = {
player: Player; player: Player;
@@ -16,6 +16,9 @@ type SettingsProps = {
}; };
const Settings = ({ player, opponents, onChange }: SettingsProps) => { const Settings = ({ player, opponents, onChange }: SettingsProps) => {
const { isSupported, released, request, release } = useWakeLock();
const handleWakeLock = () => (released === false ? release() : request());
const handleColorChange = (event: React.ChangeEvent<HTMLInputElement>) => { const handleColorChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const updatedPlayer = { ...player, color: event.target.value }; const updatedPlayer = { ...player, color: event.target.value };
onChange(updatedPlayer); onChange(updatedPlayer);
@@ -134,6 +137,10 @@ const Settings = ({ player, opponents, onChange }: SettingsProps) => {
<S.Button rotation={player.settings.rotation} onClick={toggleFullscreen}> <S.Button rotation={player.settings.rotation} onClick={toggleFullscreen}>
Fullscreen Fullscreen
</S.Button> </S.Button>
<S.Button rotation={player.settings.rotation} onClick={handleWakeLock}>
{released === false ? 'Release' : 'Request'} nosleep
</S.Button>
</S.SettingsContainer> </S.SettingsContainer>
); );
}; };

View File

@@ -8195,6 +8195,11 @@ react-refresh@^0.11.0:
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.11.0.tgz#77198b944733f0f1f1a90e791de4541f9f074046" resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.11.0.tgz#77198b944733f0f1f1a90e791de4541f9f074046"
integrity sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A== integrity sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A==
react-screen-wake-lock@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/react-screen-wake-lock/-/react-screen-wake-lock-3.0.1.tgz#53132b28384bb66fc6838b846ffeced25b42c8d3"
integrity sha512-7igtGC2btjFiPqn7JoqRqrUvSV9wX7ZB8uCtP6LA9qYcTfY5i7VqelfjZ/b57jnGR9Q5TykAaX4Lkeok4j06jA==
react-scripts@5.0.1: react-scripts@5.0.1:
version "5.0.1" version "5.0.1"
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-5.0.1.tgz#6285dbd65a8ba6e49ca8d651ce30645a6d980003" resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-5.0.1.tgz#6285dbd65a8ba6e49ca8d651ce30645a6d980003"