-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add listener for height on orientation change (#195)
* Subscribing to orientation changes * fix: useDimensions hook added to handle orientation change * fix: simplified useDimensions hook to handle window only * fix: file name change
- Loading branch information
1 parent
3b8b5d3
commit 0bbdae6
Showing
2 changed files
with
20 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react'; | ||
import { Dimensions, ScaledSize } from 'react-native'; | ||
|
||
export const useDimensions = (): ScaledSize => { | ||
const [dimensions, setDimensions] = React.useState(Dimensions.get('window')); | ||
|
||
const onChange = ({ window }: { window: ScaledSize }): void => { | ||
setDimensions(window); | ||
}; | ||
|
||
React.useEffect(() => { | ||
Dimensions.addEventListener('change', onChange); | ||
|
||
return (): void => Dimensions.removeEventListener('change', onChange); | ||
}, []); | ||
|
||
return dimensions; | ||
}; |