Skip to content

Commit e4c30ca

Browse files
committed
Fix to deal with changes to size and anchor properties on anchored spaces and adjusted spaces accordingly.
1 parent 5444b8b commit e4c30ca

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

demo/src/docs/VersionHistory.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ export const VersionHistory = () => {
55
<>
66
<h2 id="changes">Version history</h2>
77

8+
<div>
9+
<h3>0.1.11</h3>
10+
<ul>
11+
<li>
12+
Fix to deal with changes to size and anchor properties on anchored
13+
spaces and adjusted spaces accordingly.
14+
</li>
15+
</ul>
16+
</div>
817
<div>
918
<h3>0.1.10</h3>
1019
<ul>

react-spaces/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-spaces",
3-
"version": "0.1.10",
3+
"version": "0.1.11",
44
"main": "dist/index.js",
55
"repository": "github:aeagle/react-spaces",
66
"author": {

react-spaces/src/components/Space.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,21 @@ class Space extends React.Component<AllProps, IState> {
115115
}
116116
}
117117

118+
public componentWillReceiveProps(nextProps: AllProps) {
119+
if (this.props.size !== nextProps.size ||
120+
this.props.anchor !== nextProps.anchor) {
121+
this.setState({
122+
parsedSize: typeof nextProps.size === "string" ? 0 : nextProps.size as number | undefined,
123+
left: nextProps.anchor !== AnchorType.Right ? 0 : undefined,
124+
top: nextProps.anchor !== AnchorType.Bottom ? 0 : undefined,
125+
right: nextProps.anchor !== AnchorType.Left ? 0 : undefined,
126+
bottom: nextProps.anchor !== AnchorType.Top ? 0 : undefined,
127+
width: this.isHorizontalSpace() ? nextProps.size || 0 : undefined,
128+
height: this.isVerticalSpace() ? nextProps.size || 0 : undefined
129+
})
130+
}
131+
}
132+
118133
public componentWillUnmount() {
119134
if (this.props.trackSize) {
120135
if (this.resizeSensor) {
@@ -298,10 +313,17 @@ class Space extends React.Component<AllProps, IState> {
298313
spaceTakers: this.state.spaceTakers,
299314
registerSpaceTaker:
300315
(spaceTaker: ISpaceTaker) => {
301-
if (!this.state.spaceTakers.find(t => t.id === spaceTaker.id)) {
316+
const existing = this.state.spaceTakers.find(t => t.id === spaceTaker.id);
317+
318+
if (!existing) {
302319
this.setState({
303320
spaceTakers: [ ...this.state.spaceTakers, spaceTaker ]
304321
})
322+
} else {
323+
existing.adjustedSize = 0;
324+
existing.order = spaceTaker.order;
325+
existing.anchorType = spaceTaker.anchorType;
326+
existing.size = spaceTaker.size;
305327
}
306328
},
307329
removeSpaceTaker:

0 commit comments

Comments
 (0)