Skip to content

Commit

Permalink
fix: enable splash screen in preview page (#596
Browse files Browse the repository at this point in the history
* feat: support tiles data type on reearth/core (#597

* guessType

* refactor

* support tiles

* fix

* normalize url

* fix: enable splash screen in preview page

* fix

* fix

* fix

* show floating widgets
  • Loading branch information
rot1024 committed Apr 4, 2023
1 parent ae5c497 commit e1f5acb
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 36 deletions.
1 change: 1 addition & 0 deletions src/components/molecules/Visualizer/Engine/index.tsx
Expand Up @@ -23,6 +23,7 @@ export type EngineProps = {
style?: CSSProperties;
isEditable?: boolean;
isBuilt?: boolean;
inEditor?: boolean;
property?: SceneProperty;
camera?: Camera;
clock?: Clock;
Expand Down
Expand Up @@ -29,7 +29,7 @@ export type Property = {
}[];
};

const SplashScreen = ({ widget, isBuilt }: Props): JSX.Element | null => {
const SplashScreen = ({ widget, inEditor }: Props): JSX.Element | null => {
const ctx = useContext();
const { property } = widget ?? {};
const {
Expand All @@ -42,7 +42,7 @@ const SplashScreen = ({ widget, isBuilt }: Props): JSX.Element | null => {
overlayImageW: imageW,
overlayImageH: imageH,
overlayTitle: title,
} = (property as Property | undefined)?.overlay ?? {};
} = property?.overlay ?? {};
const camera = (property as Property | undefined)?.camera?.filter(c => !!c.cameraPosition);

const [cameraSequence, setCameraSequence] = useState(0);
Expand Down Expand Up @@ -70,7 +70,7 @@ const SplashScreen = ({ widget, isBuilt }: Props): JSX.Element | null => {
});

useTimeoutFn(() => {
if (isBuilt && enabled) {
if (!inEditor && enabled) {
setActive(true);
}
}, delay * 1000);
Expand All @@ -80,20 +80,20 @@ const SplashScreen = ({ widget, isBuilt }: Props): JSX.Element | null => {
}, (delay + transitionDuration + duration) * 1000);

useEffect(() => {
if (!isBuilt || !currentCamera) return;
if (inEditor || !currentCamera) return;
const t = setTimeout(() => {
setDelayedCameraSequence(i => i + 1);
}, (currentCamera?.cameraDelay ?? 0) * 1000);
return () => clearTimeout(t);
}, [currentCamera, isBuilt]);
}, [currentCamera, inEditor]);

useEffect(() => {
if (!isBuilt || !delayedCurrentCamera) return;
if (inEditor || !delayedCurrentCamera) return;
const t = setTimeout(() => {
setCameraSequence(i => i + 1);
}, (delayedCurrentCamera?.cameraDuration ?? 0) * 1000);
return () => clearTimeout(t);
}, [delayedCurrentCamera, isBuilt]);
}, [delayedCurrentCamera, inEditor]);

return state === "unmounted" ? null : (
<Wrapper state={state} bgcolor={bgcolor} duration={transitionDuration}>
Expand Down
1 change: 1 addition & 0 deletions src/components/molecules/Visualizer/Widget/index.tsx
Expand Up @@ -19,6 +19,7 @@ export type Widget = Omit<RawWidget, "layout" | "extended"> & { extended?: boole
export type Props<PP = any, SP = any> = {
isEditable?: boolean;
isBuilt?: boolean;
inEditor?: boolean;
widget: Widget;
extended?: boolean;
sceneProperty?: SP;
Expand Down
2 changes: 2 additions & 0 deletions src/components/molecules/Visualizer/index.tsx
Expand Up @@ -217,6 +217,7 @@ export default function Visualizer({
!!widgets?.ownBuiltinWidgets?.[NAVIGATOR_BUILTIN_WIDGET_ID]
}
meta={engineMeta}
inEditor={inEditor}
onLayerSelect={selectLayer}
onCameraChange={updateCamera}
onTick={updateClock}
Expand Down Expand Up @@ -255,6 +256,7 @@ export default function Visualizer({
onPluginPopupShow={onPluginPopupShow}
isEditable={props.isEditable}
isBuilt={props.isBuilt}
inEditor={inEditor}
pluginBaseUrl={pluginBaseUrl}
viewport={viewport}
/>
Expand Down
12 changes: 6 additions & 6 deletions src/core/Crust/Widgets/Widget/SplashScreen/index.tsx
Expand Up @@ -32,7 +32,7 @@ export type Property = {

const SplashScreen = ({
widget,
isBuilt,
inEditor,
isMobile,
onVisibilityChange,
context: { onFlyTo } = {},
Expand Down Expand Up @@ -81,7 +81,7 @@ const SplashScreen = ({
});

useTimeoutFn(() => {
if (isBuilt && enabled) {
if (!inEditor && enabled) {
setActive(true);
}
}, delay * 1000);
Expand All @@ -91,20 +91,20 @@ const SplashScreen = ({
}, (delay + transitionDuration + duration) * 1000);

useEffect(() => {
if (!isBuilt || !currentCamera) return;
if (inEditor || !currentCamera) return;
const t = setTimeout(() => {
setDelayedCameraSequence(i => i + 1);
}, (currentCamera?.cameraDelay ?? 0) * 1000);
return () => clearTimeout(t);
}, [currentCamera, isBuilt]);
}, [currentCamera, inEditor]);

useEffect(() => {
if (!isBuilt || !delayedCurrentCamera) return;
if (inEditor || !delayedCurrentCamera) return;
const t = setTimeout(() => {
setCameraSequence(i => i + 1);
}, (delayedCurrentCamera?.cameraDuration ?? 0) * 1000);
return () => clearTimeout(t);
}, [delayedCurrentCamera, isBuilt]);
}, [delayedCurrentCamera, inEditor]);

return !visible || state === "unmounted" ? null : (
<Wrapper state={state} bgcolor={bgcolor} duration={transitionDuration}>
Expand Down
1 change: 1 addition & 0 deletions src/core/Crust/Widgets/Widget/index.tsx
Expand Up @@ -25,6 +25,7 @@ export type Props = {
layout?: WidgetLayout;
theme?: Theme;
isEditable?: boolean;
inEditor?: boolean;
isBuilt?: boolean;
isMobile?: boolean;
context?: Context;
Expand Down
4 changes: 2 additions & 2 deletions src/core/Crust/Widgets/WidgetAlignSystem/types.ts
Expand Up @@ -54,8 +54,8 @@ export type WidgetLayoutConstraint = {

export type WidgetProps = {
widget: InternalWidget;
layout: WidgetLayout;
layout?: WidgetLayout;
extended?: boolean;
editing: boolean;
onExtend: (id: string, extended: boolean | undefined) => void;
onExtend?: (id: string, extended: boolean | undefined) => void;
};
67 changes: 46 additions & 21 deletions src/core/Crust/Widgets/index.tsx
@@ -1,6 +1,6 @@
import { ReactNode, useCallback } from "react";
import { Fragment, ReactNode, useCallback } from "react";

import type { Theme, Widget, WidgetLayout, WidgetLocationOptions } from "./types";
import type { InternalWidget, Theme, Widget, WidgetLayout, WidgetLocationOptions } from "./types";
import useWidgetAlignSystem from "./useWidgetAlignSystem";
import WidgetComponent, { type Context } from "./Widget";
import WidgetAlignSystem, {
Expand Down Expand Up @@ -30,12 +30,14 @@ export type { Widget, InternalWidget, WidgetLocationOptions, WidgetAlignment } f

export type Props = {
alignSystem?: WidgetAlignSystemType;
floatingWidgets?: InternalWidget[];
selectedWidgetArea?: WidgetAreaType;
layoutConstraint?: { [w: string]: WidgetLayoutConstraint };
editing?: boolean;
isMobile?: boolean;
theme?: Theme;
isEditable?: boolean;
inEditor?: boolean;
isBuilt?: boolean;
context?: Context;
renderWidget?: (props: WidgetProps) => ReactNode;
Expand All @@ -55,20 +57,22 @@ export type WidgetProps = {
widget: Widget;
editing: boolean;
extended?: boolean;
layout: WidgetLayout;
onExtend: (id: string, extended: boolean | undefined) => void;
moveWidget: (widgetId: string, options: WidgetLocationOptions) => void;
layout?: WidgetLayout;
onExtend?: (id: string, extended: boolean | undefined) => void;
onWidgetMove?: (widgetId: string, options: WidgetLocationOptions) => void;
onVisibilityChange: (widgetId: string, v: boolean) => void;
};

export default function Widgets({
alignSystem,
floatingWidgets,
selectedWidgetArea,
editing,
isMobile,
layoutConstraint,
theme,
isEditable,
inEditor,
isBuilt,
context,
renderWidget,
Expand All @@ -90,6 +94,7 @@ export default function Widgets({
layout={layout}
theme={theme}
isEditable={isEditable}
inEditor={inEditor}
isBuilt={isBuilt}
isMobile={isMobile}
context={context}
Expand All @@ -100,31 +105,51 @@ export default function Widgets({
extended,
layout,
onExtend,
moveWidget,
onWidgetMove: moveWidget,
onVisibilityChange,
})
}
onVisibilityChange={onVisibilityChange}
onExtend={onExtend}
/>
),
[context, isBuilt, isEditable, isMobile, renderWidget, theme, moveWidget, onVisibilityChange],
[
theme,
isEditable,
inEditor,
isBuilt,
isMobile,
context,
onVisibilityChange,
renderWidget,
moveWidget,
],
);

return (
<WidgetAlignSystem
alignSystem={overriddenAlignSystem}
selectedWidgetArea={selectedWidgetArea}
invisibleWidgetIDs={invisibleWidgetIDs}
editing={editing}
built={isBuilt}
isMobile={isMobile}
layoutConstraint={layoutConstraint}
theme={theme}
renderWidget={renderWidgetInternal}
onAlignmentUpdate={onAlignmentUpdate}
onWidgetLayoutUpdate={onWidgetLayoutUpdate}
onWidgetAreaSelect={onWidgetAreaSelect}
/>
<>
<WidgetAlignSystem
alignSystem={overriddenAlignSystem}
selectedWidgetArea={selectedWidgetArea}
invisibleWidgetIDs={invisibleWidgetIDs}
editing={editing}
built={isBuilt}
isMobile={isMobile}
layoutConstraint={layoutConstraint}
theme={theme}
renderWidget={renderWidgetInternal}
onAlignmentUpdate={onAlignmentUpdate}
onWidgetLayoutUpdate={onWidgetLayoutUpdate}
onWidgetAreaSelect={onWidgetAreaSelect}
/>
{floatingWidgets?.map(w => (
<Fragment key={w.id}>
{renderWidgetInternal({
widget: w,
editing: false,
})}
</Fragment>
))}
</>
);
}
2 changes: 2 additions & 0 deletions src/core/Crust/index.tsx
Expand Up @@ -198,7 +198,9 @@ export default function Crust({
isMobile={isMobile}
isBuilt={isBuilt}
isEditable={isEditable}
inEditor={inEditor}
alignSystem={widgetAlignSystem}
floatingWidgets={floatingWidgets}
selectedWidgetArea={selectedWidgetArea}
editing={widgetAlignSystemEditing}
layoutConstraint={widgetLayoutConstraint}
Expand Down

0 comments on commit e1f5acb

Please sign in to comment.