Skip to content

Commit ba77e07

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

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

app/layout.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Metadata, Viewport } from "next";
1+
import type { Metadata } from "next";
22
import "@fontsource-variable/inconsolata";
33
// import "@fontsource/m-plus-rounded-1c/400.css";
44
// import "@fontsource/m-plus-rounded-1c/700.css";
@@ -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: 20 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,23 @@ 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.visualViewport?.addEventListener("resize", updateHeight);
40+
return () =>
41+
window.visualViewport?.removeEventListener("resize", updateHeight);
42+
} else {
43+
if (modalDivRef.current) {
44+
modalDivRef.current.style.height = "";
45+
}
46+
}
47+
}, [daisyModalEnabled]);
3048

3149
return (
3250
<>
@@ -39,6 +57,7 @@ export function Modal(props: Props) {
3957
<div
4058
className={clsx(daisyModalEnabled && "modal h-dvh")}
4159
role={daisyModalEnabled ? "dialog" : undefined}
60+
ref={modalDivRef}
4261
>
4362
<div
4463
className={clsx(

0 commit comments

Comments
 (0)