Skip to content

Commit b1d9e88

Browse files
authored
Merge pull request #6 from sevvaleygul0/master
The feature to add images to checkbox has been added
2 parents 9fd398b + 5bce2d8 commit b1d9e88

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

example/App.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const App = () => {
1010
style={{
1111
flex: 1,
1212
alignItems: "center",
13-
justifyContent: "center"
13+
justifyContent: "center",
1414
}}
1515
>
1616
<RadioButton
@@ -30,6 +30,7 @@ const App = () => {
3030
isBounceable={false}
3131
animation={"bounceIn"}
3232
onPress={() => console.log("RadioButton is pressed")}
33+
disableText={true}
3334
/>
3435
</View>
3536
<View style={{ marginTop: 16 }}>
@@ -41,6 +42,7 @@ const App = () => {
4142
outerColor="#6a29d9"
4243
animation={"bounceIn"}
4344
onPress={() => console.log("RadioButton is pressed")}
45+
disableImage={true}
4446
/>
4547
</View>
4648
</SafeAreaView>

example/ios/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ DEPENDENCIES:
250250
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
251251

252252
SPEC REPOS:
253-
https://github.com/cocoapods/specs.git:
253+
trunk:
254254
- boost-for-react-native
255255

256256
EXTERNAL SOURCES:
@@ -335,4 +335,4 @@ SPEC CHECKSUMS:
335335

336336
PODFILE CHECKSUM: 79310af6b976c356911a8a833e9b99c3399fdda3
337337

338-
COCOAPODS: 1.7.4
338+
COCOAPODS: 1.9.3

lib/src/RadioButton.js

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import React, { Component } from "react";
22
import PropTypes from "prop-types";
3-
import { Animated, Easing, Text, TouchableOpacity } from "react-native";
3+
import { Animated, Easing, Text, TouchableOpacity, Image } from "react-native";
44
import { View } from "react-native-animatable";
55
import styles, {
66
textStyle,
77
innerStyle,
88
outerStyle,
99
isHorizontal,
1010
textContainer,
11-
transformStyle
11+
transformStyle,
1212
} from "./RadioButton.style";
1313

1414
export default class RadioButton extends Component {
1515
constructor(props) {
1616
super(props);
1717
this.state = {
1818
_isSelected: this.props.isSelected,
19-
springValue: new Animated.Value(1)
19+
springValue: new Animated.Value(1),
2020
};
2121
}
2222

@@ -34,7 +34,7 @@ export default class RadioButton extends Component {
3434
springValue.setValue(0.7);
3535
Animated.spring(springValue, {
3636
toValue: 1,
37-
friction: 5
37+
friction: 5,
3838
}).start();
3939
};
4040

@@ -49,7 +49,11 @@ export default class RadioButton extends Component {
4949
innerColor,
5050
outerColor,
5151
disableText,
52-
disableBuiltinStateManagement
52+
disableBuiltinStateManagement,
53+
imageSource,
54+
imageStyle,
55+
disableImage,
56+
ImageComponent = Image,
5357
} = this.props;
5458
const { springValue, _isSelected } = this.state;
5559

@@ -66,20 +70,26 @@ export default class RadioButton extends Component {
6670
style={[
6771
outerStyle(size, outerColor),
6872
transformStyle(springValue),
69-
styles.center
73+
styles.center,
7074
]}
7175
>
7276
{stateManagement ? (
7377
<View style={innerStyle(size, innerColor)} {...this.props} />
7478
) : null}
7579
</Animated.View>
76-
{disableText || (
77-
<View style={textContainer(horizontal)}>
80+
<View style={textContainer(horizontal)}>
81+
{!disableImage && (
82+
<ImageComponent
83+
style={imageStyle || styles.imageStyle}
84+
source={imageSource}
85+
/>
86+
)}
87+
{!disableText && (
7888
<Text style={textStyle(textColor, innerColor, fontSize)}>
7989
{text}
8090
</Text>
81-
</View>
82-
)}
91+
)}
92+
</View>
8393
</TouchableOpacity>
8494
);
8595
}
@@ -95,7 +105,7 @@ RadioButton.propTypes = {
95105
disableText: PropTypes.bool,
96106
isBounceable: PropTypes.bool,
97107
innerColor: PropTypes.string,
98-
outerColor: PropTypes.string
108+
outerColor: PropTypes.string,
99109
};
100110

101111
RadioButton.defaultProps = {
@@ -108,5 +118,5 @@ RadioButton.defaultProps = {
108118
onPress: () => null,
109119
text: "Radio Button",
110120
innerColor: "dodgerblue",
111-
outerColor: "dodgerblue"
121+
outerColor: "dodgerblue",
112122
};

lib/src/RadioButton.style.js

+9
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,19 @@ export const textStyle = (textColor, innerColor, fontSize) => ({
3535
export const textContainer = (horizontal) => ({
3636
marginTop: horizontal ? 8 : 0,
3737
marginLeft: horizontal ? 0 : 8,
38+
flexDirection: "row",
39+
justifyContent: "center",
40+
alignItems: "center",
3841
});
3942

4043
export default {
4144
center: {
4245
alignItems: "center",
4346
},
47+
imageStyle: {
48+
width: 35,
49+
height: 35,
50+
marginRight: 8,
51+
marginLeft: 4,
52+
},
4453
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-animated-radio-button",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Fully customizable animated radio button for React Native",
55
"keywords": [
66
"bouncy",

0 commit comments

Comments
 (0)