DeptPage.js 4.25 KB
Newer Older
YoonDongMin's avatar
부채    
YoonDongMin committed
1
import React, { useState } from 'react';
YoonDongMin's avatar
DongM    
YoonDongMin committed
2
import { StyleSheet, Text, View, FlatList, TouchableOpacity, Modal, Alert, TouchableWithoutFeedback, Keyboard } from 'react-native';
Choi Ga Young's avatar
Choi Ga Young committed
3
import TodoItem from './components/TodoItem';
YoonDongMin's avatar
YdM    
YoonDongMin committed
4
import InfoForm from './screens/InfoForm';
YoonDongMin's avatar
DongM    
YoonDongMin committed
5
import Ionicons from 'react-native-vector-icons/Ionicons';
Choi Ga Young's avatar
Choi Ga Young committed
6
import ButtonsForm from './components/ButtonsForm'; 
YoonDongMin's avatar
YdM    
YoonDongMin committed
7
import { TabView } from 'react-native-elements';
YoonDongMin's avatar
부채    
YoonDongMin committed
8
9


YoonDongMin's avatar
YdM    
YoonDongMin committed
10
function DeptPage({ navigation }) {
YoonDongMin's avatar
DongM    
YoonDongMin committed
11
12
  const [selectedIndex, setSelectedIndex] = useState(0)
  const [modallOpen, setModallOpen] = useState(false);
YoonDongMin's avatar
YdM    
YoonDongMin committed
13
14
15
16
17
  const [todo, setTodo] = useState([
    { date: '7/10', person: 'Mark', money: '100만원', remained_money: '10만원남음', key: '1' },
    { date: '7/10', person: 'John', money: '100만원', remained_money: '10만원남음', key: '2' },
    { date: '7/10', person: 'Steve', money: '100만원', remained_money: '10만원남음', key: '3' }
]);
YoonDongMin's avatar
DongM    
YoonDongMin committed
18
  const [todos, setTodos] = useState([
YoonDongMin's avatar
YdM    
YoonDongMin committed
19
20
21
    { date: '7/10', person: '수빈이', money: '100만원', remained_money: '10만원남음', key: '1' },
    { date: '7/10', person: '수현이', money: '100만원', remained_money: '10만원남음', key: '2' },
    { date: '7/10', person: '가영이', money: '100만원', remained_money: '10만원남음', key: '3' }
YoonDongMin's avatar
DongM    
YoonDongMin committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  ]);

  const addInfo = (info) => {
    info.key = Math.random().toString(); //앞에 key를 받아올수있도록 생성
    setTodos((currentInfos) => {
      return [info, ...currentInfos]; //새로운 정보와 지금까지 정보를 합친다
    });
    setModallOpen(false); //modal이 보여지지 않게
  }

  const pressHandler = (key) => {
    setTodos((prevTodos) => {
      return prevTodos.filter(todo => todo.key != key);
    });
  }
YoonDongMin's avatar
부채    
YoonDongMin committed
37

YoonDongMin's avatar
DongM    
YoonDongMin committed
38
39
40
41
  return (
    <TouchableWithoutFeedback onPress={() => {
      Keyboard.dismiss();
    }}>
YoonDongMin's avatar
YdM    
YoonDongMin committed
42
      <View Style={style.container}>
YoonDongMin's avatar
DongM    
YoonDongMin committed
43
44
45
46
47
        <ButtonsForm
          onPress={(index) => setSelectedIndex(index)}
          selectedIndex={selectedIndex}
          group={["빌려준금액", "빌린금액"]} />

YoonDongMin's avatar
YdM    
YoonDongMin committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
        <View>
          <View style={{ width: '100%', height: '75%' }}>
            <TabView value={selectedIndex} onChange={setSelectedIndex} >
              <TabView.Item style={{ width: '100%', height: '100%' }}>
                <FlatList
                  data={todo}
                  renderItem={({ item }) => (
                    <TouchableOpacity onPress={() => navigation.navigate('InfoDetails', item)}>
                      <TodoItem item={item} pressHandler={pressHandler} />
                    </TouchableOpacity>
                  )}
                />
              </TabView.Item>
              <TabView.Item style={{ width: '100%', height: '100%' }}>
                <FlatList
                  data={todos}
                  renderItem={({ item }) => (
                    <TouchableOpacity onPress={() => navigation.navigate('InfoDetails', item)}>
                      <TodoItem item={item} pressHandler={pressHandler} />
                    </TouchableOpacity>
                  )}
YoonDongMin's avatar
DongM    
YoonDongMin committed
69
                />
YoonDongMin's avatar
YdM    
YoonDongMin committed
70
71
              </TabView.Item>
            </TabView>
YoonDongMin's avatar
DongM    
YoonDongMin committed
72
          </View>
YoonDongMin's avatar
YdM    
YoonDongMin committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
          <Ionicons
            name='add'
            size={24}
            style={style.modalToggle} //...은 중괄호를 풀어서 합치려고 이용함
            onPress={() => setModallOpen(true)}
          />
        </View>
        <View>
          <Modal visible={modallOpen} animationType='slide'>
            <View style={style.modalContent}>
              <Ionicons
                name='close'
                size={24}
                style={style.modalToggle}
                onPress={() => setModallOpen(false)}
              />
              <InfoForm addInfo={addInfo} />

            </View>
          </Modal>
YoonDongMin's avatar
DongM    
YoonDongMin committed
93
        </View>
Choi Ga Young's avatar
Choi Ga Young committed
94
      </View> 
YoonDongMin's avatar
YdM    
YoonDongMin committed
95
    </TouchableWithoutFeedback >
YoonDongMin's avatar
DongM    
YoonDongMin committed
96
  );
YoonDongMin's avatar
부채    
YoonDongMin committed
97
98
99
}


YoonDongMin's avatar
DongM    
YoonDongMin committed
100

YoonDongMin's avatar
YdM    
YoonDongMin committed
101
102
103


const style = StyleSheet.create({
YoonDongMin's avatar
DongM    
YoonDongMin committed
104
105
  container: {
    flex: 1,
YoonDongMin's avatar
YdM    
YoonDongMin committed
106
    width: '100%',
YoonDongMin's avatar
DongM    
YoonDongMin committed
107
108
109
  },
  modalToggle: {
    borderWidth: 1,
YoonDongMin's avatar
YdM    
YoonDongMin committed
110
111
    borderColor: 'gray', //gray
    padding: 5,
YoonDongMin's avatar
DongM    
YoonDongMin committed
112
113
114
    borderRadius: 10,
    alignSelf: 'center', //위치를 center로
  },
YoonDongMin's avatar
YdM    
YoonDongMin committed
115

YoonDongMin's avatar
DongM    
YoonDongMin committed
116
117
118
119
120
121
122
123
124
125
126
127
128
  modalContent: {
    flex: 1, //이후 유용한 키보드를 추가하려고 ex)dismissing keyboard
  },

  TextInput: {
    borderColor: 'skyblue',
    height: 40,
    margin: 12,
    borderWidth: 1
  },
  Font: {
    fontSize: 24
  }
YoonDongMin's avatar
YdM    
YoonDongMin committed
129
130
131
});

export default DeptPage;