Skip to content

Commit af5a5cc

Browse files
Inbal-Tishethanshar
authored andcommitted
fix for passing borderRadius 0 (#540)
1 parent 6fea4e4 commit af5a5cc

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

demo/src/screens/componentScreens/CardsScreen.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import _ from 'lodash';
22
import React, {Component} from 'react';
33
import {StyleSheet, ScrollView} from 'react-native';
4-
import {Constants, Colors, View, Card, Button, Text, Image} from 'react-native-ui-lib'; //eslint-disable-line
4+
import {Constants, Colors, View, Card, Button, Text, Image} from 'react-native-ui-lib'; // eslint-disable-line
55
import posts from '../../data/posts';
66

7+
78
const featureIcon = require('../../assets/icons/star.png');
89
const shareIcon = require('../../assets/icons/share.png');
910
const cardImage = require('../../assets/images/card-example.jpg');
@@ -12,18 +13,19 @@ const cardImage2 = require('../../assets/images/empty-state.jpg');
1213
export default class CardsScreen extends Component {
1314
state = {
1415
selected1: true,
15-
selected2: true,
16+
selected2: true
1617
};
1718

1819
render() {
1920
const {selected1, selected2} = this.state;
21+
2022
return (
2123
<View>
2224
<Image
2325
style={StyleSheet.absoluteFillObject}
2426
source={{
2527
uri:
26-
'https://images.pexels.com/photos/1005644/pexels-photo-1005644.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260',
28+
'https://images.pexels.com/photos/1005644/pexels-photo-1005644.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260'
2729
}}
2830
/>
2931

@@ -59,7 +61,7 @@ export default class CardsScreen extends Component {
5961
activeOpacity={1}
6062
marginR-20
6163
>
62-
<Card.Image height={'100%'} imageSource={cardImage} />
64+
<Card.Image height={'100%'} imageSource={cardImage}/>
6365
</Card>
6466
<Card
6567
height={120}
@@ -74,7 +76,7 @@ export default class CardsScreen extends Component {
7476
borderWidth: 3,
7577
}}
7678
>
77-
<Card.Image height={'100%'} imageSource={cardImage} />
79+
<Card.Image height={'100%'} imageSource={cardImage}/>
7880
</Card>
7981
</View>
8082

@@ -110,16 +112,15 @@ export default class CardsScreen extends Component {
110112
)}
111113
</View>
112114

113-
<Card row height={160} style={{marginBottom: 15}} onPress={() => {}} enableBlur>
114-
<Card.Image width={115} imageSource={cardImage} />
115+
<Card row height={160} style={{marginBottom: 15}} onPress={() => {}} enableBlur borderRadius={0}>
116+
<Card.Image width={115} imageSource={cardImage}/>
115117
<View padding-20 flex>
116118
<Text text70 dark10>
117119
You’re Invited!
118120
</Text>
119121
<Text text80 dark10>
120122
222 Join Old The Town Barbershop Official Store. Download the Wix app to...
121123
</Text>
122-
123124
<Text text90 dark50>
124125
wix.to/A465c
125126
</Text>
@@ -131,36 +132,34 @@ export default class CardsScreen extends Component {
131132
<Text text70 dark10>
132133
You’re Invited!
133134
</Text>
134-
135135
<Text text80 dark10>
136136
Join Old The Town Barbershop Official Store. Download the Wix app to...
137137
</Text>
138-
139138
<Text text90 dark50>
140139
wix.to/A465c
141140
</Text>
142141
</View>
143-
<Card.Image width={115} imageSource={cardImage} />
142+
<Card.Image width={115} imageSource={cardImage}/>
144143
</Card>
145144

146145
<Card style={{marginBottom: 15}} onPress={() => {}}>
147146
<View padding-20>
148147
<Text text70 dark10>
149148
You’re Invited!
150149
</Text>
151-
152150
<Text text90 dark50>
153151
join now
154152
</Text>
155153
</View>
156-
<Card.Image height={120} imageSource={cardImage2} />
154+
<Card.Image height={120} imageSource={cardImage2}/>
157155
</Card>
158156

159157
{_.map(posts, (post, i) => {
160158
const statusColor = post.status === 'Published' ? Colors.green30 : Colors.orange30;
159+
161160
return (
162161
<Card key={i} style={{marginBottom: 15}} onPress={() => console.log('press on a card')}>
163-
<Card.Image height={160} imageSource={post.coverImage} />
162+
<Card.Image height={160} imageSource={post.coverImage}/>
164163

165164
<View padding-20>
166165
<Text text40 color={Colors.dark10}>
@@ -182,8 +181,8 @@ export default class CardsScreen extends Component {
182181
{post.likes} Likes
183182
</Text>
184183
<View row right>
185-
<Button style={{marginRight: 10}} text90 link iconSource={featureIcon} label="Feature" />
186-
<Button text90 link iconSource={shareIcon} label="Share" />
184+
<Button style={{marginRight: 10}} text90 link iconSource={featureIcon} label="Feature"/>
185+
<Button text90 link iconSource={shareIcon} label="Share"/>
187186
</View>
188187
</View>
189188
</View>

src/components/card/index.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import CardItem from './CardItem';
1414
import CardImage from './CardImage';
1515
import Assets from '../../assets';
1616

17-
const DEFAULT_BORDER_RADIUS = BorderRadiuses.br40;
1817

18+
const DEFAULT_BORDER_RADIUS = BorderRadiuses.br40;
1919
const DEFAULT_SELECTION_PROPS = {
2020
borderWidth: 2,
2121
color: Colors.blue30,
@@ -147,31 +147,39 @@ class Card extends PureBaseComponent {
147147

148148
get elevationStyle() {
149149
const {elevation, enableShadow} = this.getThemeProps();
150+
150151
if (enableShadow) {
151152
return {elevation: elevation || 2};
152153
}
153154
}
154155

155156
get shadowStyle() {
156157
const {enableShadow} = this.getThemeProps();
158+
157159
if (enableShadow) {
158160
return this.styles.containerShadow;
159161
}
160162
}
161163

162164
get blurBgStyle() {
163165
const {enableBlur} = this.getThemeProps();
166+
164167
if (Constants.isIOS && enableBlur) {
165168
return {backgroundColor: Colors.rgba(Colors.white, 0.85)};
166169
} else {
167170
return {backgroundColor: Colors.white};
168171
}
169172
}
170173

174+
get borderRadius() {
175+
const {borderRadius} = this.getThemeProps();
176+
177+
return borderRadius === undefined ? DEFAULT_BORDER_RADIUS : borderRadius;
178+
}
179+
171180
renderSelection() {
172-
const {selectionOptions, borderRadius, selected} = this.getThemeProps();
181+
const {selectionOptions, selected} = this.getThemeProps();
173182
const {animatedSelected} = this.state;
174-
175183
const selectionColor = _.get(selectionOptions, 'color', DEFAULT_SELECTION_PROPS.color);
176184

177185
if (_.isUndefined(selected)) {
@@ -183,7 +191,7 @@ class Card extends PureBaseComponent {
183191
style={[
184192
this.styles.selectedBorder,
185193
{borderColor: selectionColor},
186-
borderRadius && {borderRadius},
194+
{borderRadius: this.borderRadius},
187195
{opacity: animatedSelected}
188196
]}
189197
pointerEvents="none"
@@ -196,13 +204,12 @@ class Card extends PureBaseComponent {
196204
}
197205

198206
renderChildren() {
199-
const {borderRadius} = this.getThemeProps();
200207
const children = React.Children.map(this.props.children, (child, index) => {
201208
if (_.get(child, 'type.displayName') === CardImage.displayName) {
202209
const position = this.calcImagePosition(index);
203210
return React.cloneElement(child, {
204211
position,
205-
borderRadius: borderRadius || DEFAULT_BORDER_RADIUS
212+
borderRadius: this.borderRadius
206213
});
207214
}
208215
return child;
@@ -211,10 +218,10 @@ class Card extends PureBaseComponent {
211218
}
212219

213220
render() {
214-
const {onPress, style, containerStyle, borderRadius, enableBlur, ...others} = this.getThemeProps();
221+
const {onPress, style, containerStyle, enableBlur, ...others} = this.getThemeProps();
215222
const blurOptions = this.getBlurOptions();
216223
const Container = onPress ? TouchableOpacity : View;
217-
const brRadius = borderRadius || DEFAULT_BORDER_RADIUS;
224+
const brRadius = this.borderRadius;
218225

219226
return (
220227
<Container
@@ -244,14 +251,16 @@ class Card extends PureBaseComponent {
244251
}
245252
}
246253

247-
function createStyles({width, height, borderRadius = DEFAULT_BORDER_RADIUS, selectionOptions}) {
254+
function createStyles({width, height, borderRadius, selectionOptions}) {
248255
const selectionOptionsWithDefaults = _.merge(DEFAULT_SELECTION_PROPS, selectionOptions);
256+
const brRadius = borderRadius === undefined ? DEFAULT_BORDER_RADIUS : borderRadius;
257+
249258
return StyleSheet.create({
250259
container: {
251260
width,
252261
height,
253262
overflow: 'visible',
254-
borderRadius
263+
borderRadius: brRadius
255264
},
256265
containerShadow: {
257266
// sh30 bottom
@@ -262,7 +271,7 @@ function createStyles({width, height, borderRadius = DEFAULT_BORDER_RADIUS, sele
262271
},
263272
blurView: {
264273
...StyleSheet.absoluteFillObject,
265-
borderRadius
274+
borderRadius: brRadius
266275
},
267276
selectedBorder: {
268277
...StyleSheet.absoluteFillObject,

0 commit comments

Comments
 (0)