Skip to content

Commit

Permalink
ClimbingView: Fullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
jvaclavik committed Nov 21, 2024
1 parent 47bdaa6 commit 2950978
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/components/FeaturePanel/Climbing/ClimbingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled from '@emotion/styled';
import SplitPane from 'react-split-pane';
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
import {
Button,
CircularProgress,
Fab,
IconButton,
Expand Down Expand Up @@ -32,6 +33,7 @@ import EditIcon from '@mui/icons-material/Edit';
import ArrowForwardIcon from '@mui/icons-material/ArrowForward';
import { useGetCragViewLayout } from './utils/useCragViewLayout';
import { RouteFloatingMenu } from './Editor/RouteFloatingMenu';
import { useFullScreen } from './utils/useFullscreen';

export const DEFAULT_CRAG_VIEW_LAYOUT = 'horizontal';

Expand Down Expand Up @@ -254,6 +256,7 @@ const FabMapSwitcher = ({ isMapVisible, setIsMapVisible }) => (
);

export const ClimbingView = ({ photo }: { photo?: string }) => {
const viewRef = React.useRef<HTMLDivElement>(null);
const {
imageSize,
routeSelectedIndex,
Expand Down Expand Up @@ -283,6 +286,9 @@ export const ClimbingView = ({ photo }: { photo?: string }) => {
const machine = getMachine();
const cragViewLayout = useGetCragViewLayout();
const { userSettings } = useUserSettingsContext();
const { enterFullscreen, exitFullscreen, isFullScreenActive } = useFullScreen(
viewRef.current,
);

useEffect(() => {
if (isEditMode && machine.currentStateName === 'routeSelected') {
Expand Down Expand Up @@ -420,7 +426,7 @@ export const ClimbingView = ({ photo }: { photo?: string }) => {
};

return (
<Container>
<Container ref={viewRef}>
{(showArrowOnTop || showArrowOnBottom) && (
<ArrowExpanderContainer $cragViewLayout={cragViewLayout}>
<ArrowExpanderButton $arrowOnTop={showArrowOnTop}>
Expand Down Expand Up @@ -514,6 +520,11 @@ export const ClimbingView = ({ photo }: { photo?: string }) => {
<BottomPanel onScroll={handleOnScroll}>
<ClimbingViewContent isMapVisible={isMapVisible} />
</BottomPanel>
<Button
onClick={isFullScreenActive ? exitFullscreen : enterFullscreen}
>
FULL
</Button>
</BottomContainer>
</SplitPane>
) : (
Expand Down
29 changes: 29 additions & 0 deletions src/components/FeaturePanel/Climbing/utils/useFullscreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useState } from 'react';

export const useFullScreen = (elem: HTMLDivElement, options?: any) => {
const [isFullScreenActive, setIsFullScreenActive] = useState(false);
const enterFullscreen = () => {
setIsFullScreenActive(true);
return elem[
[
'requestFullscreen',
'mozRequestFullScreen',
'msRequestFullscreen',
'webkitRequestFullscreen',
].find((prop) => typeof elem[prop] === 'function')
]?.(options);
};

const exitFullscreen = () => {
setIsFullScreenActive(false);
return document[
[
'exitFullscreen',
'mozExitFullscreen',
'msExitFullscreen',
'webkitExitFullscreen',
].find((prop) => typeof document[prop] === 'function')
]?.();
};
return { enterFullscreen, exitFullscreen, isFullScreenActive };
};

0 comments on commit 2950978

Please sign in to comment.