Skip to content
This repository was archived by the owner on Jun 3, 2021. It is now read-only.

Commit cc9ba8d

Browse files
committed
[iOS] Fix the border of view hasn't gone after changing border width to 0 dynamically; (#2153)
1 parent f95db5a commit cc9ba8d

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ typedef id (^WXDataBindingBlock)(NSDictionary *data, BOOL *needUpdate);
130130
WXBorderStyle _borderBottomStyle;
131131
WXBorderStyle _borderLeftStyle;
132132

133+
NSInteger _lastBorderRecords; // Records last border drawing
134+
133135
BOOL _isViewTreeIgnored; // Component is added to super, but it is not added to views.
134136
BOOL _isFixed;
135137
BOOL _async;

ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@
3131

3232
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
3333

34+
typedef NS_ENUM(NSInteger, WXComponentBorderRecord) {
35+
WXComponentBorderRecordNone = 0,
36+
WXComponentBorderRecordTop = 1,
37+
WXComponentBorderRecordRight = 1 << 1,
38+
WXComponentBorderRecordBottom = 1 << 2,
39+
WXComponentBorderRecordLeft = 1 << 3,
40+
WXComponentBorderRecordAll = WXComponentBorderRecordTop | WXComponentBorderRecordRight | WXComponentBorderRecordBottom | WXComponentBorderRecordLeft
41+
};
42+
3443
@implementation WXComponent (Display)
3544

3645
#pragma mark Public
@@ -61,7 +70,7 @@ - (BOOL)needsDrawRect
6170
return YES;
6271
}
6372

64-
if (![self _needsDrawBorder]) {
73+
if (![self _needsDrawBorder] && _lastBorderRecords == WXComponentBorderRecordNone) {
6574
WXLogDebug(@"No need to draw border for %@", self.ref);
6675
WXPerformBlockOnMainThread(^{
6776
[self _resetNativeBorderRadius];
@@ -354,6 +363,9 @@ - (void)_drawBorderWithContext:(CGContextRef)context size:(CGSize)size
354363
CGContextAddLineToPoint(context, topLeft, _borderTopWidth/2);
355364
CGContextAddArc(context, topLeft, topLeft, topLeft-_borderTopWidth/2, -M_PI_2, -M_PI_2-M_PI_4-(_borderLeftWidth>0?0:M_PI_4), 1);
356365
CGContextStrokePath(context);
366+
_lastBorderRecords |= WXComponentBorderRecordTop;
367+
} else {
368+
_lastBorderRecords &= ~(WXComponentBorderRecordTop);
357369
}
358370

359371
// Left
@@ -372,6 +384,9 @@ - (void)_drawBorderWithContext:(CGContextRef)context size:(CGSize)size
372384
CGContextAddLineToPoint(context, _borderLeftWidth/2, size.height-bottomLeft);
373385
CGContextAddArc(context, bottomLeft, size.height-bottomLeft, bottomLeft-_borderLeftWidth/2, M_PI, M_PI-M_PI_4-(_borderBottomWidth>0?0:M_PI_4), 1);
374386
CGContextStrokePath(context);
387+
_lastBorderRecords |= WXComponentBorderRecordLeft;
388+
} else {
389+
_lastBorderRecords &= ~WXComponentBorderRecordLeft;
375390
}
376391

377392
// Bottom
@@ -390,6 +405,9 @@ - (void)_drawBorderWithContext:(CGContextRef)context size:(CGSize)size
390405
CGContextAddLineToPoint(context, size.width-bottomRight, size.height-_borderBottomWidth/2);
391406
CGContextAddArc(context, size.width-bottomRight, size.height-bottomRight, bottomRight-_borderBottomWidth/2, M_PI_2, M_PI_4-(_borderRightWidth > 0?0:M_PI_4), 1);
392407
CGContextStrokePath(context);
408+
_lastBorderRecords |= WXComponentBorderRecordBottom;
409+
} else {
410+
_lastBorderRecords &= ~WXComponentBorderRecordBottom;
393411
}
394412

395413
// Right
@@ -408,9 +426,15 @@ - (void)_drawBorderWithContext:(CGContextRef)context size:(CGSize)size
408426
CGContextAddLineToPoint(context, size.width-_borderRightWidth/2, topRight);
409427
CGContextAddArc(context, size.width-topRight, topRight, topRight-_borderRightWidth/2, 0, -M_PI_4-(_borderTopWidth > 0?0:M_PI_4), 1);
410428
CGContextStrokePath(context);
429+
_lastBorderRecords |= WXComponentBorderRecordRight;
430+
} else {
431+
_lastBorderRecords &= ~WXComponentBorderRecordRight;
432+
}
433+
if (_lastBorderRecords <= 0 || _lastBorderRecords > WXComponentBorderRecordAll) {
434+
CGContextClearRect(context, rect);
435+
} else {
436+
CGContextStrokePath(context);
411437
}
412-
413-
CGContextStrokePath(context);
414438

415439
//clipRadius is beta feature
416440
//TO DO: remove _clipRadius property

0 commit comments

Comments
 (0)