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

Commit

Permalink
[iOS] Fix the border of view hasn't gone after changing border width …
Browse files Browse the repository at this point in the history
…to 0 dynamically; (#2153)
  • Loading branch information
NickeyLin committed Mar 14, 2019
1 parent f95db5a commit cc9ba8d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ios/sdk/WeexSDK/Sources/Component/WXComponent_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ typedef id (^WXDataBindingBlock)(NSDictionary *data, BOOL *needUpdate);
WXBorderStyle _borderBottomStyle;
WXBorderStyle _borderLeftStyle;

NSInteger _lastBorderRecords; // Records last border drawing

BOOL _isViewTreeIgnored; // Component is added to super, but it is not added to views.
BOOL _isFixed;
BOOL _async;
Expand Down
30 changes: 27 additions & 3 deletions ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@

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

typedef NS_ENUM(NSInteger, WXComponentBorderRecord) {
WXComponentBorderRecordNone = 0,
WXComponentBorderRecordTop = 1,
WXComponentBorderRecordRight = 1 << 1,
WXComponentBorderRecordBottom = 1 << 2,
WXComponentBorderRecordLeft = 1 << 3,
WXComponentBorderRecordAll = WXComponentBorderRecordTop | WXComponentBorderRecordRight | WXComponentBorderRecordBottom | WXComponentBorderRecordLeft
};

@implementation WXComponent (Display)

#pragma mark Public
Expand Down Expand Up @@ -61,7 +70,7 @@ - (BOOL)needsDrawRect
return YES;
}

if (![self _needsDrawBorder]) {
if (![self _needsDrawBorder] && _lastBorderRecords == WXComponentBorderRecordNone) {
WXLogDebug(@"No need to draw border for %@", self.ref);
WXPerformBlockOnMainThread(^{
[self _resetNativeBorderRadius];
Expand Down Expand Up @@ -354,6 +363,9 @@ - (void)_drawBorderWithContext:(CGContextRef)context size:(CGSize)size
CGContextAddLineToPoint(context, topLeft, _borderTopWidth/2);
CGContextAddArc(context, topLeft, topLeft, topLeft-_borderTopWidth/2, -M_PI_2, -M_PI_2-M_PI_4-(_borderLeftWidth>0?0:M_PI_4), 1);
CGContextStrokePath(context);
_lastBorderRecords |= WXComponentBorderRecordTop;
} else {
_lastBorderRecords &= ~(WXComponentBorderRecordTop);
}

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

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

// Right
Expand All @@ -408,9 +426,15 @@ - (void)_drawBorderWithContext:(CGContextRef)context size:(CGSize)size
CGContextAddLineToPoint(context, size.width-_borderRightWidth/2, topRight);
CGContextAddArc(context, size.width-topRight, topRight, topRight-_borderRightWidth/2, 0, -M_PI_4-(_borderTopWidth > 0?0:M_PI_4), 1);
CGContextStrokePath(context);
_lastBorderRecords |= WXComponentBorderRecordRight;
} else {
_lastBorderRecords &= ~WXComponentBorderRecordRight;
}
if (_lastBorderRecords <= 0 || _lastBorderRecords > WXComponentBorderRecordAll) {
CGContextClearRect(context, rect);
} else {
CGContextStrokePath(context);
}

CGContextStrokePath(context);

//clipRadius is beta feature
//TO DO: remove _clipRadius property
Expand Down

0 comments on commit cc9ba8d

Please sign in to comment.