react-native-reanimated
Version:
More powerful alternative to Animated library for React Native.
17 lines (16 loc) • 467 B
JavaScript
import { measure } from './NativeMethods';
/**
* Given an absolute position and a component ref, returns the relative
* position in the component's local coordinate space.
*/
export function getRelativeCoords(parentRef, absoluteX, absoluteY) {
'worklet';
const parentCoords = measure(parentRef);
if (parentCoords === null) {
return null;
}
return {
x: absoluteX - parentCoords.x,
y: absoluteY - parentCoords.y,
};
}