File tree 6 files changed +66
-5399
lines changed
6 files changed +66
-5399
lines changed Original file line number Diff line number Diff line change 7
7
import React , { Component } from 'react' ;
8
8
import {
9
9
Platform ,
10
- StyleSheet ,
11
- Text ,
12
10
View
13
11
} from 'react-native' ;
14
- import Header from './src/components/header' ;
12
+ import Header from './src/components/Header' ;
13
+ import AlbumList from './src/components/AlbumList' ;
14
+
15
15
16
16
const instructions = Platform . select ( {
17
17
ios : 'Press Cmd+R to reload,\n' +
@@ -24,37 +24,10 @@ type Props = {};
24
24
export default class App extends Component < Props > {
25
25
render ( ) {
26
26
return (
27
- < Header />
28
- // <View style={styles.container}>
29
- // <Text style={styles.welcome}>
30
- // Welcome to React Native App
31
- // </Text>
32
- // <Text style={styles.instructions}>
33
- // That's first App
34
- // </Text>
35
- // <Text style={styles.instructions}>
36
- // {instructions}
37
- // </Text>
38
- // </View>
27
+ < View >
28
+ < Header headerText = 'Albums' />
29
+ < AlbumList />
30
+ </ View >
39
31
) ;
40
32
}
41
33
}
42
-
43
- // const styles = StyleSheet.create({
44
- // container: {
45
- // flex: 1,
46
- // justifyContent: 'center',
47
- // alignItems: 'center',
48
- // backgroundColor: '#F5FCFF',
49
- // },
50
- // welcome: {
51
- // fontSize: 20,
52
- // textAlign: 'center',
53
- // margin: 10,
54
- // },
55
- // instructions: {
56
- // textAlign: 'center',
57
- // color: '#333333',
58
- // marginBottom: 5,
59
- // },
60
- // });
Original file line number Diff line number Diff line change 7
7
"test" : " jest"
8
8
},
9
9
"dependencies" : {
10
+ "axios" : " ^0.18.0" ,
10
11
"react" : " 16.3.1" ,
11
12
"react-native" : " 0.55.4"
12
13
},
Original file line number Diff line number Diff line change
1
+ import React , { Component } from 'react' ;
2
+ import { View , Text } from 'react-native' ;
3
+
4
+ class AlbumDetail extends Component {
5
+ render ( ) {
6
+ const { title } = this . props . album ;
7
+ return (
8
+ < View >
9
+ < Text > { title } </ Text >
10
+ </ View >
11
+ ) ;
12
+ }
13
+ }
14
+ export default AlbumDetail ;
Original file line number Diff line number Diff line change
1
+ import React , { Component } from 'react' ;
2
+ import { View } from 'react-native' ;
3
+ import axios from 'axios' ;
4
+ import AlbumDetail from './AlbumDetail' ;
5
+
6
+ class AlbumList extends Component {
7
+ state = {
8
+ albums : [ ]
9
+ } ;
10
+ componentWillMount ( ) {
11
+ console . log ( 'component will mount in Album list.' ) ;
12
+ axios . get ( 'https://rallycoding.herokuapp.com/api/music_albums' ) . then ( ( response ) => {
13
+ console . log ( 'response is: ' , response . data ) ;
14
+ this . setState ( { albums : response . data } ) ;
15
+ } ) . catch ( ( ( err ) => {
16
+ console . log ( 'catch ' , err ) ;
17
+ } ) ) ;
18
+ }
19
+ renderAlbums ( ) {
20
+ return this . state . albums . map ( album => < AlbumDetail key = { album . title } album = { album } /> ) ;
21
+ }
22
+
23
+ render ( ) {
24
+ return (
25
+ < View >
26
+ { this . renderAlbums ( ) }
27
+ </ View >
28
+ ) ;
29
+ }
30
+ }
31
+
32
+ export default AlbumList ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import { Text , View } from "react-native" ;
3
3
4
- const Header = ( ) => {
4
+ const Header = ( props ) => {
5
5
const { textStyle, viewStyle } = styles ;
6
6
return (
7
7
< View style = { viewStyle } >
8
- < Text style = { textStyle } > Albums </ Text >
8
+ < Text style = { textStyle } > { props . headerText } </ Text >
9
9
</ View >
10
10
) ;
11
11
} ;
@@ -14,9 +14,18 @@ export default Header;
14
14
const styles = {
15
15
viewStyle : {
16
16
backgroundColor : '#F8F8F8' ,
17
+ justifyContent : 'center' ,
18
+ alignItems : 'center' ,
19
+ height : 60 ,
20
+ paddingTop : 15 ,
21
+ shadowColor : '#000' ,
22
+ shadowOffset : { width : 0 , height : 2 } ,
23
+ shadowOpacity : 0.2 ,
24
+ elevation : 2 ,
25
+ position : 'relative' ,
17
26
} ,
18
27
textStyle : {
19
28
fontSize : 20 ,
20
- color : 'red '
29
+ color : 'green '
21
30
}
22
31
} ;
You can’t perform that action at this time.
0 commit comments