Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch & SwitchAndroid doesn't work in Android

Tags:

react-native

var React = require('react-native');
var {
  Switch,
  Text,
  View
} = React;

var BasicSwitchExample = React.createClass({
  getInitialState() {
    return {
      trueSwitchIsOn: true,
      falseSwitchIsOn: false,
    };
  },
  render() {
    return (
      <View>
        <Switch
          onValueChange={(value) => this.setState({falseSwitchIsOn: value})}
          style={{marginBottom: 10}}
          value={this.state.falseSwitchIsOn} />
        <Switch
          onValueChange={(value) => this.setState({trueSwitchIsOn: value})}
          value={this.state.trueSwitchIsOn} />
      </View>
    );
  }
});

BasicSwitchExample doesn't work in Android.

error screenshot:

compile ('com.facebook.react:react-native:0.20.1'){
 exclude group: 'com.nineoldandroids', module: 'library' }
like image 529
Perry.du Avatar asked May 17 '26 23:05

Perry.du


1 Answers

I know that this is pretty old, but if anyone ends up here...

I had the exact same problem, after little bit of digging into source I found out that it was caused by android theme i was using.

So the solution for me was to switch android theme in andorid/app/src/main/res/styles.xml from android:Theme.Material.Light.NoActionBar to Theme.AppCompat.Light.NoActionBar

like image 87
Jakub Martyčák Avatar answered May 21 '26 16:05

Jakub Martyčák