11import * as React from "react" ;
2- import { View , StyleProp , ViewStyle } from "react-native" ;
2+ import { View , StyleProp , ViewStyle , Alert } from "react-native" ;
33import RNBounceable from "@freakycoder/react-native-bounceable" ;
44/**
55 * ? Local Imports
@@ -12,6 +12,7 @@ export interface IRadioButtonProps {
1212 style ?: CustomStyleProp ;
1313 innerContainerStyle ?: CustomStyleProp ;
1414 isActive ?: boolean ;
15+ initial ?: boolean ;
1516 innerBackgroundColor ?: string ;
1617 onPress : ( isActive : boolean ) => void ;
1718}
@@ -27,19 +28,25 @@ export default class RadioButton extends React.Component<
2728 constructor ( props : IRadioButtonProps ) {
2829 super ( props ) ;
2930 this . state = {
30- isActive : props . isActive || false ,
31+ isActive : props . initial || false ,
3132 } ;
3233 }
3334
3435 handlePress = ( ) => {
35- this . setState ( { isActive : ! this . state . isActive } , ( ) => {
36- this . props . onPress && this . props . onPress ( this . state . isActive ) ;
37- } ) ;
36+ const { isActive = undefined } = this . props ;
37+ if ( isActive !== undefined && isActive !== null ) {
38+ this . props . onPress && this . props . onPress ( isActive ! ) ;
39+ } else {
40+ this . setState ( { isActive : ! this . state . isActive } , ( ) => {
41+ this . props . onPress && this . props . onPress ( this . state . isActive ) ;
42+ } ) ;
43+ }
3844 } ;
3945
4046 render ( ) {
4147 const {
4248 style,
49+ isActive = undefined ,
4350 innerContainerStyle,
4451 innerBackgroundColor = "red" ,
4552 } = this . props ;
@@ -50,7 +57,7 @@ export default class RadioButton extends React.Component<
5057 >
5158 < View
5259 style = { [
53- _innerStyle ( this . state . isActive , innerBackgroundColor ) ,
60+ _innerStyle ( isActive || this . state . isActive , innerBackgroundColor ) ,
5461 innerContainerStyle ,
5562 ] }
5663 />
0 commit comments