ayand04

new2

Dec 8th, 2017
67
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. } from 'react-native';
  7. import {
  8.     ThemeProvider,
  9.     Toolbar,
  10.     ListItem
  11. } from 'react-native-material-ui';
  12. import getPlatformElevation from 'react-native-material-ui/src/styles/getPlatformElevation';
  13.  
  14. export default class recentChatListScreen extends Component
  15. {
  16.     constructor(props) {
  17.         super(props);
  18.         this.state = { elevation: 0 };
  19.     }
  20.  
  21.     onScroll = (e) => {
  22.         const { contentOffset } = e.nativeEvent;
  23.  
  24.         if (contentOffset.y <= 0) {
  25.             this.setState({ elevation: 0 });
  26.         } else if (contentOffset.y < 7) {
  27.             this.setState({ elevation: Math.round(contentOffset.y) });
  28.         } else {
  29.             this.setState({ elevation: 7 });
  30.         }
  31.     };
  32.  
  33.     _renderItem = ({item}) => (
  34.         <ListItem
  35.             divider={true}
  36.             centerElement={item.lastMessage}
  37.         />
  38.     );
  39.  
  40.     render() {
  41.         return (
  42.             <ThemeProvider uiTheme={uiTheme}>
  43.                 <View style={{flex:1}}>
  44.                     <Toolbar
  45.                         leftElement="menu"
  46.                         centerElement="Aloha"
  47.                         searchable={{
  48.                             autoFocus: true,
  49.                             placeholder: 'Search your chats',
  50.                         }}
  51.                         onLeftElementPress={() => Alert.alert('Menu Icon pressed')}
  52.                         style={{container: getPlatformElevation(this.state.elevation)}}
  53.                     />
  54.  
  55.                     <View style={{flex:1, flexDirection: 'column'}}>
  56.                         <FlatList
  57.                             data={[
  58.                                 {  
  59.                                     userId: 1,    
  60.                                     lastMessage: 'This line here will show the last message and takes up the whole line'
  61.                                 },
  62.                                 {  
  63.                                     userId: 2,                                
  64.                                     lastMessage: 'This line here will show the last loooooong message'            
  65.                                 },
  66.                                 {  
  67.                                     userId: 3,    
  68.                                     lastMessage: 'This line here will show the last message and takes up the whole line'
  69.                                 },
  70.                                 {  
  71.                                     userId: 4,                                
  72.                                     lastMessage: 'This line here will show the last loooooong message'            
  73.                                 },
  74.                                 {  
  75.                                     userId: 5,    
  76.                                     lastMessage: 'This line here will show the last message and takes up the whole line'
  77.                                 },
  78.                                 {  
  79.                                     userId: 6,                                
  80.                                     lastMessage: 'This line here will show the last loooooong message'            
  81.                                 },
  82.                                 {  
  83.                                     userId: 7,    
  84.                                     lastMessage: 'This line here will show the last message and takes up the whole line'
  85.                                 },
  86.                                 {  
  87.                                     userId: 8,                                
  88.                                     lastMessage: 'This line here will show the last loooooong message'            
  89.                                 },
  90.                                 {  
  91.                                     userId: 9,    
  92.                                     lastMessage: 'This line here will show the last message and takes up the whole line'
  93.                                 },
  94.                                 {  
  95.                                     userId: 10,                                
  96.                                     lastMessage: 'This line here will show the last loooooong message'            
  97.                                 },
  98.                             ]}
  99.                             renderItem={this._renderItem}
  100.                             keyExtractor={item => item.userId}
  101.                             onScroll={this.onScroll}
  102.                         />                      
  103.                     </View>
  104.                 </View>
  105.             </ThemeProvider>
  106.         );
  107.     }
  108. }
Add Comment
Please, Sign In to add comment