Skip to content

Commit 1c49116

Browse files
ArnonZethanshar
authored andcommitted
Feat/Badge - Add onPress. (#519)
* Added onPress * Revert of unneeded styling * Unneeded file commit
1 parent 3203347 commit 1c49116

File tree

2 files changed

+20
-36
lines changed

2 files changed

+20
-36
lines changed

demo/src/screens/componentScreens/BadgesScreen.js

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,8 @@ export default class BadgesScreen extends Component {
2929
<Text text50 row center marginB-15>
3030
Badges
3131
</Text>
32-
<View row center>
33-
<View center marginH-10>
34-
<Badge label={'10'} backgroundColor={Colors.blue30} />
35-
<Badge
36-
label={'10'}
37-
containerStyle={{marginTop: BadgesSpace}}
38-
backgroundColor={Colors.blue30}
39-
borderWidth={3}
40-
borderColor={Colors.blue50}
41-
/>
42-
<Badge
43-
size="small"
44-
label={'10'}
45-
containerStyle={{marginTop: BadgesSpace}}
46-
backgroundColor={Colors.blue30}
47-
/>
48-
</View>
49-
50-
<View center marginH-10>
32+
<View row center style={{alignItems: 'flex-start'}}>
33+
<View center paddingH-10>
5134
<Badge label={this.state.value.toString()} backgroundColor={Colors.red30} />
5235
<Badge
5336
label={this.state.value.toString()}
@@ -63,7 +46,7 @@ export default class BadgesScreen extends Component {
6346
/>
6447
</View>
6548

66-
<View center marginH-10>
49+
<View center paddingH-10>
6750
<Badge label={'9999'} labelFormatterLimit={3} />
6851
<Badge
6952
label={'999'}
@@ -74,19 +57,6 @@ export default class BadgesScreen extends Component {
7457
/>
7558
<Badge labelFormatterLimit={1} size="small" label={'99999999'} containerStyle={{marginTop: BadgesSpace}} />
7659
</View>
77-
78-
<View center marginH-10>
79-
<Badge size={28} label={'9999'} labelFormatterLimit={3} />
80-
<Badge
81-
size={28}
82-
label={'999'}
83-
labelFormatterLimit={2}
84-
containerStyle={{marginTop: BadgesSpace}}
85-
borderWidth={2}
86-
borderColor={Colors.white}
87-
/>
88-
<Badge size={28} labelFormatterLimit={1} label={'99999999'} containerStyle={{marginTop: BadgesSpace}} />
89-
</View>
9060
</View>
9161

9262
<View row paddingT-20 marginB-15>

src/components/badge/index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import {StyleSheet, Text, ViewPropTypes} from 'react-native';
55
import {View as AnimatableView} from 'react-native-animatable';
66
import {PureBaseComponent} from '../../commons';
77
import {BorderRadiuses, Colors, ThemeManager, Typography} from '../../style';
8-
import View from '../view';
98
import Image from '../image';
9+
import TouchableOpacity from '../touchableOpacity';
10+
import View from '../view';
1011

1112
const LABEL_FORMATTER_VALUES = [1, 2, 3, 4];
1213

@@ -192,13 +193,24 @@ export default class Badge extends PureBaseComponent {
192193

193194
render() {
194195
// TODO: remove testId after deprecation
195-
const {borderWidth, backgroundColor, borderColor, containerStyle, icon, testId, testID, ...others} = this.props;
196+
const {
197+
activeOpacity,
198+
borderWidth,
199+
backgroundColor,
200+
borderColor,
201+
containerStyle,
202+
icon,
203+
onPress,
204+
testId,
205+
testID,
206+
...others
207+
} = this.props;
196208
const backgroundStyle = backgroundColor && {backgroundColor};
197209
const sizeStyle = this.getBadgeSizeStyle();
198210
const borderStyle = borderWidth ? this.getBorderStyling() : undefined;
199211

200212
const animationProps = this.extractAnimationProps();
201-
const Container = !_.isEmpty(animationProps) ? AnimatableView : View;
213+
const Container = !_.isEmpty(animationProps) ? AnimatableView : onPress ? TouchableOpacity : View;
202214
if (!_.isEmpty(animationProps)) {
203215
console.warn(
204216
'Badge component will soon stop supporting animationProps.' +
@@ -213,6 +225,8 @@ export default class Badge extends PureBaseComponent {
213225
testID={testID || testId}
214226
pointerEvents={'none'}
215227
style={[sizeStyle, this.styles.badge, borderStyle, backgroundStyle]}
228+
onPress={onPress}
229+
activeOpacity={activeOpacity}
216230
{...animationProps}
217231
>
218232
{icon ? this.renderIcon() : this.renderLabel()}

0 commit comments

Comments
 (0)