responsive-font.ts 572 B

12345678910111213141516171819
  1. import { PixelRatio } from 'react-native';
  2. const fontScale = PixelRatio.getFontScale();
  3. export const getFontSize = (size: number) => size / fontScale;
  4. export const getYears = (date: string): number => {
  5. const birthDate = new Date(date);
  6. const today = new Date();
  7. let age = today.getFullYear() - birthDate.getFullYear();
  8. const monthDifference = today.getMonth() - birthDate.getMonth();
  9. const dayDifference = today.getDate() - birthDate.getDate();
  10. if (monthDifference < 0 || (monthDifference === 0 && dayDifference < 0)) {
  11. age--;
  12. }
  13. return age;
  14. };