Skip to content

Commit ff49d86

Browse files
committed
Implemented fast path for same borders/radii
1 parent 3b24f52 commit ff49d86

File tree

5 files changed

+490
-333
lines changed

5 files changed

+490
-333
lines changed

Examples/UIExplorer/BorderExample.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,15 @@ var styles = StyleSheet.create({
8181
borderTopLeftRadius: 100,
8282
},
8383
border7: {
84-
borderRadius: 20,
84+
borderWidth: 10,
85+
borderColor: 'rgba(255,0,0,0.5)',
86+
borderRadius: 30,
87+
overflow: 'hidden',
8588
},
8689
border7_inner: {
8790
backgroundColor: 'blue',
88-
flex: 1,
91+
width: 100,
92+
height: 100
8993
},
9094
});
9195

React/React.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
13B080261A694A8400A75B9A /* RCTWrapperViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B080241A694A8400A75B9A /* RCTWrapperViewController.m */; };
4040
13C156051AB1A2840079392D /* RCTWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 13C156021AB1A2840079392D /* RCTWebView.m */; };
4141
13C156061AB1A2840079392D /* RCTWebViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13C156041AB1A2840079392D /* RCTWebViewManager.m */; };
42+
13CC8A821B17642100940AE7 /* RCTBorderDrawing.m in Sources */ = {isa = PBXBuildFile; fileRef = 13CC8A811B17642100940AE7 /* RCTBorderDrawing.m */; };
4243
13E0674A1A70F434002CDEE1 /* RCTUIManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E067491A70F434002CDEE1 /* RCTUIManager.m */; };
4344
13E067551A70F44B002CDEE1 /* RCTShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E0674C1A70F44B002CDEE1 /* RCTShadowView.m */; };
4445
13E067561A70F44B002CDEE1 /* RCTViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 13E0674E1A70F44B002CDEE1 /* RCTViewManager.m */; };
@@ -155,6 +156,8 @@
155156
13C325261AA63B6A0048765F /* RCTAutoInsetsProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTAutoInsetsProtocol.h; sourceTree = "<group>"; };
156157
13C325271AA63B6A0048765F /* RCTScrollableProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTScrollableProtocol.h; sourceTree = "<group>"; };
157158
13C325281AA63B6A0048765F /* RCTViewNodeProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTViewNodeProtocol.h; sourceTree = "<group>"; };
159+
13CC8A801B17642100940AE7 /* RCTBorderDrawing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTBorderDrawing.h; sourceTree = "<group>"; };
160+
13CC8A811B17642100940AE7 /* RCTBorderDrawing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTBorderDrawing.m; sourceTree = "<group>"; };
158161
13E067481A70F434002CDEE1 /* RCTUIManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTUIManager.h; sourceTree = "<group>"; };
159162
13E067491A70F434002CDEE1 /* RCTUIManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTUIManager.m; sourceTree = "<group>"; };
160163
13E0674B1A70F44B002CDEE1 /* RCTShadowView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTShadowView.h; sourceTree = "<group>"; };
@@ -279,6 +282,8 @@
279282
children = (
280283
13442BF21AA90E0B0037E5B0 /* RCTAnimationType.h */,
281284
13C325261AA63B6A0048765F /* RCTAutoInsetsProtocol.h */,
285+
13CC8A801B17642100940AE7 /* RCTBorderDrawing.h */,
286+
13CC8A811B17642100940AE7 /* RCTBorderDrawing.m */,
282287
58C571C01AA56C1900CDF9C8 /* RCTDatePickerManager.h */,
283288
58C571BF1AA56C1900CDF9C8 /* RCTDatePickerManager.m */,
284289
13456E911ADAD2DE009F94A7 /* RCTConvert+CoreLocation.h */,
@@ -513,6 +518,7 @@
513518
830A229E1A66C68A008503DA /* RCTRootView.m in Sources */,
514519
13B07FF01A69327A00A75B9A /* RCTExceptionsManager.m in Sources */,
515520
83CBBA5A1A601E9000E9B192 /* RCTRedBox.m in Sources */,
521+
13CC8A821B17642100940AE7 /* RCTBorderDrawing.m in Sources */,
516522
83CBBA511A601E3B00E9B192 /* RCTAssert.m in Sources */,
517523
13AF20451AE707F9005F5298 /* RCTSlider.m in Sources */,
518524
58114A501AAE93D500E7D092 /* RCTAsyncLocalStorage.m in Sources */,

React/Views/RCTBorderDrawing.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
#import <UIKit/UIKit.h>
11+
12+
typedef struct {
13+
CGFloat topLeft;
14+
CGFloat topRight;
15+
CGFloat bottomLeft;
16+
CGFloat bottomRight;
17+
} RCTCornerRadii;
18+
19+
typedef struct {
20+
CGSize topLeft;
21+
CGSize topRight;
22+
CGSize bottomLeft;
23+
CGSize bottomRight;
24+
} RCTCornerInsets;
25+
26+
typedef struct {
27+
CGColorRef top;
28+
CGColorRef left;
29+
CGColorRef bottom;
30+
CGColorRef right;
31+
} RCTBorderColors;
32+
33+
/**
34+
* Determine if the border widths, colors and radii are all equal.
35+
*/
36+
BOOL RCTBorderInsetsAreEqual(UIEdgeInsets borderInsets);
37+
BOOL RCTCornerRadiiAreEqual(RCTCornerRadii cornerRadii);
38+
BOOL RCTBorderColorsAreEqual(RCTBorderColors borderColors);
39+
40+
/**
41+
* Convert RCTCornerRadii to RCTCornerInsets by applying border insets.
42+
*/
43+
RCTCornerInsets RCTGetCornerInsets(RCTCornerRadii cornerRadii,
44+
UIEdgeInsets borderInsets);
45+
46+
/**
47+
* Create a CGPath representing a rounded rectangle with the specified bounds
48+
* and corner insets. Note that the CGPathRef must be released by the caller.
49+
*/
50+
CGPathRef RCTPathCreateWithRoundedRect(CGRect bounds,
51+
RCTCornerInsets cornerInsets,
52+
const CGAffineTransform *transform);
53+
54+
/**
55+
* Draw a CSS-compliant border as a scalable image.
56+
*/
57+
UIImage *RCTGetBorderImage(RCTCornerRadii cornerRadii,
58+
UIEdgeInsets borderInsets,
59+
RCTBorderColors borderColors,
60+
CGColorRef backgroundColor,
61+
BOOL drawToEdge);

0 commit comments

Comments
 (0)