From 7677a60bbec3d8d018732de19320f9f4ea4591c1 Mon Sep 17 00:00:00 2001 From: Matchu Date: Mon, 21 Sep 2020 18:50:27 -0700 Subject: [PATCH] add non-canvas version back for smaller previews --- src/app/WardrobePage/index.js | 1 + src/app/components/OutfitPreview.js | 92 +++++++++++++++++++++++++---- 2 files changed, 81 insertions(+), 12 deletions(-) diff --git a/src/app/WardrobePage/index.js b/src/app/WardrobePage/index.js index 2c66f9a..1f5b1a8 100644 --- a/src/app/WardrobePage/index.js +++ b/src/app/WardrobePage/index.js @@ -63,6 +63,7 @@ function WardrobePage() { pose={outfitState.pose} appearanceId={outfitState.appearanceId} wornItemIds={outfitState.wornItemIds} + engine="canvas" /> } controls={ diff --git a/src/app/components/OutfitPreview.js b/src/app/components/OutfitPreview.js index 7bbd038..1a2ed5c 100644 --- a/src/app/components/OutfitPreview.js +++ b/src/app/components/OutfitPreview.js @@ -1,6 +1,8 @@ import React from "react"; import { Box, DarkMode, Flex, Text } from "@chakra-ui/core"; import { WarningIcon } from "@chakra-ui/icons"; +import { css, cx } from "emotion"; +import { CSSTransition, TransitionGroup } from "react-transition-group"; import HangerSpinner from "./HangerSpinner"; import useOutfitAppearance from "./useOutfitAppearance"; @@ -29,6 +31,7 @@ function OutfitPreview({ placeholder, loadingDelayMs, spinnerVariant, + engine = "images", }) { const { loading, error, visibleLayers } = useOutfitAppearance({ speciesId, @@ -61,7 +64,8 @@ function OutfitPreview({ placeholder={placeholder} loadingDelayMs={loadingDelayMs} spinnerVariant={spinnerVariant} - doAnimations + engine={engine} + doTransitions /> ); } @@ -76,7 +80,8 @@ export function OutfitLayers({ placeholder, loadingDelayMs = 500, spinnerVariant = "overlay", - doAnimations = false, + doTransitions = false, + engine = "images", }) { // NOTE: I couldn't find an official NPM source for this that worked with // Webpack, and I didn't want to rely on random people's ports, and I @@ -137,19 +142,82 @@ export function OutfitLayers({ )} - {!scriptsLoading && ( - - + { + // TODO: A bit of a mess in here! Extract these out? + engine === "canvas" ? ( + !scriptsLoading && ( + + + {visibleLayers.map((layer) => ( + + ))} + + + ) + ) : ( + {visibleLayers.map((layer) => ( - + classNames={css` + &-exit { + opacity: 1; + } + + &-exit-active { + opacity: 0; + transition: opacity 0.2s; + } + `} + timeout={200} + > + + finishes preloading and + // applies the src to the underlying . + className={cx( + css` + object-fit: contain; + max-width: 100%; + max-height: 100%; + + &.do-animations { + animation: fade-in 0.2s; + } + + @keyframes fade-in { + from { + opacity: 0; + } + to { + opacity: 1; + } + } + `, + doTransitions && "do-animations" + )} + // This sets up the cache to not need to reload images during + // download! + // TODO: Re-enable this once we get our change into Chakra + // main. For now, this will make Downloads a bit slower, which + // is fine! + // crossOrigin="Anonymous" + /> + + ))} - - - )} + + ) + }