Skip to content

Instantly share code, notes, and snippets.

@tugrulcan
Last active June 22, 2017 21:04
Show Gist options
  • Save tugrulcan/975e70a23282f215ba9d94ea40d85753 to your computer and use it in GitHub Desktop.
Save tugrulcan/975e70a23282f215ba9d94ea40d85753 to your computer and use it in GitHub Desktop.
import React from "react";
import {
View,
Text,
ListView,
Image,
TouchableHighlight,
ScrollView,
Linking,
Alert
} from "react-native";
import { connect } from "react-redux";
import studentListData from "../Fixtures/student-data.json";
import ActionButton from "react-native-action-button";
import GiftedListView from "react-native-gifted-listview";
import autobind from "autobind-decorator";
const DELETE_ICON = require("../Images/delete.png");
const USER_EDIT_ICON = require("../Images/user-edit.png");
const USER_ADD_ICON = require("../Images/user-add.png");
const USER_PNG = require("../Images/user.png");
// Add Actions - replace 'Your' with whatever your reducer is called :)
// import YourActions from '../Redux/YourRedux'
// Styles
import styles from "./Styles/OgrenciYonetimiScreenStyle";
class OgrenciYonetimiScreenScreen extends React.Component {
constructor(props) {
super(props);
const rowHasChanged = (r1, r2) => r1 !== r2;
this.data_obj = studentListData.studentList;
// DataSource configured
this.ds = new ListView.DataSource({ rowHasChanged });
// Datasource is always in state
this.state = {
//dataObjects: this.data_obj,
dataSource: this.ds.cloneWithRows(this.data_obj)
};
this._delete = this._delete.bind(this);
this.renderRow = this.renderRow.bind(this);
}
_delete(rowData) {
console.log(rowData);
let index = this.data_obj.findIndex(x => x.studentID == rowData.studentID);
console.log(index);
alert(this.data_obj[index].name);
let a = this.data_obj.splice(index, 1);
console.log(a);
///console.log(this.data_obj[index].name);
this.setState({
dataSource: this.state.dataSource.cloneWithRows(this.data_obj)
});
}
renderRow(rowData, rowID) {
return (
<View style={styles.row}>
<View style={{ flex: 3 }}>
<Image
style={{ width: 90, height: 90, borderRadius: 50 }}
source={USER_PNG}
//source={{ uri: rowData.photoURL }}
/>
</View>
<View style={{ justifyContent: "flex-start", flex: 3 }}>
<Text style={styles.boldLabel}>{rowData.name}</Text>
<Text style={styles.label}>{rowData.parentName}</Text>
<Text style={styles.label}>{rowData.parentPhone}</Text>
</View>
<View style={{ justifyContent: "center", flex: 3 }}>
<Image style={{ width: 40, height: 40 }} source={USER_EDIT_ICON} />
</View>
<View style={{ flex: 3 }}>
<TouchableHighlight
onPress={() =>
Alert.alert(
"Öğrenci bilgilerini silmek istiyor musunuz?",
rowData.name,
[
{
text: "İptal",
onPress: () => console.log("Cancel Pressed"),
style: "cancel"
},
{
text: "Sil",
onPress: () => this._delete(rowData) // <----- HERE!!!!
}
],
{ cancelable: true }
)}
>
<Image style={{ width: 40, height: 40 }} source={DELETE_ICON} />
</TouchableHighlight>
</View>
</View>
);
}
/* ***********************************************************
* STEP 4
* If your datasource is driven by Redux, you'll need to
* reset it when new data arrives.
* DO NOT! place `cloneWithRows` inside of render, since render
* is called very often, and should remain fast! Just replace
* state's datasource on newProps.
*
* e.g.
componentWillReceiveProps (newProps) {
if (newProps.someData) {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(newProps.someData)
})
}
}
*************************************************************/
// Used for friendly AlertMessage
// returns true if the dataSource is empty
noRowData() {
return this.state.dataSource.getRowCount() === 0;
}
// Render a footer.
renderFooter = () => {
return <Text> - Footer - </Text>;
};
render() {
return (
<View style={styles.container}>
<Text style={styles.headerText}>Öğrenci Yönetimi Ekranı</Text>
<GiftedListView
rowView={this.renderRow}
dataSource={this.state.dataSource}
firstLoader={true} // display a loader for the first fetching
refreshable={true} // enable pull-to-refresh for iOS and touch-to-refresh for Android
refreshableTintColor="blue"
/>
{/* Rest of the app comes ABOVE the action button component !*/}
<ActionButton
buttonColor="rgba(30, 144, 255,1)"
position="center"
size={100}
icon={
<Image
source={USER_ADD_ICON}
style={{
height: 72,
width: 72,
borderRadius: 50
}}
/>
}
onPress={() => {
//URL https://gist.github.com/tugrulcan/1261c428095227ed7c8d7a089ce7d5a0
const url =
"http://maps.google.com/maps?saddr=38.491697,27.707017&daddr=1901.%20Sk.%20No:43,%20Saruhan%20Mahallesi,%2045010%20Manisa%20Merkez/Manisa,%20T%C3%BCrkiye+to:Oktay%20Erol%20Pulcuo%C4%9Flu%20Cd.%20No:8,%2045030%20Ke%C3%A7ilik%C3%B6y%20Osb/Manisa%20Merkez/Manisa,%20T%C3%BCrkiye+to:Manisa%20TOK%C4%B0%20Konutlar%C4%B1%20No:3,%20Uncubozk%C3%B6y%20Mahallesi,%2045030%20Manisa%20Merkez/Manisa,%20T%C3%BCrkiye+to:5619.%20Sk.%20No:2,%20Ke%C3%A7ili%20K%C3%B6y%20Mahallesi,%2045030%20Manisa%20Merkez/Manisa,%20T%C3%BCrkiye+to:Vali%20Azizbey%20Cd.%20No:34,%2075.%20Y%C4%B1l%20Mahallesi,%2045030%20Manisa%20Merkez/Manisa,%20T%C3%BCrkiye+to:43.%20Sk.%20No:23,%20Turgut%20%C3%96zal%20Mahallesi,%2045040%20Manisa%20Merkez/Manisa,%20T%C3%BCrkiye+to:308.%20Sk.%20No:130,%20Kaz%C4%B1m%20Karabekir%20Mahallesi,%2045040%20%C5%9Eehzadeler/Manisa,%20T%C3%BCrkiye+to:1803.%20Sk.%20No:7,%20%C3%87ar%C5%9F%C4%B1%20Mahallesi,%2045010%20Manisa%20Merkez/Manisa,%20T%C3%BCrkiye+to:Muradiye%20Mah.%20Manolya%20Sokak%20No:234%20Yunusemre%20-%20Manisa&dirflg=d";
Linking.openURL(url);
}}
/>
</View>
);
}
}
const mapStateToProps = state => {
return {};
};
const mapDispatchToProps = dispatch => {
return {};
};
export default connect(mapStateToProps, mapDispatchToProps)(
OgrenciYonetimiScreenScreen
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment