useGetPositionRange.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { useCallback } from 'react';
  2. import { useGetBoneDimensions } from './useGetBoneDimensions';
  3. import { ICustomViewStyle } from '../constants';
  4. import type { ISkeletonProps, IComponentSize } from '../constants';
  5. type UseGetPositionRangeProps = Pick<ISkeletonProps, 'animationDirection'> & {
  6. boneLayout: ICustomViewStyle;
  7. };
  8. export const useGetPositionRange = (componentSize: IComponentSize) => {
  9. const getBoneDimensions = useGetBoneDimensions(componentSize);
  10. return useCallback(
  11. ({ animationDirection, boneLayout }: UseGetPositionRangeProps) => {
  12. 'worklet';
  13. const outputRange: number[] = [];
  14. const { width, height } = getBoneDimensions(boneLayout);
  15. switch (animationDirection) {
  16. case 'horizontalRight':
  17. outputRange.push(-width, +width);
  18. break;
  19. case 'horizontalLeft':
  20. outputRange.push(+width, -width);
  21. break;
  22. case 'verticalDown':
  23. outputRange.push(-height, +height);
  24. break;
  25. case 'verticalTop':
  26. outputRange.push(+height, -height);
  27. break;
  28. }
  29. return outputRange;
  30. },
  31. [getBoneDimensions],
  32. );
  33. };