Create professional demos and 3D mockups in seconds, directly in your browser
fix: resolve iPhone Duo review issues
Efrain Chiri Nina4bbe44cd574c
diff --git a/app/[locale]/layout.tsx b/app/[locale]/layout.tsxindex 7a78502..48139f9 100644--- a/app/[locale]/layout.tsx+++ b/app/[locale]/layout.tsx@@ -5,7 +5,6 @@ import { defaultLocale, locales, type Locale } from "@/i18n";import { TooltipProvider } from "@/components/ui/tooltip";import { Inter, Roboto } from "next/font/google";import type { Metadata, Viewport } from "next";-import Script from "next/script";import { GoogleAnalytics } from "@next/third-parties/google";import { SuppressScriptWarning } from "@/app/components/common/SuppressScriptWarning";import {@@ -18,6 +17,22 @@ import {} from "@/lib/seo";import "../globals.css";+const THEME_INLINE_SCRIPT = `+(function () {+ try {+ var get = function (name) {+ var match = document.cookie.match(new RegExp("(?:^|;\\s*)" + name + "=([^;]*)"));+ return match ? decodeURIComponent(match[1]) : null;+ };+ var preference = get("openvid_theme_pref") || get("openvid_theme") || "system";+ var isDark = preference === "system"+ ? window.matchMedia("(prefers-color-scheme: dark)").matches+ : preference === "dark";+ document.documentElement.classList.toggle("dark", isDark);+ } catch {}+})();+`;+const inter = Inter({subsets: ["latin"],variable: "--font-inter",@@ -170,7 +185,10 @@ export default async function LocaleLayout({return (<html lang={locale || defaultLocale} suppressHydrationWarning><head>- <Script id="openvid-theme" src="/openvid-theme.js" strategy="beforeInteractive" />+ <script+ id="openvid-theme"+ dangerouslySetInnerHTML={{ __html: THEME_INLINE_SCRIPT }}+ /></head><bodyclassName={`${inter.variable} ${roboto.variable} ${inter.className} antialiased`}diff --git a/app/components/ui/editor/DuoMotionCard.tsx b/app/components/ui/editor/DuoMotionCard.tsxindex 79f8e33..6124b8a 100644--- a/app/components/ui/editor/DuoMotionCard.tsx+++ b/app/components/ui/editor/DuoMotionCard.tsx@@ -27,7 +27,7 @@ export function DuoMotionCard() {return (<div className="overflow-hidden rounded-2xl border border-border bg-card"><div className="relative h-36 overflow-hidden bg-[#101116]">- <Image width={800} height={480} src="/images/mockups-3d/iphone-duo/preview.webp" alt="iPhone Duo" className="h-full w-full object-cover" />+ <Image width={800} height={480} src="/images/mockups-3d/iphone-duo.png" alt="iPhone Duo" className="h-full w-full object-cover" /><span className="absolute left-3 top-3 rounded-full border border-white/15 bg-black/35 px-2 py-1 text-[9px] font-medium uppercase tracking-widest text-white/80">3D · iPhone Duo</span></div><div className="space-y-3 p-3">diff --git a/app/components/ui/editor/mockups-3d/Device3DBoundary.tsx b/app/components/ui/editor/mockups-3d/Device3DBoundary.tsxindex a32ff36..49a208b 100644--- a/app/components/ui/editor/mockups-3d/Device3DBoundary.tsx+++ b/app/components/ui/editor/mockups-3d/Device3DBoundary.tsx@@ -4,18 +4,18 @@ import { Component, type ReactNode } from "react";import { useTranslations } from "next-intl";import { useGLTF } from "@react-three/drei";-class Boundary extends Component<{ children: ReactNode; fallback: (retry: () => void) => ReactNode }, { failed: boolean }> {+class Boundary extends Component<{ children: ReactNode; modelUrl?: string; fallback: (retry: () => void) => ReactNode }, { failed: boolean }> {state = { failed: false };static getDerivedStateFromError() { return { failed: true }; }render() {return this.state.failed ? this.props.fallback(() => {- useGLTF.clear("/models/iphone-duo.glb");+ if (this.props.modelUrl) useGLTF.clear(this.props.modelUrl);this.setState({ failed: false });}) : this.props.children;}}-export function Device3DBoundary({ children }: { children: ReactNode }) {+export function Device3DBoundary({ children, modelUrl }: { children: ReactNode; modelUrl?: string }) {const t = useTranslations("mockupMenu");return (<Boundary fallback={(retry) => (@@ -23,6 +23,6 @@ export function Device3DBoundary({ children }: { children: ReactNode }) {<p>{t("deviceLoadError")}</p><button type="button" onClick={retry} className="rounded-lg border border-border px-4 py-2 hover:bg-muted">{t("retry")}</button></div>- )}>{children}</Boundary>+ )} modelUrl={modelUrl}>{children}</Boundary>);}diff --git a/app/components/ui/editor/mockups-3d/IPhoneDuo3DViewer.tsx b/app/components/ui/editor/mockups-3d/IPhoneDuo3DViewer.tsxindex e8f7f5c..d5bb1d2 100644--- a/app/components/ui/editor/mockups-3d/IPhoneDuo3DViewer.tsx+++ b/app/components/ui/editor/mockups-3d/IPhoneDuo3DViewer.tsx@@ -134,8 +134,8 @@ export function IPhoneDuoScene({videoElement.addEventListener("resize", updateVideo);} else {const urls = imageUrl ? [imageUrl, imageUrl] : [- "/images/mockups-3d/iphone-duo/apple-desert.avif",- "/images/mockups-3d/iphone-duo/apple-desert-cover.avif",+ "/images/mockups-3d/apple-desert_duo.avif",+ "/images/mockups-3d/apple-desert-cover_duo.avif",];Promise.all(urls.map(async (url, index) => {const texture = await new THREE.TextureLoader().loadAsync(url);diff --git a/app/components/ui/editor/mockups-3d/Mockup3DStage.tsx b/app/components/ui/editor/mockups-3d/Mockup3DStage.tsxindex 9302d1d..dbde54a 100644--- a/app/components/ui/editor/mockups-3d/Mockup3DStage.tsx+++ b/app/components/ui/editor/mockups-3d/Mockup3DStage.tsx@@ -10,7 +10,7 @@ import { Phone3DApi, Phone3DScene } from "./Phone3DViewer";import { Laptop3DApi, LaptopScene } from "./Laptop3DViewer";import { IPhone17ProMax3DApi, IPhone17ProMaxScene } from "./IPhone17ProMax3DViewer";import { IPadMini63DApi, IPadMiniScene } from "./IPadMini63DViewer";-import { ImageMaskConfigLike } from "@/lib/phone3d.utils";+import { ImageMaskConfigLike, PHONE_DEVICE_URLS } from "@/lib/phone3d.utils";import type { ImageDeviceId } from "@/types/mockup.types";import { EnvironmentPreset } from "@/lib/viewer-controls3d";import { REST_MOCKUP_3D_MOTION, type Mockup3DMotionTransform } from "@/lib/mockup-motion-3d";@@ -139,7 +139,7 @@ function Motion3DApplicator({}export function Mockup3DStage(props: StageProps) {- return <Device3DBoundary key={props.device}><StageContent {...props} /></Device3DBoundary>;+ return <Device3DBoundary key={props.device} modelUrl={PHONE_DEVICE_URLS[props.device]}><StageContent {...props} /></Device3DBoundary>;}function StageContent({ device, rootRef: externalRootRef, cameraRef: externalCameraRef, onLoadedChange, ...props }: StageProps) {diff --git a/lib/mockup-motion-3d.ts b/lib/mockup-motion-3d.tsindex e4e3d70..6a6666f 100644--- a/lib/mockup-motion-3d.ts+++ b/lib/mockup-motion-3d.ts@@ -457,9 +457,17 @@ export function sampleCombined3DMotion(// Sampling by time (not frame history) makes scrubbing and export identical.const lastFold = fragments.filter((f) => f.presetId.startsWith("duo-") && f.endTime < currentTime).sort((a, b) => b.endTime - a.endTime)[0];- const rest = lastFold ? {+ const nextFold = lastFold ? undefined : fragments+ .filter((f) => f.presetId.startsWith("duo-") && f.startTime > currentTime)+ .sort((a, b) => a.startTime - b.startTime)[0];+ const heldOpeningProgress = lastFold+ ? sample3DFragmentMotion(lastFold, lastFold.endTime).openingProgress+ : nextFold+ ? sample3DFragmentMotion(nextFold, nextFold.startTime).openingProgress+ : undefined;+ const rest = heldOpeningProgress !== undefined ? {...REST_MOCKUP_3D_MOTION,- openingProgress: sample3DFragmentMotion(lastFold, lastFold.endTime).openingProgress,+ openingProgress: heldOpeningProgress,} : REST_MOCKUP_3D_MOTION;if (active.length === 0) return rest;diff --git a/tests/iphone-duo-motion.test.mjs b/tests/iphone-duo-motion.test.mjsindex 64d2abf..7cd5b1e 100644--- a/tests/iphone-duo-motion.test.mjs+++ b/tests/iphone-duo-motion.test.mjs@@ -46,7 +46,7 @@ test('folded pose is retained through gaps and unrelated motion', () => {assert.equal(sampleCombined3DMotion(fragments, 2.5).openingProgress, 0);assert.equal(sampleCombined3DMotion(fragments, 4).openingProgress, 0);assert.equal(sampleCombined3DMotion(fragments, 10).openingProgress, 1);- assert.equal(sampleCombined3DMotion(fragments, -1).openingProgress, undefined);+ assert.equal(sampleCombined3DMotion(fragments, -1).openingProgress, 1);});test('random scrubbing and serialized project restore match sequential export sampling', () => {