Files
spacedrive/apps/web/src/ScreenshotWrapper.tsx
Arnab Chakraborty ca8049eeed [MOB-23] Mobile Hardware Information for Overview Page (#2106)
* wip for iDevices

* Working HardwareModel Info for iOS

* wip

* Merge 'main' into 'mob-hw-info-overview'

* Half-Working `get_volume()`

* Objective c bridge to talk to FS

* Working objc bridge

The bridge works now, and we can now access the iOS file system using the native objective-c APIs instead for proper values, including on the simulator.

* Isolate `icrate` for `ios` deployments only

* Working Stats for Android

* Clean Up + `pnpm format`

* Fix to FSInfoResult Type

Due to the RNFS fork change, I had to change the types to make it so it doesn't fail building and CI.

* iOS Device Name Fix
2024-03-06 06:46:22 +00:00

71 lines
1.5 KiB
TypeScript

import * as htmlToImage from 'html-to-image';
import React, { useEffect, useRef } from 'react';
const ScreenshotWrapper = ({
showControls,
children
}: {
showControls: boolean;
children: React.ReactNode;
}) => {
const domEl = useRef(null);
const downloadImage = async () => {
const style = document.createElement('style');
style.innerHTML = `
::-webkit-scrollbar {
display: none;
}
body, .no-scrollbar, .custom-scroll {
overflow: hidden !important;
-ms-overflow-style: none;
scrollbar-width: none;
}
`;
document.head.appendChild(style);
if (!domEl.current) return;
const dataUrl = await htmlToImage.toPng(domEl.current);
document.head.removeChild(style);
const link = document.createElement('a');
link.download = 'test.png';
link.href = dataUrl;
link.click();
};
useEffect(() => {
if (showControls) {
window.document.body.style.backgroundColor = 'black';
window.addEventListener('keyup', (e) => {
if (e.key === 'k') {
downloadImage();
}
});
return () => window.removeEventListener('keyup', downloadImage);
}
}, [showControls]);
return (
<div
ref={showControls ? domEl : null}
style={
showControls
? {
width: '1278px',
height: '626px',
margin: '0 auto',
position: 'relative',
overflow: 'hidden'
}
: {}
}
>
{children}
</div>
);
};
export default ScreenshotWrapper;