ayand04

Screen 1

Nov 21st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component }  from 'react';
  2. import {
  3.     View,
  4.     FlatList,
  5.     Alert,
  6.     Animated
  7. } from 'react-native';
  8. import {
  9.     ThemeProvider,
  10.     Toolbar,
  11.     ListItem,
  12. } from 'react-native-material-ui';
  13. import { Button } from 'react-native-elements';
  14. import CustomStatusBar from '../statusBar/statusBar';
  15. import ProfilePic from './profilePicture';
  16. import CenterComponent from './centerElement';
  17. import uiTheme from '../../themes/defaultTheme';
  18. import styles from './styles';
  19.  
  20. export default class recentChatListScreen extends Component
  21. {
  22.     /*
  23.     state = {
  24.         scrollY: new Animated.Value(0)
  25.     };*/
  26.  
  27.     constructor(props) {
  28.         super(props);
  29.         this.elevation = new Animated.Value(0);
  30.         this.state = {
  31.             scrollY: new Animated.Value(0)
  32.         };
  33.     }
  34.  
  35.     changeElevation = () => {
  36.         let elevation = 7;
  37.         if (this.state.scrollY === 0) elevation = 0;
  38.         Animated
  39.             .timing(this.elevation, {
  40.                 toValue: elevation,
  41.                 duration: 200 //could be 200
  42.             })
  43.             .start();
  44.     };
  45.  
  46.     _renderItem = ({item}) => (
  47.         <ListItem
  48.             divider={true}
  49.             numberOfLines={2}
  50.             onPress={() => Alert.alert('Single Tap')}
  51.             onLongPress={() => Alert.alert('Long Tap')}
  52.             leftElement={
  53.                 <ProfilePic image={item.avatar} theme={uiTheme}/>
  54.             }
  55.             centerElement={
  56.                 <CenterComponent
  57.                     primaryText={item.chatWith}
  58.                     secondaryText={item.lastMessage}
  59.                     timestamp={item.lastMessageTime}
  60.                     unreadCount={item.unreadMessages}
  61.                     theme={uiTheme}
  62.                 />
  63.             }
  64.         />
  65.     );
  66.  
  67.     render() {
  68.         /*
  69.         const elevate = this.state.scrollY.interpolate({
  70.             inputRange: [0, 1],
  71.             outputRange: [0, 7],
  72.             extrapolate: 'clamp'
  73.         });*/
  74.  
  75.         //console.log(elevate);
  76.  
  77.         this.changeElevation();
  78.  
  79.         return (
  80.             <ThemeProvider uiTheme={uiTheme}>
  81.                 <View style={styles.contentWrapper}>
  82.                     <CustomStatusBar themeColor={uiTheme.palette.primaryColor} elevation={0}/>
  83.                     <View>
  84.                         <Toolbar
  85.                             leftElement="menu"
  86.                             centerElement="Aloha"
  87.                             searchable={{
  88.                                 autoFocus: true,
  89.                                 placeholder: 'Search your chats',
  90.                             }}
  91.                             onLeftElementPress={() => this.props.navigation.navigate('DrawerOpen')}
  92.                             style={{container: {elevation: this.elevation}}}
  93.                         />
  94.                     </View>
  95.                     <View style={styles.chatListContainer}>
  96.                         <FlatList
  97.                             data={[
  98.                                 {
  99.                                     userId: 1,
  100.                                     messageId: 'a',
  101.                                     avatar: '',
  102.                                     chatWith: 'Jane Doe',
  103.                                     lastMessage: 'This line here will show the last message and takes up the whole line',
  104.                                     lastMessageTime: 1509693517,
  105.                                     unreadMessages: 0
  106.                                 },
  107.                                 {
  108.                                     userId: 2,
  109.                                     messageId: 'b',
  110.                                     avatar: 'https://pbs.twimg.com/profile_images/718588760003383296/2AG8omMO_400x400.jpg',
  111.                                     chatWith: 'John Doe',
  112.                                     lastMessage: 'This line here will show the last loooooong message',
  113.                                     lastMessageTime: 1509520707,
  114.                                     unreadMessages: 100
  115.                                 },
  116.                                 {
  117.                                     userId: 3,
  118.                                     messageId: 'c',
  119.                                     avatar: 'https://pbs.twimg.com/profile_images/907811115459125248/i8AzK6gR_400x400.jpg',
  120.                                     chatWith: 'John Doe',
  121.                                     lastMessage: 'This line here will show the last message',
  122.                                     lastMessageTime: 1510134380,
  123.                                     unreadMessages: 1
  124.                                 },
  125.                                 {
  126.                                     userId: 4,
  127.                                     messageId: 'c',
  128.                                     avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/kfriedson/128.jpg',
  129.                                     chatWith: 'John Doe',
  130.                                     lastMessage: 'This line here will show the last message to show it extends and forms ellipsis',
  131.                                     lastMessageTime: 1510246390,
  132.                                     unreadMessages: 0
  133.                                 },
  134.                                 {
  135.                                     userId: 5,
  136.                                     messageId: 'd',
  137.                                     avatar: '',
  138.                                     chatWith: 'John Doe',
  139.                                     lastMessage: 'This line here will show the last message',
  140.                                     lastMessageTime: 1510134380,
  141.                                     unreadMessages: 55
  142.                                 },
  143.                                 {
  144.                                     userId: 6,
  145.                                     messageId: 'e',
  146.                                     avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/brynn/128.jpg',
  147.                                     chatWith: 'John Doe',
  148.                                     lastMessage: 'This line here will show the last message',
  149.                                     lastMessageTime: 1510134380,
  150.                                     unreadMessages: 1
  151.                                 },
  152.                                 {
  153.                                     userId: 7,
  154.                                     messageId: 'f',
  155.                                     avatar: '',
  156.                                     chatWith: 'John Doe',
  157.                                     lastMessage: 'This line here will show the last message',
  158.                                     lastMessageTime: 1510134380,
  159.                                     unreadMessages: 0
  160.                                 },
  161.                                 {
  162.                                     userId: 8,
  163.                                     messageId: 'g',
  164.                                     avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/ladylexy/128.jpg',
  165.                                     chatWith: 'John Doe',
  166.                                     lastMessage: 'This line here will show the last message',
  167.                                     lastMessageTime: 1510134380,
  168.                                     unreadMessages: 1
  169.                                 },
  170.                                 {
  171.                                     userId: 9,
  172.                                     messageId: 'h',
  173.                                     avatar: 'https://s3.amazonaws.com/uifaces/faces/twitter/adhamdannaway/128.jpg',
  174.                                     chatWith: 'John Doe',
  175.                                     lastMessage: 'This line here will show the last message',
  176.                                     lastMessageTime: 1510134380,
  177.                                     unreadMessages: 1
  178.                                 }
  179.                             ]}
  180.                             renderItem={this._renderItem}
  181.                             keyExtractor={item => item.userId}
  182.                             scrollEventThrottle={16}
  183.                             onScroll={Animated.event(
  184.                                 [{nativeEvent: {contentOffset: {y: this.state.scrollY}}}]
  185.                             )}
  186.                         />
  187.                         <Button
  188.                             icon={{name:"chat", size: 26}}
  189.                             title="START CHAT"
  190.                             raised
  191.                             borderRadius={50}
  192.                             containerViewStyle={uiTheme.button.container}
  193.                             buttonStyle={uiTheme.button.buttonStyle}
  194.                             fontWeight="500"
  195.                         />
  196.                     </View>
  197.                 </View>
  198.             </ThemeProvider>
  199.         );
  200.     }
  201. }
Add Comment
Please, Sign In to add comment