Skip to content

Commit 4fbe762

Browse files
author
Ryan Nixon Salim
committed
Add proxy and update readme
1 parent e5dd019 commit 4fbe762

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

readme.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,29 @@ import InfinityGauntlet from 'react-thanos-snap';
3131
function App(props) {
3232
const [snap, setSnap] = useState(false);
3333
return (
34-
<>
34+
<div>
3535
<InfinityGauntlet snap={true}>{/** Put your components here **/}</InfinityGauntlet>
3636
<button onClick={() => setSnap(!snap)}>Snap❗️</button>
37-
</>
37+
</div>
3838
);
3939
}
4040
```
4141

4242
# Limitation
4343

4444
- The components will be wrap with the div that have `position: relative;` style on it.
45-
- We use `html2canvas`. This library have the limitation that can not render the image outside the origin because of the content policy restriction from the browser. if you wish to render image outside your origin, please read kindly use [proxy](http://html2canvas.hertzen.com/proxy/);
45+
- We use `html2canvas`. This library have the limitation that can not render the image outside the origin because of the content policy restriction from the browser. if you wish to render image outside your origin, please read kindly use [proxy](http://html2canvas.hertzen.com/proxy/);. This component have the `options.proxy` props so you can add the proxy on that props.
4646

4747
# Credit
4848

4949
- The idea of this project also comes from [red stappler tutorial](https://redstapler.co/thanos-snap-effect-javascript-tutorial/). I porting the logic to the react and use some modification on the animation. So super thanks to the [red stapper](https://redstapler.co) for creating the great tutorial!
5050

5151
- The Amazing infinity gauntlet logo image for this repo is owned by [Jamie Ferrato](https://dribbble.com/shots/4595136-Infinity-Gauntlet). I own no rights to the image.
5252

53-
# License
53+
# Contributing
5454

55-
MIT
55+
I ❤️ to have your helping on react-thanos-snap project! Feel free to PR's, add issues or give feedback! Enjoy your mighty power 😎
5656

57-
# Contributing
57+
# License
5858

59-
I ❤️ to have your helping hand on react-thanos-snap project! Feel free to PR's, add issues or give feedback! Enjoy your mighty power 😎
59+
MIT

src/components/InfinityGauntlet.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ const OriginalElement = posed.div({
3737
},
3838
});
3939

40-
function handleSnap(imgRef, particleRefs, setState, snap, seParticleVisibility) {
40+
function handleSnap(imgRef, particleRefs, setState, snap, seParticleVisibility, proxy) {
4141
seParticleVisibility(true);
4242
if (!snap) {
4343
setState('visible');
4444
} else {
4545
if (imageDataArray.length === 0) {
46-
html2canvas(imgRef.current, { scale: 1, backgroundColor: null })
46+
html2canvas(imgRef.current, { scale: 1, backgroundColor: null, proxy })
4747
.then((canvas) => {
4848
const w = canvas.width;
4949
const h = canvas.height;
@@ -78,6 +78,15 @@ function handleSnap(imgRef, particleRefs, setState, snap, seParticleVisibility)
7878
}
7979
}
8080

81+
InfinityGauntlet.defaultProps = {
82+
style: {},
83+
snap: false,
84+
options: {
85+
zIndex: 2,
86+
proxy: null,
87+
},
88+
};
89+
8190
function InfinityGauntlet(props) {
8291
const { options, snap, style = {} } = props;
8392
const wrapperRef = useRef();
@@ -89,7 +98,7 @@ function InfinityGauntlet(props) {
8998
const canvases = generateBlankCanvas(particleRefs, state, canvasCount, zIndex);
9099

91100
useEffect(() => {
92-
handleSnap(wrapperRef, particleRefs, setState, snap, seParticleVisibility);
101+
handleSnap(wrapperRef, particleRefs, setState, snap, seParticleVisibility, options.proxy);
93102
}, [snap]);
94103

95104
return (
@@ -102,11 +111,10 @@ function InfinityGauntlet(props) {
102111
}
103112
}}
104113
ref={wrapperRef}
105-
style={{ position: 'absolute', zIndex }}
114+
style={{ position: 'absolute', zIndex, width: '100%' }}
106115
>
107116
{props.children}
108117
</OriginalElement>
109-
110118
<CanvasContainer style={{ display: particleVisibility ? 'block' : 'none' }} key={1} pose={state}>
111119
{canvases}
112120
</CanvasContainer>

0 commit comments

Comments
 (0)