Skip to content

Commit

Permalink
fix useAppColorScheme hook to return correct scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay committed Feb 3, 2024
1 parent 10209f3 commit 3f0ae88
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ export function create(customConfig: TwConfig, platform: Platform): TailwindFn {
configureCache();
};

tailwindFn.getColorScheme = () => {
return device.colorScheme;
};

return tailwindFn;
}

Expand Down
4 changes: 2 additions & 2 deletions src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState } from 'react';
import { useColorScheme, useWindowDimensions, Appearance } from 'react-native';
import { useColorScheme, useWindowDimensions } from 'react-native';
import type { TailwindFn, RnColorScheme } from './types';

type Options = {
Expand Down Expand Up @@ -29,7 +29,7 @@ export function useAppColorScheme(
setColorScheme: (colorScheme: RnColorScheme) => void,
] {
const [colorScheme, setColorScheme] = useState<RnColorScheme>(
initialValue ?? Appearance.getColorScheme(),
initialValue ?? tw.getColorScheme(),
);
return [
colorScheme,
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface TailwindFn {
setFontScale: (fontScale: number) => unknown;
setPixelDensity: (pixelDensity: 1 | 2) => unknown;
setColorScheme: (colorScheme: RnColorScheme) => unknown;
getColorScheme: () => RnColorScheme;
}

export type ClassInput =
Expand Down

0 comments on commit 3f0ae88

Please sign in to comment.