Skip to content

Instantly share code, notes, and snippets.

@tofusoup429
Last active August 28, 2021 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tofusoup429/f578abc2f30f1440ca25847bb1602d07 to your computer and use it in GitHub Desktop.
Save tofusoup429/f578abc2f30f1440ca25847bb1602d07 to your computer and use it in GitHub Desktop.
import {useEffect, useState} from 'react';
import {useCamera} from '@tofusoup429/camera';
import { useWindowSize } from '@tofusoup429/use-window-size';
import LensSharpIcon from '@material-ui/icons/LensSharp';
import LoopIcon from '@material-ui/icons/Loop';
const FullScreenMobileView = () => {
let {width, height} = useWindowSize() // get window width and height as everytime screen resized.
const {captureImage ,imageData, switchCameraFacingMode} = useCamera(); // customHook that contains logics
const [imageDatas, handleImageDatas] = useState<string[]>([]) // capture imageUrls are saved in this state.
useEffect(()=>{
//whenever imageData changed, which means captureImage is executed, imageUrl is cumulated in the array.
handleImageDatas([...imageDatas, imageData])
}, [imageData])
return(
<div style={{display:"flex", flexDirection:"column", justifyContent:"start", alignItems:"flex-start"}}>
<div className="VideoAndCanvas">
<video width={width} style={{objectFit:'contain'}} />
<canvas style={{opacity:0}} />
</div>
<LensSharpIcon id='CaptureImageButton' fontSize='large' color="secondary" style={{width:'75px', height:"75px", position:'absolute', top:height*0.9, left:width*0.5, transform: "translate(-50%, -50%)"}} onClick={captureImage} />
<LoopIcon id='SwitchCameraButton' fontSize='large' color="secondary" style={{position:'absolute', top:'40px', left:'40px', transform: "translate(-50%, -50%)" }} onClick={switchCameraFacingMode} />
{imageDatas.length>0 &&
<div id="Images" style={{display:"flex", flexDirection:"row", justifyContent:"center", flexWrap:'wrap', margin:'1%', padding:'1%' }}>
{
imageDatas.map((imageData, index)=>{
return(
imageData.length>10 && <img key={index} src={imageData} width={width*0.45} alt='NoImage'/>
)
})
}
</div>
}
</div>
)
}
export default FullScreenMobileView;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment