Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
react-native-skia-gesture
Advanced tools
A detection system for React Native Skia components.
React Native Skia, provides many declarative APIs for building screens using React Components. However, Skia components are not real components, but abstract representations of a part of a drawing. Therefore direct interactions with individual Skia components can only be achieved indirectly from the Canvas (trying to figure out if the point on the screen that was clicked is within the element we want to interact with).
This package, simply provides a set of APIs to be able to interact directly with individual components.
You need to have already installed @shopify/react-native-skia (>= 0.1.221)
You need to install Reanimated (v3.0.0+) and Gesture Handler (v2.0.0+)
yarn add react-native-reanimated react-native-gesture-handler
Open a Terminal in your project's folder and then install the library using yarn
:
yarn add react-native-skia-gesture
import {
useSharedValue,
} from 'react-native-reanimated';
import Touchable, {
useGestureHandler,
} from 'react-native-skia-gesture';
export default function App() {
const cx = useSharedValue(100);
const cy = useSharedValue(100);
const circleGesture = useGestureHandler<{ x: number; y: number }>({
onStart: (_, context) => {
'worklet'; // Remember the 'worklet' keyword
context.x = cx.value;
context.y = cy.value;
},
onActive: ({ translationX, translationY }, context) => {
'worklet';
cx.value = context.x + translationX;
cy.value = context.y + translationY;
},
});
return (
<Touchable.Canvas style={styles.fill}>
<Touchable.Circle cx={cx} cy={cy} r={50} color="red" {...circleGesture} />
</Touchable.Canvas>
);
}
If the element is a Circle, Rect, RoundedRect, or a Path the package will automatically derive its touchablePath. Alternatively it will have to be passed as a parameter to the TouchableComponent.
...
const touchablePath = useDerivedValue(() => {
const path = new Path();
path.addCircle(cx.value, cy.value, 50);
return path;
}, [cx, cy]);
return (
<Touchable.Canvas style={styles.fill}>
<Touchable.Circle cx={cx} cy={cy} r={50} color="red" touchablePath={touchablePath} {...circleGesture} />
</Touchable.Canvas>
);
...
You might want to run the gestures on the JS thread (but it's not recommended). However it could be useful if you want to slowly migrate from the v0.2.0 to the v0.3.0.
To handle that you need to define the panGesture and pass it to the Touchable.Canvas
import { Gesture } from 'react-native-gesture-handler';
...
const panGesture = Gesture.Pan().runOnJS(true)
const circleGesture = useGestureHandler<{ x: number; y: number }>({
// You can avoid the 'worklet' keyword if you are running the gesture on JS thread
onStart: (_, context) => {
context.x = cx.value;
context.y = cy.value;
},
onActive: ({ translationX, translationY }, context) => {
cx.value = context.x + translationX;
cy.value = context.y + translationY;
},
});
return (
<Touchable.Canvas style={styles.fill} panGesture={panGesture}>
<Touchable.Circle cx={cx} cy={cy} r={50} color="red" {...circleGesture} />
</Touchable.Canvas>
);
Canvas
It's simply a Wrapper of Skia's Canvas.
withTouchableHandler
It's a HOC with which to wrap all Skia components with which you want to interact directly. You will need to pass a touchablePath
to the component.
import { Image } from '@shopify/react-native-skia';
import { withTouchableHandler } from 'react-native-skia-gesture';
const TouchableImage = withTouchableHandler(Image);
const touchablePath = Skia.Path.Make().addCircle(x, y, 50);
return (
<Touchable.Canvas style={styles.fill}>
<TouchableImage
image={image}
x={x}
y={y}
width={50}
height={50}
touchablePath={touchablePath}
{...circleGesture}
/>
</Touchable.Canvas>
);
useGestureHandler
It's a hook from which onStart, onActive, onEnd interactions can be managed. The hook provides as the second parameter of each callback a context that can be optionally used (strongly inspired by the useAnimatedGestureHandler hook).
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library
FAQs
A detection system for React Native Skia components
The npm package react-native-skia-gesture receives a total of 178 weekly downloads. As such, react-native-skia-gesture popularity was classified as not popular.
We found that react-native-skia-gesture demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.