Skip to content

Commit 1189046

Browse files
lidord-wixLidor Dafna
andauthored
add border radius to badge (#865)
* add border radius to badge * change examples * remove commented examples Co-authored-by: Lidor Dafna <[email protected]>
1 parent d524bfb commit 1189046

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ build/
2929
.gradle
3030
local.properties
3131
*.iml
32+
android/gradlew.bat
33+
expoDemo/android/gradlew.bat
3234

3335
# node.js
3436
#
@@ -65,3 +67,4 @@ package-lock.json
6567
/ios/Pods/
6668
/ios/Podfile.lock
6769
expoDemo/ios/Pods
70+

demo/src/screens/componentScreens/BadgesScreen.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ const BadgesSpace = 30;
55
const plusIcon = require('../../assets/icons/chevronUp.png');
66
const minusIcon = require('../../assets/icons/chevronDown.png');
77
const star = require('../../assets/icons/star.png');
8+
const search = require('../../assets/icons/search.png');
9+
810

911
export default class BadgesScreen extends Component {
1012
constructor(props) {
@@ -127,6 +129,13 @@ export default class BadgesScreen extends Component {
127129
large(24)
128130
</Text>
129131
</View>
132+
133+
<View style={styles.iconBadgeColumnContainer}>
134+
<Badge icon={star} borderRadius={6} iconStyle={{backgroundColor: Colors.red30}}/>
135+
<Text text80 style={{marginTop: 10}}>
136+
border radius (6)
137+
</Text>
138+
</View>
130139
</View>
131140
</ScrollView>
132141
);

src/components/badge/index.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ export default class Badge extends PureBaseComponent {
5757
* width of border around the badge
5858
*/
5959
borderWidth: PropTypes.number,
60+
/**
61+
* radius of border around the badge
62+
*/
63+
borderRadius: PropTypes.number,
6064
/**
6165
* color of border around the badge
6266
*/
@@ -174,11 +178,16 @@ export default class Badge extends PureBaseComponent {
174178
}
175179

176180
getBorderStyling() {
177-
const {borderWidth, borderColor} = this.props;
178-
return {
179-
borderWidth,
180-
borderColor
181-
};
181+
const {borderWidth, borderColor, borderRadius} = this.props;
182+
const style = {};
183+
if (borderWidth) {
184+
style.borderWidth = borderWidth;
185+
style.borderColor = borderColor;
186+
}
187+
if (borderRadius) {
188+
style.borderRadius = borderRadius;
189+
}
190+
return style;
182191
}
183192

184193
renderLabel() {
@@ -218,7 +227,6 @@ export default class Badge extends PureBaseComponent {
218227
// TODO: remove testId after deprecation
219228
const {
220229
activeOpacity,
221-
borderWidth,
222230
backgroundColor,
223231
containerStyle,
224232
hitSlop,
@@ -230,7 +238,7 @@ export default class Badge extends PureBaseComponent {
230238
} = this.props;
231239
const backgroundStyle = backgroundColor && {backgroundColor};
232240
const sizeStyle = this.getBadgeSizeStyle();
233-
const borderStyle = borderWidth ? this.getBorderStyling() : undefined;
241+
const borderStyle = this.getBorderStyling();
234242

235243
const animationProps = this.extractAnimationProps();
236244
const Container = !_.isEmpty(animationProps) ? AnimatableView : onPress ? TouchableOpacity : View;
@@ -240,7 +248,7 @@ export default class Badge extends PureBaseComponent {
240248
}
241249
return (
242250
// The extra View wrapper is to break badge's flex-ness
243-
<View style={containerStyle} {...others} backgroundColor={undefined} {...this.getAccessibilityProps()}>
251+
<View style={containerStyle} {...others} backgroundColor={undefined} borderWidth={undefined} {...this.getAccessibilityProps()}>
244252
<Container
245253
testID={testID || testId}
246254
pointerEvents={'none'}

0 commit comments

Comments
 (0)