Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
react-with-gesture
Advanced tools
npm install react-with-gesture
import { useGesture, withGesture, Gesture } from 'react-with-gesture'
React-with-gesture is a small utility that lets you bind enriched mouse and touch events to any component or view. It calculates initial position, deltas, velocity, direction, distance, etc. With this data it becomes trivial to set up even complex gesture controls with just a few lines of code.
You can use it stand-alone, but to make the most of it you should combine it with a animation library, preferrably react-spring.
Viewpager/carousel: https://codesandbox.io/embed/n9vo1my91p
Draggable list: https://codesandbox.io/embed/r5qmj8m6lq
Slider: https://codesandbox.io/embed/zrj66y8714
{
touch: true, // accept mouse input
mouse: true, // accept touch input
passive: { passive: true }, // event handler 3rd argument input, passive by default
onAction: undefined // if you define onAction: event => eventHandler react-with-gesture
// will not render changes through React any longer
}
Alternatively you can supply a function, which becomes onAction
with defaults.
// Short cut with event handler
const bind = useGesture(event => eventHandler)
return <div {...bind(optionalArgs)} />
// Full config with event handler
const bind = useGesture({ onAction: event => eventHandler, ...config })
return <div {...bind(optionalArgs)} />
// No event handler (will re-render the component on event changes)
const [bind, props] = useGesture()
return <div {...bind(optionalArgs)} />
// Render props
<Gesture {...config}>
{event => <div />}
</Gesture>
// HOC
@withGesture(config)
class extends React.Component {
render() {
const event = this.props.event
return <div />
}
}
{
event, // source event
target, // dom node
time, // time tag
initial, // click coordinates (vec2)
xy, // page coordinates (vec2)
previous, // previous page coordinates (vec2)
delta, // delta offset (xy - initial) (vec2)
direction, // direction normal (vec2)
local, // delta with book-keeping (vec2)
velocity, // drag momentuum / speed
distance, // delta distance
down, // mouse / touch down
first, // marks first event (mouse / touch down)
args, // arguments optionally passed to bind(a,b,c,d,..)
temp, // arguments optionally returns by the onAction
}
Demo: https://codesandbox.io/embed/l2wy87l28l
const [bind, { local: [x, y] }] = useGesture()
return <div {...bind()} style={{ transform: `translate3d(${x}px,${y}px,0)` }} />
Demo: https://codesandbox.io/embed/r24mzvo3q
const [{ xy }, set] = useSpring(() => ({ xy: [0, 0] }))
const bind = useGesture(({ down, delta }) => set({ xy: down ? delta : [0, 0] }))
return (
<animated.div
{...bind()}
style={{ transform: xy.interpolate((x, y) => `translate3d(${x}px,${y}px,0)`) }}
/>
)
Demo: https://codesandbox.io/embed/zq19y1xr9m
const [{ xy }, set] = useSpring(() => ({ xy: [0, 0] }))
const bind = useGesture(({ down, delta, velocity, direction, temp = xy.getValue() }) => {
set({
xy: add(delta, temp),
immediate: down,
config: { velocity: scale(direction, velocity), decay: true }
})
return temp
})
return (
<animated.div
{...bind()}
style={{ transform: xy.interpolate((x, y) => `translate3d(${x}px,${y}px,0)`) }}
/>
)
FAQs
hoc for receiving gestures
The npm package react-with-gesture receives a total of 767 weekly downloads. As such, react-with-gesture popularity was classified as not popular.
We found that react-with-gesture demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.