Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #509 from gluestack/feat/use-media-hook
Browse files Browse the repository at this point in the history
feat: use media hook
  • Loading branch information
ankit-tailor authored Oct 31, 2023
2 parents 10ecfa4 + a54ebc3 commit 95faaf1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/react/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { useMediaQuery };
export { useBreakpointValue } from './useBreakpointValue';
export { useToken } from './useToken';
export { useColorMode } from './useColorMode';
export { useMedia } from './useMedia';
26 changes: 26 additions & 0 deletions packages/react/src/hooks/useMedia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useWindowDimensions } from 'react-native';
import { isValidBreakpoint } from '../generateStylePropsFromCSSIds';
import { useStyled } from '../StyledProvider';
import type { GSConfig } from '../types';

type BreakPointValue = Partial<{
[key in keyof GSConfig['tokens']['breakpoints']]: boolean;
}>;

export const useMedia = (): BreakPointValue => {
const theme = useStyled();
const { width } = useWindowDimensions();
const mediaQueries = theme?.config?.tokens?.mediaQueries;

const breakpoints: any = {};

Object.keys(mediaQueries).forEach((currentBreakPoint: any) => {
breakpoints[currentBreakPoint] = isValidBreakpoint(
theme?.config,
mediaQueries[currentBreakPoint],
width
);
});

return breakpoints;
};

0 comments on commit 95faaf1

Please sign in to comment.