Skip to content

Commit 7d6a102

Browse files
committed
fix: ios allow changing rect top,left,bottom,right
1 parent e27898d commit 7d6a102

File tree

1 file changed

+48
-14
lines changed

1 file changed

+48
-14
lines changed

Diff for: src/canvas.ios.ts

+48-14
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,54 @@ function createCGRect(l, t, r, b) {
169169
}
170170

171171
export class Rect implements IRect {
172+
_rect: CGRect;
173+
_left: number;
174+
_top: number;
175+
_right: number;
176+
_bottom: number;
177+
178+
private updateCGRect() {
179+
this.cgRect = createCGRect(this._left, this._top, this._right, this._bottom);
180+
181+
}
182+
183+
get left() {
184+
return this._left;
185+
}
186+
set left(value: number) {
187+
this._left = value;
188+
this.updateCGRect();
189+
}
190+
get top() {
191+
return this._top;
192+
}
193+
set top(value: number) {
194+
this._top = value;
195+
this.updateCGRect();
196+
}
197+
get right() {
198+
return this._right;
199+
}
200+
set right(value: number) {
201+
this._right = value;
202+
this.updateCGRect();
203+
}
204+
get bottom() {
205+
return this._bottom;
206+
}
207+
set bottom(value: number) {
208+
this._bottom = value;
209+
this.updateCGRect();
210+
}
172211
get cgRect() {
173212
return this._rect;
174213
}
175214
set cgRect(rect: CGRect) {
176215
this._rect = rect;
177-
this.left = this._rect.origin.x;
178-
this.top = this._rect.origin.y;
179-
this.right = this.left + this._rect.size.width;
180-
this.bottom = this.top + this._rect.size.height;
216+
this._left = this._rect.origin.x;
217+
this._top = this._rect.origin.y;
218+
this._right = this._left + this._rect.size.width;
219+
this._bottom = this._top + this._rect.size.height;
181220
}
182221

183222
// public set(rect: Rect) {
@@ -191,11 +230,11 @@ export class Rect implements IRect {
191230
this.cgRect = args[0];
192231
}
193232
} else {
194-
// const l = (this.left = args[0]);
195-
// const t = (this.top = args[1]);
196-
// const r = (this.right = args[2]);
197-
// const b = (this.bottom = args[3]);
198-
this.cgRect = createCGRect(args[0], args[1], args[2], args[3]);
233+
this._left = args[0];
234+
this._top = args[1];
235+
this._right = args[2];
236+
this._bottom = args[3];
237+
this.updateCGRect();
199238
}
200239
}
201240
public inset(dx: number, dy: number): void {
@@ -242,11 +281,6 @@ export class Rect implements IRect {
242281
}
243282
return CGRectContainsRect(this.cgRect, rect);
244283
}
245-
_rect: CGRect;
246-
left: number;
247-
top: number;
248-
right: number;
249-
bottom: number;
250284
constructor(...args) {
251285
this.set.apply(this, args);
252286
}

0 commit comments

Comments
 (0)