Created
February 28, 2018 18:56
-
-
Save Evshved/2f91a56051c77b4299795d0955f37b1e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| import { View, Text, TouchableOpacity } from 'react-native'; | |
| import styles from './schedule.styles'; | |
| export default class Schedule extends Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { | |
| schedule: [], | |
| }; | |
| } | |
| componentDidMount() { | |
| const schedule = Array.from(Array(10)).map((item, index) => { | |
| return { | |
| id: index + 100, | |
| title: '15:00 - 16:00', | |
| active: false, | |
| }; | |
| }); | |
| schedule[0].active = true; | |
| } | |
| activeChange = (id, row) => { | |
| const newRow = row.map((item) => { | |
| if (item.active) { | |
| const newItem = { ...item }; | |
| newItem.active = (item.id === id); | |
| return newItem; | |
| } | |
| if (item.id === id) { | |
| const newItem = { ...item }; | |
| newItem.active = true; | |
| return newItem; | |
| } | |
| return item; | |
| }); | |
| return newRow; | |
| } | |
| activeChangeSchedule = (id) => { | |
| const schedule = this.activeChange(id, this.state.schedule); | |
| this.setState({ schedule }); | |
| } | |
| render() { | |
| const list = this.state.schedule.map((item) => { | |
| <TouchableOpacity style={styles.buttonActive} | |
| onPress={this.activeChangeQuantity} | |
| id={item.id} | |
| active={item.active} > | |
| <Text style={styles.textActive}> {item.title} </Text> | |
| </TouchableOpacity> | |
| }) | |
| const same_text = { | |
| <Text> {index} </Text> | |
| <Text> {index} </Text> | |
| <Text> {index} </Text> | |
| }) | |
| return ( | |
| <View style={styles.container}> | |
| {same_text} | |
| </View> | |
| ); | |
| } | |
| } | |
| Schedule.defaultProps = { | |
| time: '15:00 - 16:00', | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment