Showing
1 changed file
with
43 additions
and
137 deletions
1 | -import React, { Component } from 'react'; | 1 | +import React, {Component} from 'react'; |
2 | -import { | 2 | +import {Platform, StyleSheet, Text, |
3 | - StyleSheet, | 3 | + View,TouchableOpacity, AsyncStorage, |
4 | - Text, | 4 | +} from 'react-native'; |
5 | - View, | 5 | +import { Icon } from "native-base"; |
6 | - ScrollView, | 6 | + |
7 | - TouchableOpacity, | 7 | + |
8 | - Image, | 8 | +export default class App extends Component { |
9 | - Alert, | ||
10 | - AsyncStorage | ||
11 | - } from 'react-native'; | ||
12 | -import { Icon } from 'native-base'; | ||
13 | -import axios from "axios"; | ||
14 | -const API_KEY = "2bf00f660b1a6a3ffeb6e06ac270cce3"; | ||
15 | -const NAVER_CLIENT_ID = "KqPsntd1hcPJ8FUPBGqN"; | ||
16 | -const NAVER_CLIENT_SECRET = "0GRb3uya1U"; | ||
17 | -import uuidv1 from "uuid/v1"; //ID 만들기위해 import | ||
18 | - | ||
19 | - | ||
20 | -export default class WantToWatchTab extends Component { | ||
21 | //네비게이션 바 | 9 | //네비게이션 바 |
22 | static navigationOptions = { | 10 | static navigationOptions = { |
23 | tabBarIcon: ({ tintColor }) => ( | 11 | tabBarIcon: ({ tintColor }) => ( |
24 | <Icon name='ios-star' style={{ color: tintColor }} /> | 12 | <Icon name='ios-star' style={{ color: tintColor }} /> |
25 | ) | 13 | ) |
26 | } | 14 | } |
27 | - | ||
28 | - state = { | ||
29 | - isLoading: true, | ||
30 | - info: [], | ||
31 | - date: "", | ||
32 | - imgur1: [] | ||
33 | - }; | ||
34 | - | ||
35 | - getMovieList = async date => { | ||
36 | - axios | ||
37 | - .get( | ||
38 | - `http://www.kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json?key=${API_KEY}&targetDt=${date}` | ||
39 | - ) | ||
40 | - .then( | ||
41 | - response => { | ||
42 | - this.setState({ | ||
43 | - //영화 제목 | ||
44 | - name0: response.data.boxOfficeResult.dailyBoxOfficeList[0].movieNm, | ||
45 | - info: response.data.boxOfficeResult.dailyBoxOfficeList | ||
46 | - }); | ||
47 | - | ||
48 | - name = response.data.boxOfficeResult.dailyBoxOfficeList[0].movieNm; | ||
49 | - fetch( | ||
50 | - `https://openapi.naver.com/v1/search/movie.json?query='${name}'`, | ||
51 | - { | ||
52 | - headers: { | ||
53 | - "X-Naver-Client-Id": NAVER_CLIENT_ID, | ||
54 | - "X-Naver-Client-Secret": NAVER_CLIENT_SECRET | ||
55 | - } | ||
56 | - } | ||
57 | - ) | ||
58 | - .then(response => response.json()) | ||
59 | - .then(json => { | ||
60 | - this.setState({ | ||
61 | - imgurl0: json.items[0].image | ||
62 | - }); | ||
63 | - }); | ||
64 | - } | ||
65 | - ) | ||
66 | - .catch(error => { | ||
67 | - console.log(error); | ||
68 | - }); | ||
69 | - }; | ||
70 | - | ||
71 | - //날짜 정하기 | ||
72 | - componentDidMount() { | ||
73 | - var day = new Date().getDate() - 1; // 어제 날짜 | ||
74 | - if (day == 1) { | ||
75 | - day = 30; | ||
76 | - } else if (day < 10) { | ||
77 | - day = "0" + day; | ||
78 | - } | ||
79 | - var month = new Date().getMonth() + 1; //Current Month | ||
80 | - var year = new Date().getFullYear(); //Current Year | ||
81 | - var date = year + "" + month + day; | ||
82 | - this.getMovieList(date); | ||
83 | - } | ||
84 | - | ||
85 | - //눌렀을 때 동작 | ||
86 | - _onPressButton = () => { | ||
87 | - Alert.alert("Image Pressed"); | ||
88 | - | ||
89 | - }; | ||
90 | - | ||
91 | - | ||
92 | - | ||
93 | - render() { | ||
94 | - return ( | ||
95 | - <ScrollView style={style.scrollView}> | ||
96 | - <Text style={style.title}>MovieRanking</Text> | ||
97 | - <View style={style.lowContainer}> | ||
98 | - <TouchableOpacity | ||
99 | - style={style.button} | ||
100 | - onPress={this._onPressButton}//누르는 동작 | ||
101 | - > | ||
102 | - <Image | ||
103 | - style={style.poster} | ||
104 | - source={{ uri: `${this.state.imgurl0}` }} | ||
105 | - /> | ||
106 | - <Text>{this.state.name0}</Text> | ||
107 | - </TouchableOpacity> | ||
108 | - </View> | ||
109 | - </ScrollView> | ||
110 | - ); | ||
111 | - } | ||
112 | -} | ||
113 | - | ||
114 | - | ||
115 | -const style = StyleSheet.create({ | ||
116 | - container: { | ||
117 | - flex: 1 | ||
118 | - }, | ||
119 | - scrollView: { | ||
120 | - // backgroundColor: "black", | ||
121 | - // justifyContent: "center", | ||
122 | - // alignItems: "center" | ||
123 | - }, | ||
124 | - title: { | ||
125 | - fontSize: 20, | ||
126 | - justifyContent: "center", | ||
127 | - alignItems: "center" | ||
128 | - }, | ||
129 | - lowContainer: { | ||
130 | - flex: 1, | ||
131 | - flexDirection: "row", | ||
132 | - justifyContent: "center", | ||
133 | - alignItems: "center" | ||
134 | - }, | ||
135 | - poster: { | ||
136 | - // resizeMode: "cover", | ||
137 | - flex: 10, | ||
138 | - width: "90%", | ||
139 | - height: 200, | ||
140 | - paddingHorizontal: 50 | ||
141 | - // alignItems: "stretch" | ||
142 | - }, | ||
143 | - }); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
15 | + saveData(){ | ||
16 | + let name = "앙기모띠"; | ||
17 | + AsyncStorage.setItem('user',name); | ||
18 | + } | ||
19 | + displayData = async ()=>{ | ||
20 | + try{ | ||
21 | + let user = await AsyncStorage.getItem('user'); | ||
22 | + alert(user); | ||
23 | + } | ||
24 | + catch(error){ | ||
25 | + alert(error) | ||
26 | + } | ||
27 | + } | ||
28 | + render() { | ||
29 | + return ( | ||
30 | + <View style={styles.container}> | ||
31 | + <TouchableOpacity onPress ={this.saveData}> | ||
32 | + <Text>User정보 저장</Text> | ||
33 | + </TouchableOpacity> | ||
34 | + <TouchableOpacity onPress ={this.displayData}> | ||
35 | + <Text>User정보 출력</Text> | ||
36 | + </TouchableOpacity> | ||
37 | + </View> | ||
38 | + ); | ||
39 | + } | ||
40 | +} | ||
41 | + | ||
42 | +const styles = StyleSheet.create({ | ||
43 | + container: { | ||
44 | + flex: 1, | ||
45 | + justifyContent: 'center', | ||
46 | + alignItems: 'center', | ||
47 | + backgroundColor: '#F5FCFF', | ||
48 | + }, | ||
49 | +}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment