Last active
July 11, 2017 05:29
-
-
Save khalid32/53935ddb680646704db40671e17165b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| import { | |
| StyleSheet, | |
| Text, | |
| View, | |
| ListView, | |
| ScrollView | |
| } from 'react-native'; | |
| import Swipeout from 'react-native-swipeout'; | |
| //import Icon from 'react-native-vector-icons/MaterialIcons'; | |
| const url = 'https://jsonplaceholder.typicode.com/photos?_limit=5'; | |
| //editIcon = (<Icon name="edit" size={60} color="#FFF" />), | |
| //deleteIcon = (<Icon name="delete" size={60} color="#FFF" />); | |
| class ListViewDesign extends Component{ | |
| constructor(){ | |
| super(); | |
| const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); | |
| this.state = { | |
| routeDataSource: ds, | |
| sectionID: null, | |
| rowID: null, | |
| }; | |
| } | |
| componentDidMount(){ | |
| this.fetchData(); | |
| } | |
| fetchData(){ | |
| fetch(url) | |
| .then((response) => response.json()) | |
| .then((response) => { | |
| this.setState({ | |
| routeDataSource: this.state.routeDataSource.cloneWithRows(response) | |
| }); | |
| }) | |
| } | |
| deleteData(id){ | |
| url.child(id).remove(); | |
| } | |
| renderRow(route, sectionID, rowID, highlightRow){ | |
| const swipeButton = [ | |
| { | |
| text: 'Edit', | |
| color: "#FFF", | |
| backgroundColor: '#73bace', | |
| onPress: () => alert("This is Edit.."), | |
| }, | |
| { | |
| text: 'Delete', | |
| color: "#FFF", | |
| backgroundColor: '#9b2217', | |
| onPress: () => alert("This is Delete.."), | |
| } | |
| ]; | |
| return( | |
| <Swipeout | |
| style={styles.flexBox} | |
| right={swipeButton} | |
| autoClose={true}> | |
| <View style={styles.row}> | |
| <Text style={[styles.flexBox, styles.fontStyle]}>{route.id}.{"\n"} Title: {route.title}{"\n"} url: {route.url}</Text> | |
| </View> | |
| </Swipeout> | |
| ); | |
| } | |
| render(){ | |
| return( | |
| <View style={styles.flexBox}> | |
| <View style={{flexGrow: 15}}> | |
| <ListView | |
| scrollEnabled | |
| style={{flex: 2}} | |
| dataSource={this.state.routeDataSource} | |
| renderRow={this.renderRow} /> | |
| </View> | |
| <View style={{flexGrow: 1, flexDirection: 'row'}}> | |
| <View style={{flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'red'}}> | |
| <Text style={{color: 'white', fontWeight: '700',}}>Back</Text> | |
| </View> | |
| <View style={{flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'blue'}}> | |
| <Text style={{color: 'white', fontWeight: '700',}}>Submit</Text> | |
| </View> | |
| </View> | |
| </View> | |
| ); | |
| } | |
| } | |
| const styles = StyleSheet.create({ | |
| flexBox: { | |
| flex: 1, | |
| }, | |
| adjustCenter:{ | |
| justifyContent: 'center', | |
| alignItems: 'center', | |
| }, | |
| row: { | |
| flexDirection: 'row', | |
| justifyContent:'center', | |
| padding:12, | |
| backgroundColor:'#f6f6f6', | |
| marginBottom:6 | |
| }, | |
| fontStyle:{ | |
| fontWeight: '400', | |
| fontSize: 15, | |
| } | |
| }); | |
| export default ListViewDesign; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react'; | |
| import { | |
| StyleSheet, | |
| Text, | |
| View, | |
| ListView, | |
| ScrollView, | |
| Image | |
| } from 'react-native'; | |
| class ListViewDesign extends Component{ | |
| constructor(){ | |
| super(); | |
| const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); | |
| this.state = { | |
| routeDataSource: ds, | |
| }; | |
| } | |
| componentDidMount(){ | |
| this.fetchData(); | |
| } | |
| fetchData(){ | |
| fetch('https://jsonplaceholder.typicode.com/photos') | |
| .then((response) => response.json()) | |
| .then((response) => { | |
| this.setState({ | |
| routeDataSource: this.state.routeDataSource.cloneWithRows(response) | |
| }); | |
| }) | |
| } | |
| renderRow(route, sectionID, rowID, highlightRow){ | |
| return( | |
| <View style={styles.row}> | |
| <Text></Text> | |
| <Text style={[styles.flexBox, styles.fontStyle]}>{route.id}.{"\n"} Title: {route.title}{"\n"} url: {route.url}</Text> | |
| <Image style={{height: 60, width: 60}} source={{uri: route.thumbnailUrl}}/> | |
| </View> | |
| ); | |
| } | |
| render(){ | |
| return( | |
| <View style={{flex: 1}}> | |
| <View style={{flexGrow: 15}}> | |
| <ListView | |
| scrollEnabled | |
| style={{flex: 2}} | |
| dataSource={this.state.routeDataSource} | |
| renderRow={this.renderRow} /> | |
| </View> | |
| <View style={{flexGrow: 1, flexDirection: 'row'}}> | |
| <View style={{flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'red'}}> | |
| <Text style={{color: 'white', fontWeight: '700',}}>Back</Text> | |
| </View> | |
| <View style={{flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: 'blue'}}> | |
| <Text style={{color: 'white', fontWeight: '700',}}>Submit</Text> | |
| </View> | |
| </View> | |
| </View> | |
| ); | |
| } | |
| } | |
| const styles = StyleSheet.create({ | |
| flexBox: { | |
| flex: 1, | |
| }, | |
| adjustCenter:{ | |
| justifyContent: 'center', | |
| alignItems: 'center', | |
| }, | |
| row: { | |
| flexDirection: 'row', | |
| justifyContent:'center', | |
| padding:12, | |
| backgroundColor:'#f6f6f6', | |
| marginBottom:6 | |
| }, | |
| fontStyle:{ | |
| fontWeight: '400', | |
| fontSize: 15, | |
| } | |
| }); | |
| export default ListViewDesign; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment