Skip to content

Commit ca9702d

Browse files
author
Rizwan Zaheer
authored
Merge pull request rizwanzaheer#1 from RizwanZaheer/Dev
Dev
2 parents 27b9d86 + dd23ea5 commit ca9702d

File tree

6 files changed

+66
-5399
lines changed

6 files changed

+66
-5399
lines changed

App.js

+7-34
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
import React, { Component } from 'react';
88
import {
99
Platform,
10-
StyleSheet,
11-
Text,
1210
View
1311
} 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+
1515

1616
const instructions = Platform.select({
1717
ios: 'Press Cmd+R to reload,\n' +
@@ -24,37 +24,10 @@ type Props = {};
2424
export default class App extends Component<Props> {
2525
render() {
2626
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>
3931
);
4032
}
4133
}
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-
// });

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"test": "jest"
88
},
99
"dependencies": {
10+
"axios": "^0.18.0",
1011
"react": "16.3.1",
1112
"react-native": "0.55.4"
1213
},

src/components/AlbumDetail.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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;

src/components/AlbumList.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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;

src/components/header.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react';
22
import { Text, View } from "react-native";
33

4-
const Header = () => {
4+
const Header = (props) => {
55
const { textStyle, viewStyle } = styles;
66
return (
77
<View style={viewStyle}>
8-
<Text style={textStyle}> Albums </Text>
8+
<Text style={textStyle}> {props.headerText} </Text>
99
</View>
1010
);
1111
};
@@ -14,9 +14,18 @@ export default Header;
1414
const styles = {
1515
viewStyle: {
1616
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',
1726
},
1827
textStyle: {
1928
fontSize: 20,
20-
color: 'red'
29+
color: 'green'
2130
}
2231
};

0 commit comments

Comments
 (0)