Chore: Deprecate Dimensions (#4597)

This commit is contained in:
Diego Mello 2022-10-21 15:29:02 -03:00 committed by GitHub
parent 1486204546
commit 1aef030d75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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;