Skip to content

Commit

Permalink
feat(ViewportProvider): extend dimensions for client, outer and docum…
Browse files Browse the repository at this point in the history
…ent width and heigth
  • Loading branch information
garthenweb committed Sep 23, 2018
1 parent 50791dc commit 8f57de1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
29 changes: 24 additions & 5 deletions lib/ViewportProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,24 @@ const getNodeScroll = (elem = window) => {
};

const getClientDimensions = () => {
const { innerWidth, innerHeight, outerWidth, outerHeight } = window;
const {
clientWidth,
clientHeight,
scrollHeight,
scrollWidth,
offsetHeight,
offsetWidth,
} = document.documentElement;
return {
width: window.innerWidth || document.documentElement.clientWidth,
height: window.innerHeight || document.documentElement.clientHeight,
width: innerWidth,
height: innerHeight,
clientWidth,
clientHeight,
outerWidth,
outerHeight,
documentWidth: Math.max(scrollWidth, offsetWidth, clientWidth),
documentHeight: Math.max(scrollHeight, offsetHeight, clientHeight),
};
};

Expand Down Expand Up @@ -115,6 +130,12 @@ export const createInitDimensionsState = () => {
return {
width: 0,
height: 0,
clientWidth: 0,
clientHeight: 0,
outerWidth: 0,
outerHeight: 0,
documentWidth: 0,
documentHeight: 0,
};
}
return getClientDimensions();
Expand Down Expand Up @@ -198,9 +219,7 @@ export default class ViewportProvider extends React.PureComponent {
);

handleResize = debounce(() => {
const { width, height } = getClientDimensions();
this.dimensionsState.width = width;
this.dimensionsState.height = height;
Object.assign(this.dimensionsState, getClientDimensions());

this.componentMightHaveUpdated = true;
}, 80);
Expand Down
6 changes: 6 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import {
export interface IDimensions {
width: number;
height: number;
clientWidth: number;
clientHeight: number;
outerWidth: number;
outerHeight: number;
documentWidth: number;
documentHeight: number;
}

export interface IScroll {
Expand Down

0 comments on commit 8f57de1

Please sign in to comment.