Skip to content

Commit 2dc03d0

Browse files
committed
iosでキーボード表示時にモーダルのサイズが変わるようにする
1 parent a715107 commit 2dc03d0

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

app/layout.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ import { SidebarMdProvider } from "./sidebar";
1414
import { RuntimeProvider } from "./terminal/runtime";
1515
import { getPagesList } from "@/lib/docs";
1616

17-
export const viewport: Viewport = {
18-
width: "device-width",
19-
initialScale: 1,
20-
interactiveWidget: "resizes-content",
21-
};
22-
2317
export const metadata: Metadata = {
2418
title: {
2519
template: "%s - my.code();",

app/terminal/modal.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import clsx from "clsx";
4-
import { ReactNode, useEffect, useState } from "react";
4+
import { ReactNode, useEffect, useRef, useState } from "react";
55

66
interface Props {
77
className?: string;
@@ -14,6 +14,7 @@ interface Props {
1414
export function Modal(props: Props) {
1515
const [daisyModalEnabled, setDaisyModalEnabled] = useState(false);
1616
const [daisyModalOpen, setDaisyModalOpen] = useState(false);
17+
const modalDivRef = useRef<HTMLDivElement>(null);
1718
useEffect(() => {
1819
if (props.open) {
1920
// daisyuiのmodalモードにする → modalを開くアニメーションをする
@@ -27,6 +28,22 @@ export function Modal(props: Props) {
2728
return () => clearTimeout(timeout);
2829
}
2930
}, [props.open]);
31+
useEffect(() => {
32+
if (daisyModalEnabled) {
33+
const updateHeight = () => {
34+
if (modalDivRef.current && window.visualViewport) {
35+
modalDivRef.current.style.height = `${window.visualViewport.height}px`;
36+
}
37+
};
38+
updateHeight();
39+
window.addEventListener("resize", updateHeight);
40+
return () => window.removeEventListener("resize", updateHeight);
41+
} else {
42+
if (modalDivRef.current) {
43+
modalDivRef.current.style.height = "";
44+
}
45+
}
46+
}, [daisyModalEnabled]);
3047

3148
return (
3249
<>
@@ -39,6 +56,7 @@ export function Modal(props: Props) {
3956
<div
4057
className={clsx(daisyModalEnabled && "modal h-dvh")}
4158
role={daisyModalEnabled ? "dialog" : undefined}
59+
ref={modalDivRef}
4260
>
4361
<div
4462
className={clsx(

0 commit comments

Comments
 (0)