useGetBoneDimensions.ts 615 B

123456789101112131415161718192021
  1. import { useCallback } from 'react';
  2. import type { ICustomViewStyle, IComponentSize } from '../constants';
  3. export const useGetBoneDimensions = (componentSize: IComponentSize) =>
  4. useCallback(
  5. (boneLayout: ICustomViewStyle) => {
  6. 'worklet';
  7. return {
  8. width:
  9. typeof boneLayout.width === 'string'
  10. ? componentSize.width
  11. : boneLayout.width ?? 0,
  12. height:
  13. typeof boneLayout.height === 'string'
  14. ? componentSize.height
  15. : boneLayout.height ?? 0,
  16. } as { width: number; height: number };
  17. },
  18. [componentSize],
  19. );