From 1a9b4955582142bfcafc0a4250205f8cbde7858f Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 5 Aug 2020 13:25:20 -0700 Subject: [PATCH] add detection for whether the entire SWF is visible --- .../support/ItemLayerSupportUploadModal.js | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/app/WardrobePage/support/ItemLayerSupportUploadModal.js b/src/app/WardrobePage/support/ItemLayerSupportUploadModal.js index ee69883..86781e9 100644 --- a/src/app/WardrobePage/support/ItemLayerSupportUploadModal.js +++ b/src/app/WardrobePage/support/ItemLayerSupportUploadModal.js @@ -211,6 +211,8 @@ function ItemLayerSupportScreenshotStep({ itemLayer, step, onUpload }) { Step {step}: Take a screenshot of exactly the 600×600 Flash region, then upload it below. +
+ The border will turn green once the entire region is in view.
{ + const region = regionRef.current; + if (!region) { + return; + } + + const scrollParent = region.closest(".chakra-modal__overlay"); + if (!scrollParent) { + throw new Error(`could not find .chakra-modal__overlay scroll parent`); + } + + const onMountAndOnScroll = () => { + const regionBox = region.getBoundingClientRect(); + const scrollParentBox = scrollParent.getBoundingClientRect(); + const isVisible = + regionBox.left > scrollParentBox.left && + regionBox.right < scrollParentBox.right && + regionBox.top > scrollParentBox.top && + regionBox.bottom < scrollParentBox.bottom; + setIsVisible(isVisible); + }; + + onMountAndOnScroll(); + + scrollParent.addEventListener("scroll", onMountAndOnScroll); + + return () => scrollParent.removeEventListener("scroll", onMountAndOnScroll); + }, [regionRef.current]); + + let borderColor; + if (isVisible === null) { + borderColor = "gray.400"; + } else if (isVisible === false) { + borderColor = "red.400"; + } else if (isVisible === true) { + borderColor = "green.400"; + } + return (