Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vx-responsive): fix enhancer parent/screen size checks #621

Merged
merged 1 commit into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
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
15 changes: 8 additions & 7 deletions packages/vx-responsive/src/enhancers/withParentSize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';
import debounce from 'lodash/debounce';
import ResizeObserver from 'resize-observer-polyfill';

const CONTAINER_STYLES = { width: '100%', height: '100%' };

export type WithParentSizeProps = {
debounceTime?: number;
};
Expand Down Expand Up @@ -58,6 +60,10 @@ export default function withParentSize<BaseComponentProps extends WithParentSize
if (this.resizeObserver) this.resizeObserver.disconnect();
}

setRef = (ref: HTMLDivElement) => {
this.container = ref;
};

resize = ({ width, height }: { width: number; height: number }) => {
this.setState({
parentWidth: width,
Expand All @@ -68,13 +74,8 @@ export default function withParentSize<BaseComponentProps extends WithParentSize
render() {
const { parentWidth, parentHeight } = this.state;
return (
<div
style={{ width: '100%', height: '100%' }}
ref={ref => {
this.container = ref;
}}
>
{parentWidth !== null && parentHeight !== null && (
<div style={CONTAINER_STYLES} ref={this.setRef}>
{parentWidth != null && parentHeight != null && (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to check for 0 as well?

<BaseComponent parentWidth={parentWidth} parentHeight={parentHeight} {...this.props} />
)}
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/vx-responsive/src/enhancers/withScreenSize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function withScreenSize<BaseComponentProps extends WithScreenSize

render() {
const { screenWidth, screenHeight } = this.state;
if (!screenWidth && !screenHeight) return null;
if (screenWidth == null || screenHeight == null) return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to check for 0 as well?

return (
<BaseComponent screenWidth={screenWidth} screenHeight={screenHeight} {...this.props} />
);
Expand Down