Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ 아이폰 가로 모드 추가 #54

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions src/app/layout/iPhone/hooks/useDynamicSize.tsx

This file was deleted.

74 changes: 74 additions & 0 deletions src/app/layout/iPhone/hooks/useUtilityIPhone.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { useEffect, useRef } from 'react';

const IPHONE_MIN_SIZE = 60;
const IPHONE_INIT_SIZE = 80;
const IPHONE_MAX_SIZE = 100;

const IPHONE_PROTRAIT_MODE = 0; // 세로 모드
const IPHONE_LANDSCAPE_MODE = -90; // 가로 모드

/**
* iPhone 레이아웃의 크기를 동적으로 변경하는 훅입니다.
* @returns iPhone 레이아웃의 참조와 사이즈 변경 핸들러
*/
export const useUtilityIPhone = () => {
const iPhoneSizeRef = useRef<number>(IPHONE_INIT_SIZE);
const iPhoneModeRef = useRef<number>(IPHONE_PROTRAIT_MODE);
const iPhoneLayoutRef = useRef<HTMLDivElement>(null);

useEffect(() => {
document.documentElement.style.setProperty(
'--iphone-size',
`${IPHONE_INIT_SIZE}%`,
);

document.documentElement.style.setProperty(
'--iphone-mode',
`${IPHONE_PROTRAIT_MODE}deg`,
);
}, []);

const changeStyle = () => {
if (iPhoneLayoutRef.current) {
iPhoneLayoutRef.current.style.height = `${iPhoneSizeRef.current}%`;
document.documentElement.style.setProperty(
'--iphone-size',
`${iPhoneSizeRef.current}%`,
);
}
};

const handleSizeUp = () => {
if (iPhoneSizeRef.current >= IPHONE_MAX_SIZE) return;

iPhoneSizeRef.current += 1;
changeStyle();
};

const handleSizeDown = () => {
if (iPhoneSizeRef.current <= IPHONE_MIN_SIZE) return;

iPhoneSizeRef.current -= 1;
changeStyle();
};

const handleRotate = () => {
if (iPhoneModeRef.current === IPHONE_PROTRAIT_MODE) {
// 가로 모드로 변경
iPhoneModeRef.current = IPHONE_LANDSCAPE_MODE;
document.documentElement.style.setProperty(
'--iphone-mode',
`${IPHONE_LANDSCAPE_MODE}deg`,
);
} else {
// 세로 모드로 변경
iPhoneModeRef.current = IPHONE_PROTRAIT_MODE;
document.documentElement.style.setProperty(
'--iphone-mode',
`${IPHONE_PROTRAIT_MODE}deg`,
);
}
};

return { iPhoneLayoutRef, handleRotate, handleSizeUp, handleSizeDown };
};
7 changes: 5 additions & 2 deletions src/app/layout/iPhone/ui/IPhoneLayout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
/* 아이폰 이미지의 비율 설정 */
aspect-ratio: 256 / 538;
height: var(--iphone-size);
rotate: var(--iphone-mode);

transition: rotate 1.5s;

.iPhone-status {
/* children의 크기를 아이폰 화면 크기에 맞게 설정 */
Expand Down Expand Up @@ -55,15 +58,15 @@
.iPhone-utility-container {
position: absolute;
left: 50%;
bottom: 2%;
bottom: calc(2% + (var(--iphone-size) - 80%) * 0.025);
transform: translateX(-50%);

display: flex;
align-items: center;
gap: 24px;

.size-down-btn,
.retry-btn,
.rotation-btn,
.size-up-btn {
width: 40px;
height: 40px;
Expand Down
7 changes: 4 additions & 3 deletions src/app/layout/iPhone/ui/IPhoneLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import { Outlet } from 'react-router-dom';

import { useDynamicSize } from '../hooks/useDynamicSize';
import { useUtilityIPhone } from '../hooks/useUtilityIPhone';

import iPhoneStatus from '/assets/image/iPhone_status.png';
import './IPhoneLayout.scss';

export const IPhoneLayout = () => {
const { iPhoneLayoutRef, handleSizeDown, handleSizeUp } = useDynamicSize();
const { iPhoneLayoutRef, handleSizeDown, handleRotate, handleSizeUp } =
useUtilityIPhone();

return (
<div className='root-layout'>
Expand All @@ -25,7 +26,7 @@ export const IPhoneLayout = () => {
<button className='size-down-btn' onClick={handleSizeDown}>
-
</button>
<button className='retry-btn' onClick={() => location.reload()} />
<button className='rotation-btn' onClick={handleRotate} />
<button className='size-up-btn' onClick={handleSizeUp}>
+
</button>
Expand Down
Loading