Answer the question
In order to leave comments, you need to log in
How to use SwitchIOS in a loop in React Native?
Hello! I am making a mobile application using React Native 0.30.
There is a Report component that receives data through props.
export default class Report extends Component {
constructor(props) {
super(props);
this.state = {
questions : [],
progress : 0,
activeSlide : 0
}
}
setActiveSlide(i, inc) {
let max = this.props.check.questions.length;
let curr = inc ? i+1 : i-1;
let progress = curr / max;
this.setState({
activeSlide : curr,
progress : progress
})
}
renderSlide(slide, i) {
if(this.state.activeSlide == i)
return(
<View>
<Text>{slide.position} / {this.props.check.questions.length}. {slide.title}</Text>
<SwitchIOS
onValueChange={(value) => this.setCheck(value, i)}
value={/*anything*/}
/>
<View>
<TouchableHighlight onPress={() => this.setActiveSlide(i)}>
<Text>Назад</Text>
</TouchableHighlight>
<TouchableHighlight onPress={() => this.setActiveSlide(i, true)}>
<Text>Далее</Text>
</TouchableHighlight>
</View>
</View>
)
}
setCheck(val, i) {
this.state.questions.push({index : 1, check : val});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question