Advertisement
Guest User

Untitled

a guest
May 25th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react';
  2. import {
  3.   Text,
  4.   View,
  5.   Button,
  6.   StyleSheet,
  7.   SectionList
  8. } from 'react-native';
  9. import {RkChoice,RkTheme} from 'react-native-ui-kitten';
  10.  
  11.   RkTheme.setType('RkChoice', 'radioGreen', {
  12.     backgroundColor: '#25D366',
  13.     marginBottom:10,
  14.     inner: {
  15.       tintColor:'#1e212b',      
  16.       width:10,
  17.       height:10
  18.     },
  19.   });
  20.  
  21.  
  22. class DetailsScreen extends React.Component {
  23.     constructor(props) {
  24.       super(props);
  25.       const { navigation } = props      
  26.       this.state = {
  27.         test: 'Hola1',
  28.         gym: navigation.getParam('itemId', 'NO-ID'),
  29.         schedule: navigation.getParam('itemId', 'NO-ID').schedule
  30.       };
  31.     }
  32.  
  33.     _setHola = (text) => {
  34.       this.setState({test: text})
  35.     }
  36.  
  37.     _setCategories = (schedule) => {
  38.       const cats = []
  39.       schedule.map((sch) => {
  40.         sch.data.map((cat) =>{
  41.           cats.push(cat.name)
  42.         })
  43.       })
  44.        return uniqueArray = cats.filter(function(item, pos) {
  45.            return cats.indexOf(item) == pos;
  46.       })
  47.     }
  48.  
  49.     _filterCategories = (category) => {
  50.       if(category == 'all'){
  51.         this.setState({
  52.           schedule: this.state.gym.schedule
  53.         })
  54.       }
  55.       else{
  56.         let filtered = this.state.gym.schedule.map((item) => {
  57.           console.log(this.state.gym.schedule)
  58.           item.data = item.data.filter(act => act.name == category)
  59.           if (item.data.length > 0 ) return item
  60.         })
  61.         this.setState({
  62.           schedule: filtered
  63.         })
  64.       }
  65.     }
  66.  
  67.    
  68.     render() {
  69.       return (
  70.         <View>
  71.           <View style={styles.header}>
  72.             <Text> {this.state.test} </Text>
  73.             <Text style={styles.headerText} >Horarios Sucursal {this.state.gym.name}</Text>
  74.           </View>
  75.           {
  76.             this._setCategories(this.state.gym.schedule).map((cat) => {
  77.               return(
  78.                 <Button
  79.                 key={cat}
  80.                 onPress={() => this._filterCategories(cat)}
  81.                 color="#841584"
  82.                 title={cat}
  83.                 />
  84.  
  85.               )
  86.             })
  87.           }
  88.           <Button
  89.             key='all'
  90.             onPress={() => this._filterCategories('all')}
  91.             color="#841584"
  92.             title='todos'
  93.           />
  94.           <View>
  95.             <SectionList
  96.             sections={this.state.schedule}
  97.             renderSectionHeader={ ({section}) => <Text style={styles.dayText}>{section.title} </Text>}
  98.             renderItem={({item}) => <View><Text style={styles.activityText}> {item.name} </Text> <Text style={styles.hourText}> {item.start} - {item.end}</Text> <View
  99.             style={{
  100.               borderBottomColor: 'gray',
  101.               borderBottomWidth: 0.5,
  102.               opacity: 0.5
  103.             }}
  104.           /> </View>}
  105.             keyExtractor={(item, index) => index}
  106.             />
  107.           <Button
  108.             title="Volver"
  109.             onPress={() => this.props.navigation.goBack()}
  110.           />
  111.           </View>
  112.         </View>
  113.       );
  114.     }
  115.   }
  116.  
  117.   const styles = StyleSheet.create({
  118.     baseText: {
  119.       fontFamily: 'KohinoorBangla-Regular',
  120.     },
  121.     header: {
  122.       backgroundColor: '#25D366',
  123.       width:'100%',
  124.       height:'25%',
  125.       marginBottom: 25,
  126.       alignItems: 'stretch',
  127.       justifyContent: 'center'
  128.     },
  129.     headerText:{
  130.       color: 'white',
  131.       fontSize: 20,
  132.       fontWeight: 'bold',
  133.       textAlign: 'center',
  134.       fontFamily: 'KohinoorBangla-Regular'      
  135.     },
  136.     dayText:{
  137.       backgroundColor: '#25D366',      
  138.       color: 'black',
  139.       fontSize: 15,
  140.       fontFamily: 'KohinoorBangla-Regular'      
  141.     },
  142.     activityText:{
  143.       backgroundColor: 'white',            
  144.       color: 'black',
  145.       fontSize: 15,
  146.       fontWeight: 'bold',
  147.       fontFamily: 'KohinoorBangla-Regular'      
  148.     },
  149.     hourText:{
  150.       backgroundColor: 'white',            
  151.       color: 'grey',
  152.       fontSize: 12,
  153.       fontFamily: 'KohinoorBangla-Regular'      
  154.     }
  155.  
  156.   });
  157.   export default DetailsScreen;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement