|
1 | 1 | import _ from 'lodash'; |
2 | 2 | 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'; |
12 | 4 | import {Colors} from '../../style'; |
13 | 5 | //@ts-ignore |
14 | 6 | import Assets from '../../assets'; |
@@ -179,46 +171,50 @@ class Checkbox extends Component<CheckboxPropTypes, CheckboxState> { |
179 | 171 | return borderStyle; |
180 | 172 | } |
181 | 173 |
|
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 | + |
184 | 177 | 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 |
197 | 192 | 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} |
201 | 197 | ]} |
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> |
221 | 215 | </View> |
| 216 | + ) : ( |
| 217 | + this.renderCheckbox() |
222 | 218 | ); |
223 | 219 | } |
224 | 220 | } |
|
0 commit comments