useRenderBone.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React, { useCallback } from 'react';
  2. import ShiverBone from '../ShiverBone';
  3. import StaticBone from '../StaticBone';
  4. import type {
  5. ICustomViewStyle,
  6. IGeneralStyles,
  7. IComponentSize,
  8. } from '../constants';
  9. interface UseRenderBoneProps {
  10. generalStyles: IGeneralStyles;
  11. bonesLayout: ICustomViewStyle[];
  12. keyIndex: string | number;
  13. index: number;
  14. }
  15. /**
  16. * Renders the bone based on the animation type.
  17. * @componentSize is the size of the component.
  18. */
  19. export const useRenderBone = (componentSize: IComponentSize) =>
  20. useCallback(
  21. ({ generalStyles, bonesLayout, keyIndex, index }: UseRenderBoneProps) => {
  22. if (
  23. generalStyles.animationType === 'pulse' ||
  24. generalStyles.animationType === 'none'
  25. ) {
  26. return (
  27. <StaticBone
  28. key={keyIndex}
  29. componentSize={componentSize}
  30. index={index}
  31. boneLayout={bonesLayout[index] ?? {}}
  32. {...generalStyles}
  33. />
  34. );
  35. }
  36. return (
  37. <ShiverBone
  38. key={keyIndex}
  39. componentSize={componentSize}
  40. boneLayout={bonesLayout[index] ?? {}}
  41. {...generalStyles}
  42. />
  43. );
  44. },
  45. [componentSize],
  46. );