You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

useThemeColor.ts 536B

123456789101112131415161718192021
  1. /**
  2. * Learn more about light and dark modes:
  3. * https://docs.expo.dev/guides/color-schemes/
  4. */
  5. import { Colors } from '@/constants/Colors';
  6. import { useColorScheme } from '@/hooks/useColorScheme';
  7. export function useThemeColor(
  8. props: { light?: string; dark?: string },
  9. colorName: keyof typeof Colors.light & keyof typeof Colors.dark
  10. ) {
  11. const theme = useColorScheme() ?? 'light';
  12. const colorFromProps = props[theme];
  13. if (colorFromProps) {
  14. return colorFromProps;
  15. } else {
  16. return Colors[theme][colorName];
  17. }
  18. }