Showing
2 changed files
with
117 additions
and
20 deletions
... | @@ -207,11 +207,16 @@ export default class MovieRankingTab extends Component { | ... | @@ -207,11 +207,16 @@ export default class MovieRankingTab extends Component { |
207 | var date = year + "" + month + day; | 207 | var date = year + "" + month + day; |
208 | this.getMovieList(date); | 208 | this.getMovieList(date); |
209 | } | 209 | } |
210 | + | ||
211 | + //눌렀을 때 저장함수 | ||
210 | _onPressButton(temp) { | 212 | _onPressButton(temp) { |
211 | - Alert.alert(temp); //메시지 띄우고 | 213 | + //this.state.list = ""; //초기화(On Off 기능으로 짜놨습니당, 누적되는거 보고싶으면 이부분 주석달면 돼여) |
212 | - console.log(temp); //콘솔에 log 띄운다 | 214 | + Alert.alert(temp);//메시지 띄우고 |
213 | - AsyncStorage.setItem("MovieLists", temp); //DB에 저장한다 | 215 | + this.state.list = this.state.list + '\n' + temp; //list 누적해준다(endl으로 구분) |
216 | + console.log(this.state.list);//콘솔에 log 띄운다 | ||
217 | + AsyncStorage.setItem('MovieLists', this.state.list); //DB에 저장한다 | ||
214 | } | 218 | } |
219 | + | ||
215 | render() { | 220 | render() { |
216 | return ( | 221 | return ( |
217 | <SafeAreaView style={style.container}> | 222 | <SafeAreaView style={style.container}> | ... | ... |
1 | -import React, { Component } from "react"; | 1 | +import React, { Component } from 'react'; |
2 | -import { View, Text, StyleSheet } from "react-native"; | 2 | +import { |
3 | + StyleSheet, | ||
4 | + Text, | ||
5 | + View, | ||
6 | + TouchableOpacity, | ||
7 | + AsyncStorage, | ||
8 | + ScrollView, | ||
9 | + Image, | ||
10 | +} from 'react-native'; | ||
3 | import { Icon } from "native-base"; | 11 | import { Icon } from "native-base"; |
12 | +import axios from "axios"; | ||
13 | +const API_KEY = "2bf00f660b1a6a3ffeb6e06ac270cce3"; | ||
14 | +const NAVER_CLIENT_ID = "KqPsntd1hcPJ8FUPBGqN"; | ||
15 | +const NAVER_CLIENT_SECRET = "0GRb3uya1U"; | ||
4 | 16 | ||
5 | -export default class WantToWatchTab extends Component { | 17 | + |
6 | - static navigationOptions = { | 18 | +export default class App extends Component { |
7 | - tabBarIcon: ({ tintColor }) => ( | 19 | + state = { |
8 | - <Icon name="ios-star" style={{ color: tintColor }} /> | 20 | + list: "", //영화 제목 list |
9 | - ) | 21 | + date: "", //날짜 |
10 | - }; | 22 | + imgurl0: [], //이미지 |
11 | - render() { | 23 | + name0: [], //제목 |
12 | - return ( | 24 | + }; |
13 | - <View style={style.container}> | 25 | + |
14 | - <Text>WantToWatchTab</Text> | 26 | + //날짜 정하기 |
15 | - </View> | 27 | + componentDidMount() { |
16 | - ); | 28 | + var day = new Date().getDate() - 1; // 어제 날짜 |
17 | - } | 29 | + if (day == 1) { |
30 | + day = 30; | ||
31 | + } else if (day < 10) { | ||
32 | + day = "0" + day; | ||
33 | + } | ||
34 | + var month = new Date().getMonth() + 1; //Current Month | ||
35 | + var year = new Date().getFullYear(); //Current Year | ||
36 | + var date = year + "" + month + day; | ||
37 | + this.getMovieList(date); | ||
38 | + this.setData(); | ||
39 | + } | ||
40 | + | ||
41 | + getMovieList = async date => { | ||
42 | + axios | ||
43 | + .get( | ||
44 | + `http://www.kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json?key=${API_KEY}&targetDt=${date}` | ||
45 | + ) | ||
46 | + .then( | ||
47 | + response => { | ||
48 | + this.setState({ | ||
49 | + //영화 제목 | ||
50 | + name0: response.data.boxOfficeResult.dailyBoxOfficeList[0].movieNm, | ||
51 | + }); | ||
52 | + | ||
53 | + temp = response.data.boxOfficeResult.dailyBoxOfficeList[0].movieNm; | ||
54 | + fetch( | ||
55 | + `https://openapi.naver.com/v1/search/movie.json?query='${temp}'`, | ||
56 | + { | ||
57 | + headers: { | ||
58 | + "X-Naver-Client-Id": NAVER_CLIENT_ID, | ||
59 | + "X-Naver-Client-Secret": NAVER_CLIENT_SECRET | ||
60 | + } | ||
61 | + } | ||
62 | + ) | ||
63 | + .then(response => response.json()) | ||
64 | + .then(json => { | ||
65 | + this.setState({ | ||
66 | + imgurl0: json.items[0].image | ||
67 | + }); | ||
68 | + }); | ||
69 | + } | ||
70 | + ) | ||
71 | + .catch(error => { | ||
72 | + console.log(error); | ||
73 | + }); | ||
74 | + }; | ||
75 | + | ||
76 | + //네비게이션 바 | ||
77 | + static navigationOptions = { | ||
78 | + tabBarIcon: ({ tintColor }) => ( | ||
79 | + <Icon name='ios-star' style={{ color: tintColor }} /> | ||
80 | + ) | ||
81 | + } | ||
82 | + | ||
83 | + //Data 설정함수 | ||
84 | + setData = async () => { | ||
85 | + try { | ||
86 | + this.state.list = await AsyncStorage.getItem('MovieLists'); //List에 받아온다 | ||
87 | + //console.log(this.state.list); //잘 뜨는데?? | ||
88 | + } | ||
89 | + catch (error) { | ||
90 | + alert(error) | ||
91 | + } | ||
92 | + } | ||
93 | + | ||
94 | + | ||
95 | + render() { | ||
96 | + return ( | ||
97 | + <View style={styles.container}> | ||
98 | + <TouchableOpacity onPress={this.componentDidMount.bind(this)}> | ||
99 | + {/* 눌러용 누르면 리스트 갱신됩니다 */} | ||
100 | + <Text style={styles.textStyle}>눌러용</Text> | ||
101 | + </TouchableOpacity> | ||
102 | + <Text style={styles.textStyle}>{this.state.list}</Text> | ||
103 | + </View> | ||
104 | + ); | ||
105 | + } | ||
18 | } | 106 | } |
19 | 107 | ||
20 | -const style = StyleSheet.create({ | 108 | +const styles = StyleSheet.create({ |
21 | container: { | 109 | container: { |
22 | backgroundColor: "black", | 110 | backgroundColor: "black", |
23 | flex: 1, | 111 | flex: 1, |
24 | alignItems: "center", | 112 | alignItems: "center", |
25 | justifyContent: "center" | 113 | justifyContent: "center" |
26 | - } | 114 | + }, |
115 | + textStyle: { | ||
116 | + fontSize: 25, | ||
117 | + color: "white", | ||
118 | +}, | ||
27 | }); | 119 | }); | ... | ... |
-
Please register or login to post a comment