Skip to content

Commit a94f3d8

Browse files
authored
render checkbox container only if there's label (#1039)
1 parent 12d9637 commit a94f3d8

File tree

1 file changed

+41
-45
lines changed

1 file changed

+41
-45
lines changed

src/components/checkbox/index.tsx

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import _ from 'lodash';
22
import React, {Component} from 'react';
3-
import {
4-
Animated,
5-
Easing,
6-
StyleSheet,
7-
StyleProp,
8-
TouchableOpacityProps,
9-
ViewStyle,
10-
TextStyle
11-
} from 'react-native';
3+
import {Animated, Easing, StyleSheet, StyleProp, TouchableOpacityProps, ViewStyle, TextStyle} from 'react-native';
124
import {Colors} from '../../style';
135
//@ts-ignore
146
import Assets from '../../assets';
@@ -179,46 +171,50 @@ class Checkbox extends Component<CheckboxProps, CheckboxState> {
179171
return borderStyle;
180172
}
181173

182-
render() {
183-
const {selectedIcon, color, iconColor, disabled, testID, label, labelStyle, style, containerStyle, ...others} = this.props;
174+
renderCheckbox() {
175+
const {selectedIcon, color, iconColor, disabled, testID, style, containerStyle, ...others} = this.props;
176+
184177
return (
185-
<View row style={containerStyle}>
186-
{/*@ts-ignore*/}
187-
<TouchableOpacity
188-
{...this.getAccessibilityProps()}
189-
activeOpacity={1}
190-
testID={testID}
191-
{...others}
192-
style={[this.getBorderStyle(), style]}
193-
onPress={this.onPress}
194-
>
195-
{
196-
<Animated.View
178+
//@ts-ignore
179+
<TouchableOpacity
180+
{...this.getAccessibilityProps()}
181+
activeOpacity={1}
182+
testID={testID}
183+
{...others}
184+
style={[this.getBorderStyle(), style]}
185+
onPress={this.onPress}
186+
>
187+
{
188+
<Animated.View
189+
style={[this.styles.container, {backgroundColor: this.getColor()}, {opacity: this.animationStyle.opacity}]}
190+
>
191+
<Animated.Image
197192
style={[
198-
this.styles.container,
199-
{backgroundColor: this.getColor()},
200-
{opacity: this.animationStyle.opacity}
193+
this.styles.selectedIcon,
194+
color && {tintColor: iconColor},
195+
{transform: this.animationStyle.transform},
196+
disabled && {tintColor: DEFAULT_ICON_COLOR}
201197
]}
202-
>
203-
<Animated.Image
204-
style={[
205-
this.styles.selectedIcon,
206-
color && {tintColor: iconColor},
207-
{transform: this.animationStyle.transform},
208-
disabled && {tintColor: DEFAULT_ICON_COLOR}
209-
]}
210-
source={selectedIcon || Assets.icons.checkSmall}
211-
testID={`${testID}.selected`}
212-
/>
213-
</Animated.View>
214-
}
215-
</TouchableOpacity>
216-
{label && (
217-
<Text style={[this.styles.checkboxLabel, labelStyle]} onPress={this.onPress}>
218-
{label}
219-
</Text>
220-
)}
198+
source={selectedIcon || Assets.icons.checkSmall}
199+
testID={`${testID}.selected`}
200+
/>
201+
</Animated.View>
202+
}
203+
</TouchableOpacity>
204+
);
205+
}
206+
207+
render() {
208+
const {label, labelStyle, containerStyle} = this.props;
209+
return label ? (
210+
<View row centerV style={[containerStyle]}>
211+
{this.renderCheckbox()}
212+
<Text style={[this.styles.checkboxLabel, labelStyle]} onPress={this.onPress}>
213+
{label}
214+
</Text>
221215
</View>
216+
) : (
217+
this.renderCheckbox()
222218
);
223219
}
224220
}

0 commit comments

Comments
 (0)