Guest User

Untitled

a guest
Mar 18th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import { StyleSheet, View, Text, Button, Image, TextInput, Dimensions, ScrollView, FlatList, SafeAreaView, Alert } from 'react-native';
  3. import { Dropdown } from 'react-native-material-dropdown';
  4.  
  5. let periods = [
  6.     {
  7.         value: 'everyday',
  8.         label: 'Каждый день'
  9.     },
  10.     {
  11.         value: 'twodays',
  12.         label: 'Каждые два дня'
  13.     },
  14.     {
  15.         value: 'threedays',
  16.         label: 'Каждые три дня'
  17.     },
  18.     {
  19.         value: 'nomatter',
  20.         label: 'Не имеет значения'
  21.     }]
  22.  
  23. let usageTime = [
  24.     {
  25.         id: '1',
  26.         hours: '11',
  27.         minutes: '00'
  28.     },
  29.     {
  30.         id: '2',
  31.         hours: '13',
  32.         minutes: '00'
  33.     },
  34.     {
  35.         id: '3',
  36.         hours: '15',
  37.         minutes: '00'
  38.     },
  39.     {
  40.         id: '4',
  41.         hours: '17',
  42.         minutes: '00'
  43.     },
  44.     {
  45.         id: '5',
  46.         hours: '19',
  47.         minutes: '00'
  48.     },
  49.     {
  50.         id: '6',
  51.         hours: '21',
  52.         minutes: '00'
  53.     },
  54.     {
  55.         id: '7',
  56.         hours: '23',
  57.         minutes: '00'
  58.     },
  59.     {
  60.         id: '8',
  61.         hours: '01',
  62.         minutes: '00'
  63.     },
  64. ]
  65.  
  66. let types = [
  67.     {
  68.         value: 'tablet',
  69.         label: 'Таблетки'
  70.     },
  71.     {
  72.         value: 'drops',
  73.         label: 'Сиропы'
  74.     },
  75.     {
  76.         value: 'other',
  77.         label: 'Другое'
  78.     }
  79. ]
  80.  
  81. /**
  82.  * Profile screen
  83.  */
  84. export default class Profile extends React.Component {
  85.  
  86.     constructor(props) {
  87.         super(props);
  88.         this.createUsageTime = this.createUsageTime.bind(this);
  89.         this.state = {
  90.             usageTime
  91.         }
  92.     }
  93.  
  94.     createUsageTime({ title, id }) {
  95.         return (
  96.             <View>
  97.                 <Text
  98.                     style={styles.usageTimeItem}
  99.                     onPress={() => {
  100.                         Alert.alert(id)
  101.                         for (let i = 0; i < usageTime.length; i++) {
  102.                             if (usageTime[i].id == id) {
  103.                                 usageTime.splice(i, 1);
  104.                             }
  105.                         }
  106.                     }}    
  107.                 >{title}
  108.                 </Text>
  109.             </View>
  110.         )
  111.     }
  112.  
  113.     static navigationOptions = ({ navigation }) => {
  114.         return {
  115.             title: navigation.getParam('title'),
  116.         };
  117.     };
  118.  
  119.     render() {
  120.  
  121.         const { navigate, state } = this.props.navigation;
  122.         // width = Dimensions.get('window').width;
  123.         // height = Dimensions.get('window').height;
  124.  
  125.         return (
  126.  
  127.             <ScrollView style={styles.container}>
  128.  
  129.                 <View style={styles.form}>
  130.  
  131.                     {/* Название препарата */}
  132.                     <View style={styles.input}>
  133.                         <Image style={{width: 30, height: 30, marginRight: 10,}} source={{uri: 'https://img.icons8.com/material/4ac144/256/user-male.png'}} />
  134.                         <TextInput style={styles.inputText}>Введите название препарата</TextInput>
  135.                     </View>
  136.  
  137.                     {/* Периодичность приема */}
  138.                     <Dropdown
  139.                         label="Периодичность приема"
  140.                         data={periods}
  141.                         value='everyday'
  142.                         containerStyle={styles.dropdown}
  143.                     />
  144.  
  145.                     {/* Время приема */}
  146.                     <View style={styles.usageTimeMainContainer}>
  147.                         {/* Добавить время */}
  148.                         <View style={styles.usageTimeInputContainer}>
  149.                             <Text style={styles.inputText}>Время приема</Text>
  150.                             <Button
  151.                                 title="Добавить"
  152.                                 onPress={() => navigate('Home')} // ДОБАВИТЬ ФУНКЦИЮ
  153.                             />
  154.                         </View>
  155.                         {/* Список таймкодов */}
  156.                         <SafeAreaView style={{flex: 1}}>
  157.                             <FlatList
  158.                                 data={usageTime}
  159.                                 renderItem={({ item }) => <this.createUsageTime
  160.                                     title={`${item.hours}:${item.minutes}`}
  161.                                     id={item.id}
  162.                                 />}
  163.                                 keyExtractor={item => item.id}
  164.                                 horizontal={true}
  165.                                 style={{paddingHorizontal: 20}}
  166.                             />
  167.                         </SafeAreaView>
  168.                     </View>
  169.  
  170.                     <View style={{flex: 1, flexDirection: 'row', justifyContent: 'space-between', alignItems: 'flex-end',marginHorizontal: 20, marginVertical: 20}}>
  171.                         <Dropdown
  172.                             data={types}
  173.                             label="Тип препарата"
  174.                             value='tablet'
  175.                             containerStyle={{width: '50%', height: 50, flex: 1, justifyContent: 'center'}}
  176.                         />
  177.                         <TextInput style={styles.doseTextInput}>Дозировка</TextInput>
  178.                     </View>
  179.  
  180.                 </View>
  181.  
  182.                 {/* Кнопка сохранения данной заметки */}
  183.                 <Button
  184.                     title="Добавить"
  185.                     onPress={() => Alert.alert('Успешно', 'Добавлено')} // НУЖНО ДОБАВИТЬ ФУНКЦИЮ НА КНОПКУ
  186.                 />
  187.  
  188.             </ScrollView>
  189.         );
  190.  
  191.     }
  192.  
  193. }
  194.  
  195. const styles = StyleSheet.create({
  196.     container: {
  197.         backgroundColor: '#fff'
  198.     },
  199.     form: {
  200.  
  201.     },
  202.     input: {
  203.         flexDirection: 'row',
  204.         alignItems: 'center',
  205.         paddingHorizontal: 20,
  206.         paddingVertical: 20,
  207.         borderBottomWidth: 1,
  208.         borderBottomColor: '#E2E2E2',
  209.         width: Dimensions.get('window').width,
  210.     },
  211.  
  212.     usageTimeMainContainer: {
  213.         flexWrap: 'wrap',
  214.         borderBottomWidth: 1,
  215.         borderBottomColor: '#E2E2E2',
  216.     },
  217.     usageTimeInputContainer: {
  218.         flexDirection: 'row',
  219.         paddingHorizontal: 20,
  220.         paddingVertical: 20,
  221.         alignItems: 'center',
  222.         width: Dimensions.get('window').width,
  223.         justifyContent: 'space-between'
  224.     },
  225.     usageTimeItem: {
  226.         backgroundColor: '#fff',
  227.         paddingHorizontal: 20,
  228.         paddingVertical: 10,
  229.         borderRadius: 18,
  230.         shadowColor: "#000",
  231.         shadowOffset: {
  232.             width: 0,
  233.             height: 1,
  234.         },
  235.         shadowOpacity: 0.22,
  236.         shadowRadius: 2.22,
  237.  
  238.         elevation: 3,
  239.         marginRight: 20,
  240.         marginBottom: 20
  241.     },
  242.     doseTextInput: {
  243.         width: '50%',
  244.         height: 40,
  245.         flex: 1,
  246.         justifyContent: 'center',
  247.         paddingHorizontal: 20,
  248.         borderBottomWidth: 1,
  249.         marginLeft: 20,
  250.         paddingLeft: 0,
  251.         fontSize: 15,
  252.         borderColor: 'rgb(225, 225, 225)'
  253.     },
  254.  
  255.     dropdown: {
  256.         paddingHorizontal: 20,
  257.         paddingVertical: 10,
  258.         paddingBottom: 20,
  259.         borderBottomWidth: 1,
  260.         borderBottomColor: '#E2E2E2',
  261.     },
  262.     inputText: {
  263.         fontSize: 18,
  264.         color: '#000'
  265.     }
  266. });
Advertisement
Add Comment
Please, Sign In to add comment