add detection for whether the entire SWF is visible
This commit is contained in:
parent
10be4c4ea1
commit
1a9b495558
1 changed files with 50 additions and 1 deletions
|
@ -211,6 +211,8 @@ function ItemLayerSupportScreenshotStep({ itemLayer, step, onUpload }) {
|
||||||
<Box>
|
<Box>
|
||||||
<b>Step {step}:</b> Take a screenshot of exactly the 600×600 Flash
|
<b>Step {step}:</b> Take a screenshot of exactly the 600×600 Flash
|
||||||
region, then upload it below.
|
region, then upload it below.
|
||||||
|
<br />
|
||||||
|
The border will turn green once the entire region is in view.
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box
|
||||||
display="flex"
|
display="flex"
|
||||||
|
@ -288,12 +290,58 @@ function ItemLayerSupportReviewStep({ imageWithAlphaUrl, numWarnings }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function ItemLayerSupportFlashPlayer({ swfUrl, backgroundColor }) {
|
function ItemLayerSupportFlashPlayer({ swfUrl, backgroundColor }) {
|
||||||
|
const [isVisible, setIsVisible] = React.useState(null);
|
||||||
|
const regionRef = React.useRef(null);
|
||||||
|
|
||||||
|
// We detect whether the entire SWF region is visible, because Flash only
|
||||||
|
// bothers to render in visible places. So, screenshotting a SWF container
|
||||||
|
// that isn't fully visible will fill the not-visible space with black,
|
||||||
|
// instead of the actual SWF content. We change the border color to hint this
|
||||||
|
// to the user!
|
||||||
|
React.useEffect(() => {
|
||||||
|
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 (
|
return (
|
||||||
<Box
|
<Box
|
||||||
data-hint="No: Don't screenshot this node! Use the one below!"
|
data-hint="No: Don't screenshot this node! Use the one below!"
|
||||||
borderWidth="3px"
|
borderWidth="3px"
|
||||||
borderStyle="dashed"
|
borderStyle="dashed"
|
||||||
borderColor="green.400"
|
borderColor={borderColor}
|
||||||
marginTop="4"
|
marginTop="4"
|
||||||
>
|
>
|
||||||
<Box
|
<Box
|
||||||
|
@ -318,6 +366,7 @@ function ItemLayerSupportFlashPlayer({ swfUrl, backgroundColor }) {
|
||||||
// But this disrupts the Firefox capture! So here, we do a cheap
|
// But this disrupts the Firefox capture! So here, we do a cheap
|
||||||
// browser detection, to shift left only in Chrome.
|
// browser detection, to shift left only in Chrome.
|
||||||
marginLeft={navigator.userAgent.includes("Chrome") ? "-1px" : "0"}
|
marginLeft={navigator.userAgent.includes("Chrome") ? "-1px" : "0"}
|
||||||
|
ref={regionRef}
|
||||||
>
|
>
|
||||||
<object
|
<object
|
||||||
type="application/x-shockwave-flash"
|
type="application/x-shockwave-flash"
|
||||||
|
|
Loading…
Reference in a new issue