Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const widthPercentageToDP = widthPercent => {

// Use PixelRatio.roundToNearestPixel method in order to round the layout
// size (dp) to the nearest one that correspons to an integer number of pixels.
return PixelRatio.roundToNearestPixel(screenWidth * elemWidth / 100);
const calculatedWidthDpValue = screenWidth * elemWidth / 100
return PixelRatio.roundToNearestPixel(calculatedWidthDpValue);
};

/**
Expand All @@ -34,7 +35,8 @@ const heightPercentageToDP = heightPercent => {

// Use PixelRatio.roundToNearestPixel method in order to round the layout
// size (dp) to the nearest one that correspons to an integer number of pixels.
return PixelRatio.roundToNearestPixel(screenHeight * elemHeight / 100);
const calculatedHeightDpValue = screenHeight * elemHeight / 100
return PixelRatio.roundToNearestPixel(calculatedHeightDpValue);
};

/**
Expand All @@ -47,7 +49,7 @@ const heightPercentageToDP = heightPercent => {
* invoke setState method and trigger screen rerender (this.setState()).
*/
const listenOrientationChange = that => {
Dimensions.addEventListener('change', newDimensions => {
return Dimensions.addEventListener('change', newDimensions => {
// Retrieve and save new dimensions
screenWidth = newDimensions.window.width;
screenHeight = newDimensions.window.height;
Expand All @@ -56,6 +58,7 @@ const listenOrientationChange = that => {
that.setState({
orientation: screenWidth < screenHeight ? 'portrait' : 'landscape'
});

});
};

Expand All @@ -66,9 +69,9 @@ const listenOrientationChange = that => {
* avoid adding new listeners every time the same component is re-mounted.
*/
const removeOrientationListener = () => {
Dimensions.removeEventListener('change', () => {});
listenOrientationChange().remove()
};

export {
widthPercentageToDP,
heightPercentageToDP,
Expand Down