Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { StyleSheet, Text, View,Button,FlatList,Alert,ScrollView } from 'react-native';
  2. import { ListItem,Overlay} from 'react-native-elements';
  3. import React from 'react';
  4. import api from '../../config/api';
  5. import server from '../../config/server';
  6. import * as SecureStore from 'expo-secure-store';
  7. import Modal from "react-native-modal";
  8. import axios from 'axios';
  9. class UsersList extends  React.Component {
  10.     constructor(props){
  11.         super(props);
  12.         this.state = {
  13.           users: [],
  14.           error: '',
  15.           isVisible: false,
  16.           refershing: false,
  17.           loading: false
  18.         };
  19.         this._onUserPress = this._onUserPress.bind(this);
  20.       }
  21.     async componentDidMount() {
  22.         const accessToken = await SecureStore.getItemAsync('accessToken');
  23.         if(accessToken) {
  24.           axios.get(`${api.user.list}?access-token=${accessToken}`, {
  25.             params: {
  26.               'access-token': accessToken
  27.             }
  28.           })
  29.         .then((response) => {
  30.           const {users} = response.data;
  31.  
  32.           this.setState({ error: '', loading: false,users:users});
  33.         })
  34.         .catch((error) => {
  35.             Alert.alert('Ошибка получения данных');
  36.         });
  37.         }else {
  38.           this.props.navigation.navigate('Login');
  39.         }
  40.     }
  41.     _onUserPress() {
  42.         this.setState({
  43.             isVisible:true
  44.         });
  45.     }
  46.     keyExtractor = (item, index) => item.Id
  47.  
  48.     renderItem = ({ item }) => (
  49.     <ListItem
  50.         title={item.ShortName}
  51.         onPress={this._onUserPress}
  52.         subtitle={item.position}
  53.         leftAvatar={{ source:{ uri: `${server.prefix}${server.host}/${item.photo_card}` }}}
  54.     />
  55.     )
  56.     toggleModal = () => {
  57.         this.setState({ isVisible: !this.state.isVisible });
  58.       };
  59.     render () {
  60.         const {users} = this.state;
  61.  
  62.        return (
  63.            <View>
  64.                          <Modal isVisible={this.state.isVisible}>
  65.             <View style={{ flex: 1 }}>
  66.             <Button title="Hide modal" onPress={this.toggleModal} />
  67.                 <Text>I am the modal content!</Text>
  68.             </View>
  69.         </Modal>
  70.            <ScrollView>
  71.                
  72.                 <FlatList
  73.                                 keyExtractor={this.keyExtractor}
  74.                                
  75.                                 data={users}
  76.                                 renderItem={this.renderItem}
  77.                     />
  78.                </ScrollView>
  79.                </View>
  80.  
  81.        
  82.  
  83.        )
  84.     }
  85. }
  86. const styles = StyleSheet.create({
  87.     item: {
  88.       color: '#000000'
  89.     },
  90.   });
  91. export default UsersList;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement