Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to show text (YES/NO) inside a switch in react-native #16

Open
lavarajallu opened this issue Nov 29, 2016 · 7 comments
Open

How to show text (YES/NO) inside a switch in react-native #16

lavarajallu opened this issue Nov 29, 2016 · 7 comments

Comments

@lavarajallu
Copy link

I am new to react-native. In my app, I'm using a switch and changing the tint color to differentiate ON and OFF, but my actual requirement is to show "YES" or "NO" text inside the switch like below.

image

Here is my Code:


Please give me suggestions to solve this issue, Any help much appreciated.

@tioback
Copy link

tioback commented Dec 2, 2016

Have you tried buttonContent?

<Switch 
    buttonContent={this.state.active? "YES" : "NO"} 
    onActivate={() => this.setState({active: true})}
    onDeactivate={() => this.setState({active: false})}
/>

@lavarajallu
Copy link
Author

yes thank u ,but i solved my issue

@tioback
Copy link

tioback commented Jan 24, 2017

@lavarajallu, please post the solution and/or close ticket :-)

@lavarajallu
Copy link
Author

First Install this:
npm install --save react-native-switch

in Your Js file
import { Switch } from 'react-native-switch';

<Switch
value={true}
onValueChange={(val) => console.log(val)}
disabled={false}
activeText={'On'}
inActiveText={'Off'}
backgroundActive={'green'}
backgroundInactive={'gray'}
circleActiveColor={'#30a566'}
circleInActiveColor={'#000000'}/>

@Moniovic
Copy link

did not worked for me. It get stuck when after first toggle

@indventures
Copy link

indventures commented Jul 3, 2019

@Monivic
value is set always true here.You have to do like this

state = { switchValue: false };
toggleSwitch = () => {
this.setState({ switchValue: !this.state.switchValue });
};

and inside render

      <Switch
        value={this.state.switchValue}
        onValueChange={this.toggleSwitch}
        disabled={false}
        activeText={'On'}
        inActiveText={'Off'}
        backgroundActive={'green'}
        backgroundInactive={'gray'}
        circleActiveColor={'#30a566'}
        circleInActiveColor={'#000000'}
      />

@zakariamosa
Copy link

const [automaticdischarge, setAutomaticDischarge] = useState(true);
toggleSwitch = () => {
setAutomaticDischarge(!automaticdischarge);
};

<Switch
value={automaticdischarge}
onValueChange={(value)=>{
toggleSwitch();
console.log(value);
}}
disabled={false}
activeText={'Yes'}
inActiveText={'No'}
backgroundActive={'green'}
backgroundInactive={'gray'}
circleActiveColor={'#30a566'}
circleInActiveColor={'#000000'}
/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants