ChatRoom.js
17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
import React, { Component } from 'react';
import {Image, View, Text, StyleSheet,ScrollView,TouchableOpacity,Dimensions,Keyboard } from 'react-native';
import CouponeItem from '../CouponItem'
import StampItem from '../StampItem'
import Modal from 'react-native-modal'
import More from '../../assets/more_.svg'
import Coupon from '../../assets/coupon_chat.svg'
import Stamp from '../../assets/stamp_chat.svg'
import Menu from '../../assets/menu_chat.svg'
import Paper from '../../assets/paper_chat.svg'
import Message from '../Message'
import { TextInput } from 'react-native-gesture-handler';
import Camera from '../../assets/camera_chat.svg'
import Gallery from '../../assets/gallery_chat.svg'
import Option from '../../assets/options_chat.svg'
import ImagePicker from 'react-native-image-picker';
import CouponItem from '../CouponItem'
import MenuItem from '../MenuItem'
import X from '../../assets/X_white.svg'
import {get,post} from 'axios'
import { SERVER } from '../../common/servername';
import AsyncStorage from '@react-native-community/async-storage';
import Loading from './Loading'
const options = {
storageOptions: {
skipBackup: true,
path: 'images',
},
};
export default class AddTab extends Component {
static navigationOptions = {
headerShown: false
}
state = {
isModalVisible:false,
current:1,
select:'선택',
top_height:0,
bottom_height:0,
couponModal:false,
stampModal:false,
menuModal:false,
HistoryModal:false,
loading:true,
Store: {
},
Coupon:[
],
Menu: [
]
,
Stamp:[
],
user:{}
}
constructor(props) {
super(props)
this.scroll = null
this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardDidShow.bind(this));
}
componentWillMount() {
if(!this.props.navigation.state.params) {
this.props.navigation.goBack(null)
return alert('잘못된 접근입니다.')
}
get(`http://${SERVER}/stores/${this.props.navigation.state.params.id}`).then(res => {
this.setState({
Store:res.data.data[0]
})
})
AsyncStorage.getItem("user",(err,res) => {
this.setState({
user:JSON.parse(res)
},() => {
console.log({StoreId:this.props.navigation.state.params.id,UserId:this.state.user.id})
post(`http://${SERVER}/coupons/read`,{StoreId:this.props.navigation.state.params.id,UserId:this.state.user.id}).then(res => {
console.log(res.data.data)
this.setState({
Coupon:res.data.data
})
})
get(`http://${SERVER}/stamps/${this.props.navigation.state.params.id}`,{StoreId:this.props.navigation.state.params.id,UserId:this.state.user.id}).then(res => {
this.setState({
Stamp:res.data.data
})
console.log(res.data.data)
})
get(`http://${SERVER}/menu/${this.props.navigation.state.params.id}`,{StoreId:this.props.navigation.state.params.id,UserId:this.state.user.id}).then(res => {
this.setState({
Menu:res.data.data,
loading:false
})
console.log(res.data.data)
})
})
})
}
componentDidMount() {
this.scroll.scrollToEnd()
}
ImagePick = () => {
ImagePicker.launchImageLibrary(options, (response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri };
// You can also display the image using data:
// const source = { uri: 'data:image/jpeg;base64,' + response.data };
//this.setState({
//avatarSource: source,
//});
}
});
}
_keyboardDidShow() {
this.scroll.scrollToEnd();
}
componentWillUnmount () {
this.keyboardDidShowListener.remove();
}
OpenCamera = () => {
ImagePicker.launchCamera(options,(response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri };
// You can also display the image using data:
// const source = { uri: 'data:image/jpeg;base64,' + response.data };
//this.setState({
//avatarSource: source,
//});
}
})
}
render() {
return (
<View style={{width:"100%", height:"100%"}}>
<View onLayout={e => {
if(e.nativeEvent.layout.height >0) {
this.setState({
top_height:e.nativeEvent.layout.height
})
}}}
style={{marginBottom:8,width:"100%",justifyContent:"space-between",flexDirection:"row",paddingTop:16,paddingBottom:16,paddingLeft:16,paddingRight:16,backgroundColor:"#615F5F"}}>
<TouchableOpacity style={{justifyContent:"center"}} onPress={() => this.props.navigation.goBack(null)}>
<Image source={require('../../assets/back.png')}/>
</TouchableOpacity>
<Text style={{color:"white",fontSize:16,marginLeft:16,alignSelf:"center"}}>
{this.state.Store.name}
</Text>
<TouchableOpacity onPress={() => this.props.navigation.navigate("ChatRoomConfig",{id:this.props.navigation.state.params.id})} style={{justifyContent:"center",width:"10%"}}>
<More style={{marginLeft:"auto"}}/>
</TouchableOpacity>
</View>
<View style={{width:"100%",justifyContent:"space-between",flexDirection:"row",paddingTop:16,paddingBottom:16,paddingLeft:16,paddingRight:16,backgroundColor:"#615F5F"}}>
<TouchableOpacity onPress={() => this.setState({couponModal:true})} style={{flexDirection:"row"}}>
<Coupon/>
<Text style={{color:"white",marginLeft:8}}>
{this.state.Coupon.length}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.setState({stampModal:true})} style={{flexDirection:"row"}}>
<Stamp/>
<Text style={{color:"white",marginLeft:8}}>
{this.state.Stamp.length}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.setState({menuModal:true})} style={{flexDirection:"row"}}>
<Menu/>
<Text style={{color:"white",marginLeft:8}}>
{this.state.Menu.length}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.setState({HistoryModal:true})} style={{flexDirection:"row"}}>
<Paper/>
<Text style={{color:"white",marginLeft:8}}>
3
</Text>
</TouchableOpacity>
</View>
<ScrollView onContentSizeChange={() => this.scroll.scrollToEnd()} ref={(ref) => this.scroll = ref} style={{paddingLeft:16,paddingRight:16,paddingTop:16,paddingBottom:16,backgroundColor:"#F1F1F1",width:"100%"}}>
<Message/>
<Message/>
<Message/>
<Message/>
<Message/>
<Message/>
</ScrollView>
<View onLayout={e => {
if(e.nativeEvent.layout.height >0) {
this.setState({
bottom_height:e.nativeEvent.layout.height
})
}}} style={{
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 6,
},
shadowOpacity: 0.39,
shadowRadius: 8.30,
elevation: 13,flexDirection:"row",justifyContent:"space-between",backgroundColor:"white",width:"100%",paddingTop:11,paddingBottom:10,paddingLeft:16,paddingRight:16}}>
<Camera onPress={() => this.OpenCamera()} style={{alignSelf:"center"}} />
<Gallery onPress={() => this.ImagePick()} style={{alignSelf:"center"}} />
<TextInput style={{width:"71%",borderColor:"#615F5F",borderWidth:1,paddingLeft:16,paddingTop:3,fontSize:15,fontWeight:"bold",paddingBottom:3}} placeholder="메시지를 입력하세요."/>
<Option style={{alignSelf:"center"}} />
</View>
{// Top Tab Modal view
}
<Modal isVisible={this.state.couponModal} onBackButtonPress={() => this.setState({couponModal:false})} >
<View style={{ width:Dimensions.get("screen").width,alignSelf:"center"}}>
<Text style={{color:"white",fontSize:16,textAlign:"center",marginBottom:9}}>
{this.state.user.nickname}님의 보유쿠폰
</Text>
<ScrollView style={{height:"79%"}}>
<View style={{marginBottom:9}}>
<CouponItem user={this.state.user} index={0} height={0}
handleHeight={(e) => this.setHeight(e)} item={this.state.Coupon}/>
</View>
</ScrollView>
</View>
<TouchableOpacity onPress={() => this.setState({couponModal:false})} style={{position:"absolute",bottom:"2%",width:"100%"}}>
<X style={{alignSelf:"center"}}/>
</TouchableOpacity>
</Modal>
<Modal isVisible={this.state.stampModal} onBackButtonPress={() => this.setState({stampModal:false})} >
<Text style={{color:"white",fontSize:16,textAlign:"center",marginBottom:9}}>
{this.state.user.nickname}님의 보유 스탬프
</Text>
<View style={{justifyContent:"center"}}>
<View style={{ width:Dimensions.get("screen").width,alignSelf:"center",}}>
<ScrollView style={{height:"79%"}}>
<View style={{marginBottom:9}}>
<StampItem user={this.state.user} index={0} height={0}
handleHeight={(e) => this.setHeight(e)} item={this.state.Stamp} />
</View>
</ScrollView>
</View>
</View>
<TouchableOpacity onPress={() => this.setState({stampModal:false})} style={{position:"absolute",bottom:"2%",width:"100%"}}>
<X style={{alignSelf:"center"}}/>
</TouchableOpacity>
</Modal>
<Modal isVisible={this.state.menuModal} onBackButtonPress={() => this.setState({menuModal:false})} >
<Text style={{color:"white",fontSize:16,textAlign:"center",marginBottom:9}}>
메뉴
</Text>
<View style={{justifyContent:"center"}}>
<View style={{ width:"100%",alignSelf:"center",}}>
<ScrollView style={{height:"79%"}}>
<View style={{marginBottom:9}}>
<MenuItem store={this.state.Store} isModal={true} index={0} height={0}
handleHeight={(e) => {}} item={this.state.Menu} />
</View>
</ScrollView>
</View>
</View>
<TouchableOpacity onPress={() => this.setState({menuModal:false})} style={{position:"absolute",bottom:"2%",width:"100%"}}>
<X style={{alignSelf:"center"}}/>
</TouchableOpacity>
</Modal>
<Modal isVisible={this.state.HistoryModal} onBackButtonPress={() => this.setState({HistoryModal:false})} >
<Text style={{color:"white",fontSize:16,textAlign:"center",marginBottom:9}}>
결제내역
</Text>
<View style={{justifyContent:"center"}}>
<View style={{ width:"100%",alignSelf:"center",}}>
<ScrollView style={{backgroundColor:"white",paddingTop:7,paddingBottom:23.5,paddingLeft:16,paddingRight:16}}>
<View style={{flexDirection:"row",marginLeft:"auto",marginRight:"auto",marginTop:17}}>
<Image source={require('../../assets/img.png')} style={{width:30,height:30}} resizeMode="stretch"/>
<Text style={{marginLeft:12.5,color:"black",fontSize:14,alignSelf:"center"}}>
네네치킨 송도신도시점
</Text>
<Text style={{color:"#979292",fontSize:10,alignSelf:"center",marginLeft:8.5}}>
20/3/1
</Text>
<Text style={{color:"black",fontSize:14,alignSelf:"center",marginLeft:20}}>
5000₩
</Text>
</View>
<View style={{flexDirection:"row",marginLeft:"auto",marginRight:"auto",marginTop:17}}>
<Image source={require('../../assets/img.png')} style={{width:30,height:30}} resizeMode="stretch"/>
<Text style={{marginLeft:12.5,color:"black",fontSize:14,alignSelf:"center"}}>
네네치킨 송도신도시점
</Text>
<Text style={{color:"#979292",fontSize:10,alignSelf:"center",marginLeft:8.5}}>
20/3/1
</Text>
<Text style={{color:"black",fontSize:14,alignSelf:"center",marginLeft:20}}>
5000₩
</Text>
</View>
<View style={{flexDirection:"row",marginLeft:"auto",marginRight:"auto",marginTop:17}}>
<Image source={require('../../assets/img.png')} style={{width:30,height:30}} resizeMode="stretch"/>
<Text style={{marginLeft:12.5,color:"black",fontSize:14,alignSelf:"center"}}>
네네치킨 송도신도시점
</Text>
<Text style={{color:"#979292",fontSize:10,alignSelf:"center",marginLeft:8.5}}>
20/3/1
</Text>
<Text style={{color:"black",fontSize:14,alignSelf:"center",marginLeft:20}}>
5000₩
</Text>
</View>
</ScrollView>
</View>
</View>
<TouchableOpacity onPress={() => this.setState({HistoryModal:false})} style={{position:"absolute",bottom:"2%",width:"100%"}}>
<X style={{alignSelf:"center"}}/>
</TouchableOpacity>
</Modal>
</View>
);
}
}
const style = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});