Chore: Deprecate Dimensions (#4597)

This commit is contained in:
Diego Mello 2022-10-21 15:29:02 -03:00
parent 80171a9fdc
commit 5891f469ec
1 changed files with 9 additions and 0 deletions

View File

@ -26,6 +26,9 @@ export const DimensionsContext = React.createContext<IDimensionsContextProps>(
Dimensions.get('window') as IDimensionsContextProps Dimensions.get('window') as IDimensionsContextProps
); );
/**
* @deprecated use RN's useWindowDimensions hook instead
*/
export function withDimensions<T extends object>(Component: React.ComponentType<T> & TNavigationOptions): typeof Component { export function withDimensions<T extends object>(Component: React.ComponentType<T> & TNavigationOptions): typeof Component {
const DimensionsComponent = (props: T) => ( const DimensionsComponent = (props: T) => (
<DimensionsContext.Consumer>{contexts => <Component {...props} {...contexts} />}</DimensionsContext.Consumer> <DimensionsContext.Consumer>{contexts => <Component {...props} {...contexts} />}</DimensionsContext.Consumer>
@ -35,8 +38,14 @@ export function withDimensions<T extends object>(Component: React.ComponentType<
return DimensionsComponent; return DimensionsComponent;
} }
/**
* @deprecated use RN's useWindowDimensions hook instead
*/
export const useDimensions = () => React.useContext(DimensionsContext); export const useDimensions = () => React.useContext(DimensionsContext);
/**
* @deprecated use RN's useWindowDimensions hook instead
*/
export const useOrientation = () => { export const useOrientation = () => {
const { width, height } = React.useContext(DimensionsContext); const { width, height } = React.useContext(DimensionsContext);
const isPortrait = height > width; const isPortrait = height > width;