Skip to content

Commit

Permalink
Added optional trackSize property and only enabled ResizeSensor based…
Browse files Browse the repository at this point in the history
… on this
  • Loading branch information
aeagle committed Jul 22, 2019
1 parent 2583456 commit 4d96ad2
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions react-spaces/src/components/Space.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ interface IPublicProps {
id?: string,
className?: string,
style?: React.CSSProperties,
scrollable?: boolean
scrollable?: boolean,
trackSize?: boolean
}

interface IPrivateProps {
Expand Down Expand Up @@ -88,20 +89,24 @@ class Space extends React.Component<AllProps, IState> {

public componentDidMount() {
if (this.divElementRef.current) {
this.resizeSensor = new ResizeSensor(this.divElementRef.current, this.spaceResized);
if (this.props.trackSize) {
this.resizeSensor = new ResizeSensor(this.divElementRef.current, this.spaceResized);
}

const currentRect = this.divElementRef.current.getBoundingClientRect();
this.setState({
currentWidth: currentRect.width,
currentHeight: currentRect.height
currentWidth: parseInt(currentRect.width.toFixed(), 10),
currentHeight: parseInt(currentRect.height.toFixed(), 10)
});
}
}

public componentWillUnmount() {
if (this.resizeSensor) {
this.resizeSensor.detach();
this.resizeSensor = undefined;
if (this.props.trackSize) {
if (this.resizeSensor) {
this.resizeSensor.detach();
this.resizeSensor = undefined;
}
}

if (this.onRemove) {
Expand Down Expand Up @@ -232,7 +237,7 @@ class Space extends React.Component<AllProps, IState> {
style={{ ...style, ...this.props.style }}>

<SpaceContext.Provider value={currentContext}>
<SpaceInfoContext.Provider value={{ width: this.state.currentWidth, height: this.state.currentHeight }}>
<SpaceInfoContext.Provider value={{ width: Math.floor(this.state.currentWidth), height: Math.floor(this.state.currentHeight) }}>
{ spaceRender }
</SpaceInfoContext.Provider>
</SpaceContext.Provider>
Expand Down

0 comments on commit 4d96ad2

Please sign in to comment.