Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import {
  3.     StyleSheet,
  4.     View,
  5.     FlatList,
  6.     Text,
  7.     Platform,
  8.     Alert,
  9.     } from 'react-native';  
  10. import { Container,Header,Left,Right,Icon, Title, Body } from 'native-base';
  11. import GlobalStyle from '../component/style/GlobalStyle';
  12. import ScheduleListRow from '../component/ScheduleListRow';
  13. import Button from '../component/common/Button';
  14.  
  15.     class ScheduleScreen extends Component{
  16.         constructor(props) {
  17.             super(props);
  18.             this.state = {
  19.                 scheduleData : [
  20.                     {
  21.                         dateTrans : 'April 22, 2019',
  22.                         scheduleContent : [
  23.                             {
  24.                                 name : 'Andika',
  25.                                 description : 'Meeting 16:30',
  26.                             },
  27.                             {
  28.                                 name : 'BI Team',
  29.                                 description : 'Meeting 19:30',
  30.                             },
  31.                         ]
  32.                     },
  33.                 ]
  34.  
  35.                 // scheduleData : [
  36.                 //     {
  37.                 //         name : 'Andika',
  38.                 //         description : 'Meeting 16:30',
  39.                 //     },
  40.                 //     {
  41.                 //         name : 'BI Team',
  42.                 //         description : 'Meeting 19:30',
  43.                 //     },
  44.                 // ]
  45.             };
  46.         }
  47.         componentDidMount () {
  48.         test()
  49.         }
  50.         test = () => {
  51.         let data = this.state.scheduleData
  52.         let result = data[0].scheduleContent
  53.         console.log(result)
  54.         // baru jadikan state dan ambil namanya saja
  55.         }
  56.  
  57.         _keyApprovalExtractor = (item, index) => item.scheduleContent.name;
  58.         _renderItem = ({item, scheduleContent}) => (
  59.             <ScheduleListRow
  60.               xDateTrans={item.dateTrans}
  61.               xName={item.scheduleContent.name}
  62.               xDescription={item.scheduleContent.description}
  63.               onPressItem={this._onPressItem}
  64.             />
  65.           );
  66.        
  67.           _onPressItem = (name) => {
  68.             Alert.alert(name);
  69.         };
  70.  
  71.         render(){
  72.             return(
  73.                 <Container>
  74.                     <Header style={{ backgroundColor: 'white' }}>
  75.                     <Left style={{ flexDirection: 'row'}}>
  76.                             <Icon onPress={() => this.props.navigation.openDrawer()} name="md-menu" style={{ color: 'black', marginRight: 15 }} />
  77.                         </Left>
  78.                         <Body>
  79.                             <Title style={{color:'black'}}>Schedule</Title>
  80.                         </Body>
  81.                         <Right>
  82.                             <Icon name="ios-arrow-down" style={{ color: 'black'}} />
  83.                         </Right>
  84.                     </Header>
  85.                     <View style={styles.container}>
  86.                      <FlatList
  87.                             style={GlobalStyle.listContainer}
  88.                             data={this.state.scheduleData}
  89.                             renderItem={this._renderItem}
  90.                             keyExtractor={this._keyApprovalExtractor}  
  91.                         />
  92.                         <View style={styles.bottomContainer}>
  93.                             <Button>NEW SCHEDULE</Button>
  94.                         </View>
  95.                  </View>
  96.                 </Container>
  97.             );
  98.         }
  99.     }
  100.    
  101.     const styles = StyleSheet.create({
  102.         container : {
  103.             flex: 1,
  104.             flexDirection : 'column',
  105.             backgroundColor:'#FFFFFF',
  106.         },
  107.         dateText : {
  108.             marginTop : Platform.OS === 'ios' ? 8 : 0,
  109.             padding : 5,
  110.             fontSize:14,
  111.             color:'#000000'
  112.         },
  113.         bottomContainer : {
  114.             justifyContent : "flex-end",
  115.             alignItems : "center",
  116.             marginBottom : 10
  117.         }
  118.     });
  119.    
  120.  
  121.     export default ScheduleScreen;
  122.  
  123.  
  124. ===================================================
  125.  
  126. import React, { Component } from 'react';
  127. import { View, Text, StyleSheet, Image, TouchableOpacity } from 'react-native';
  128. import Card from './common/Card';
  129. import CardSection from './common/CardSection';
  130.  
  131.  
  132. class ScheduleListRow extends Component{
  133.     _onPress = () => {
  134.         this.props.onPressItem(this.props.xName);
  135.       };
  136.    
  137.       _dateTrans = () => {
  138.             if(this.props.xDateTrans !== null){
  139.                 return(
  140.                     <Text style={styles.titleText}>{this.props.xDateTrans}</Text>
  141.                 );
  142.             }
  143.       };
  144.  
  145.     render(){
  146.         return(
  147.             <TouchableOpacity onPress={this._onPress}
  148.             style={styles.container}>
  149.                <Text style={styles.titleText}>{this.props.xDateTrans}</Text>
  150.                 <Card>
  151.                 <CardSection>
  152.                     <View style={styles.subContainer}>
  153.                         <Image  style={styles.photo}
  154.                                     source={require('../images/ic_main_user.png')}/>    
  155.                         <View style={styles.subContainer2}>
  156.                             <Text style={styles.titleText}>{this.props.xName}</Text>
  157.                             <Text style={styles.text}>{this.props.xDescription}</Text>
  158.                         </View>
  159.                     </View>
  160.                 </CardSection>
  161.             </Card>
  162.         </TouchableOpacity>
  163.         );
  164.     }
  165. }
  166.  
  167. const styles = StyleSheet.create({
  168.     container: {
  169.         flexDirection: 'column',
  170.         flex : 1
  171.     },
  172.     subContainer : {
  173.         flex : 1,
  174.         flexDirection : 'row',
  175.     },
  176.     subContainer2 : {
  177.         flex : 1,
  178.         flexDirection : 'column',
  179.         justifyContent : 'flex-start',
  180.         alignItems: 'flex-start',
  181.         marginBottom: 5,
  182.     },
  183.     titleText: {
  184.         marginLeft: 20,
  185.         marginTop: 2,
  186.         fontSize:18,
  187.         fontWeight : 'bold',
  188.         color:'#000000',
  189.       },
  190.     text: {
  191.       marginLeft: 20,
  192.       marginTop: 2,
  193.       fontSize:15,
  194.       marginBottom : 5,
  195.       color:'#000000',
  196.     },
  197.     photo: {
  198.         marginLeft : 5,
  199.         marginTop : 8,
  200.         width:40,
  201.         height: 40,
  202.     },
  203.   });
  204.  
  205. export default ScheduleListRow;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement