Guest User

Untitled

a guest
Jan 20th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. class ButtonOption extends Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = {
  5. data : [],
  6. active : 0
  7. };
  8. }
  9.  
  10. loadButton(temp){
  11. let result = [];
  12. for (let i =0;i<temp.length;i++){
  13. if(i==this.state.active){
  14. result.push(
  15. <View key={i} style={buttonOption.main}>
  16. <TouchableOpacity style={buttonOption.tabActive} onPress={()=>{this.setState({active:i});alert(this.state.active)}}>
  17. <Text style={buttonOption.labelActive}>{temp[i]}</Text>
  18. </TouchableOpacity>
  19. </View>)
  20. }else{
  21. result.push(
  22. <View key={i} style={buttonOption.main}>
  23. <TouchableOpacity style={buttonOption.tab} onPress={()=>{this.setState({active:i});alert(this.state.active)}}>
  24. <Text style={buttonOption.label}>{temp[i]}</Text>
  25. </TouchableOpacity>
  26. </View>)
  27. }
  28. }
  29. return result;
  30. }
  31.  
  32. componentDidMount(){
  33. this.setState({data:this.loadButton(this.props.arrButton)})
  34. }
  35.  
  36. render() {
  37. return (
  38. <View style={{flexDirection:'row',padding:10}}>
  39. {this.state.data}
  40. </View>
  41. );
  42. }
  43. }
  44. export default ButtonOption;
Add Comment
Please, Sign In to add comment