31
31
32
32
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
33
33
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
+
34
43
@implementation WXComponent (Display)
35
44
36
45
#pragma mark Public
@@ -61,7 +70,7 @@ - (BOOL)needsDrawRect
61
70
return YES ;
62
71
}
63
72
64
- if (![self _needsDrawBorder ]) {
73
+ if (![self _needsDrawBorder ] && _lastBorderRecords == WXComponentBorderRecordNone ) {
65
74
WXLogDebug (@" No need to draw border for %@ " , self.ref );
66
75
WXPerformBlockOnMainThread (^{
67
76
[self _resetNativeBorderRadius ];
@@ -354,6 +363,9 @@ - (void)_drawBorderWithContext:(CGContextRef)context size:(CGSize)size
354
363
CGContextAddLineToPoint (context, topLeft, _borderTopWidth/2 );
355
364
CGContextAddArc (context, topLeft, topLeft, topLeft-_borderTopWidth/2 , -M_PI_2, -M_PI_2-M_PI_4-(_borderLeftWidth>0 ?0 :M_PI_4), 1 );
356
365
CGContextStrokePath (context);
366
+ _lastBorderRecords |= WXComponentBorderRecordTop;
367
+ } else {
368
+ _lastBorderRecords &= ~(WXComponentBorderRecordTop);
357
369
}
358
370
359
371
// Left
@@ -372,6 +384,9 @@ - (void)_drawBorderWithContext:(CGContextRef)context size:(CGSize)size
372
384
CGContextAddLineToPoint (context, _borderLeftWidth/2 , size.height -bottomLeft);
373
385
CGContextAddArc (context, bottomLeft, size.height -bottomLeft, bottomLeft-_borderLeftWidth/2 , M_PI, M_PI-M_PI_4-(_borderBottomWidth>0 ?0 :M_PI_4), 1 );
374
386
CGContextStrokePath (context);
387
+ _lastBorderRecords |= WXComponentBorderRecordLeft;
388
+ } else {
389
+ _lastBorderRecords &= ~WXComponentBorderRecordLeft;
375
390
}
376
391
377
392
// Bottom
@@ -390,6 +405,9 @@ - (void)_drawBorderWithContext:(CGContextRef)context size:(CGSize)size
390
405
CGContextAddLineToPoint (context, size.width -bottomRight, size.height -_borderBottomWidth/2 );
391
406
CGContextAddArc (context, size.width -bottomRight, size.height -bottomRight, bottomRight-_borderBottomWidth/2 , M_PI_2, M_PI_4-(_borderRightWidth > 0 ?0 :M_PI_4), 1 );
392
407
CGContextStrokePath (context);
408
+ _lastBorderRecords |= WXComponentBorderRecordBottom;
409
+ } else {
410
+ _lastBorderRecords &= ~WXComponentBorderRecordBottom;
393
411
}
394
412
395
413
// Right
@@ -408,9 +426,15 @@ - (void)_drawBorderWithContext:(CGContextRef)context size:(CGSize)size
408
426
CGContextAddLineToPoint (context, size.width -_borderRightWidth/2 , topRight);
409
427
CGContextAddArc (context, size.width -topRight, topRight, topRight-_borderRightWidth/2 , 0 , -M_PI_4-(_borderTopWidth > 0 ?0 :M_PI_4), 1 );
410
428
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);
411
437
}
412
-
413
- CGContextStrokePath (context);
414
438
415
439
// clipRadius is beta feature
416
440
// TO DO: remove _clipRadius property
0 commit comments