Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react'
- import {
- View,
- Text,
- AppRegistry,
- Image,
- StyleSheet,
- TextInput,
- TouchableOpacity,
- Dimensions,
- KeyboardAvoidingView,
- StatusBar,
- ScrollView,
- Slider,
- ListView,
- }
- from 'react-native';
- import { Card } from 'react-native-material-design';
- const { width, height } = Dimensions.get("window");
- import MultiSlider from '@ptomasroos/react-native-multi-slider';
- import Checkbox from 'react-native-custom-checkbox';
- import { RadioButtons } from 'react-native-radio-buttons'
- var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
- export default class Filter extends Component {
- constructor(props) {
- super(props);
- this.CheckRoom = this.CheckRoom.bind(this)
- this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
- }
- onNavigatorEvent(event) {
- if (event.id === 'done') {
- this.props.navigator.dismissModal({
- animationType: 'slide-down' ,
- });
- }
- }
- componentWillMount() {
- this.setState({
- Price_range : '',
- Property: [
- ],
- Room: [
- ],
- Amenity : [
- ],
- sliderOneChanging: false,
- checked: false,
- Ameneties_Array : ds.cloneWithRows([]),
- });
- this.Aminity();
- }
- async Aminity(){
- let response = await fetch('http://api.yohobed.com/api/amenity');
- let body = await response.json();
- this.setState({
- Ameneties_Array: this.state.Ameneties_Array.cloneWithRows(body.amenity),
- isLoading : true,
- });
- }
- CheckRoom = (room_category,checked) =>{
- if(checked === true){
- this.state.Room.push({room_category});
- }else {
- this.state.Room.pop({room_category});
- }
- }
- Check = (property_type,checked) => {
- if(checked === true){
- this.state.Property.push({property_type});
- }else {
- this.state.Property.pop({property_type});
- }
- }
- CheckAmenity(Amenity_type, checked){
- if(checked === true){
- this.state.Amenity.push({Amenity_type});
- }else {
- this.state.Amenity.pop({Amenity_type});
- }
- }
- renderRow(rowData: {}, sectionID: number, rowID: number){
- return (
- <View >
- <View style={styles.amenty}>
- <Text style={styles.checkboxTextWrpr}>{rowData.name}</Text>
- <Checkbox name={rowData.name} style={{color:'#666', borderWidth: 1}} onChange={(Amenity_type,checked) => this.CheckAmenity(Amenity_type, checked)}/>
- </View>
- </View>
- );
- }
- componentWillUnmount () {
- if (this.props.callback){
- var Price_range =this.state.Price_range;
- var Property =this.state.Property;
- var Room =this.state.Room;
- var Aminity =this.state.Amenity;
- var Filters={};
- Filters={Price_range,Property,Room,Aminity};
- this.props.callback(Filters);
- }
- }
- render(){
- const options = [
- "Below 2,499 LKR",
- "2,500 - 4,499 LKR",
- "4,500 - 7,499 LKR",
- "7,500 - 9,999 LKR",
- "Above 10,000 LKR",
- ];
- function setSelectedOption(selectedOption){
- if(selectedOption === "Below 2,499 LKR"){
- this.state.Price_range = 'A';
- }else if(selectedOption === "2,500 - 4,499 LKR"){
- this.state.Price_range = 'B';
- }else if(selectedOption === "4,500 - 7,499 LKR"){
- this.state.Price_range = 'C';
- }else if (selectedOption === "7,500 - 9,999 LKR") {
- this.state.Price_range = 'D';
- }else if (selectedOption === "Above 10,000 LKR") {
- this.state.Price_range = 'E';
- }else {
- this.state.Price_range = 'F';
- }
- }
- function renderOption(option, selected, onSelect, index){
- const style = selected ? { color:'#00b0bf', paddingBottom:10, fontFamily:'Lato-Light', fontSize:14} :{color:'#666', paddingBottom:10, fontFamily:'Lato-Light', fontSize:14};
- return (
- <TouchableOpacity onPress={onSelect} key={index}>
- <Text style={style}>{option}</Text>
- </TouchableOpacity>
- );
- }
- function renderContainer(optionNodes){
- return <View>{optionNodes}</View>;
- }
- return(
- <View style= {{flex : 1, backgroundColor : "#FFFFFF"}}>
- <StatusBar backgroundColor="#078f99" barStyle="light-content" />
- <ScrollView>
- <View style={styles.mainWraprFilter}>
- <View style={styles.roomTypeWrpr}>
- <Text style={styles.mainTextWrpr}>Room Type</Text>
- <Card style={{margin:0, marginTop:10, paddingTop:4, shadowColor:"#ccc", shadowOffset:{width:1, height:1}, shadowOpacity:0.8, paddingRight:10, paddingLeft:10}}>
- <Card.Body>
- <View style={{justifyContent:"space-between", flexDirection:'row'}}>
- <Text style={styles.checkboxTextWrpr}>Premium</Text>
- <Checkbox name='Premium' style={{color:'#666', borderWidth: 1}} onChange={(room_category,checked) => this.CheckRoom(room_category, checked)}/>
- </View>
- <View style={{justifyContent:"space-between", flexDirection:'row', marginTop:10}}>
- <Text style={styles.checkboxTextWrpr}>Standard</Text>
- <Checkbox name='Standard' style={{color:'#666', borderWidth: 1}} onChange={(room_category,checked) => this.CheckRoom(room_category, checked)}/>
- </View>
- <View style={{justifyContent:"space-between", flexDirection:'row', marginTop:10, marginBottom:4}}>
- <Text style={styles.checkboxTextWrpr}>Alternative</Text>
- <Checkbox name='Alternative' style={{color:'#666', borderWidth: 1}} onChange={(room_category,checked) => this.CheckRoom(room_category, checked)}/>
- </View>
- </Card.Body>
- </Card>
- </View>
- <View>
- <Text style={{flexDirection:'row',fontSize:15,marginTop:10,fontFamily:'Lato-Regular',color:'#666'}}>Price Range</Text>
- <Card style={{margin:0, marginTop:10, paddingTop:10, paddingBottom:5,shadowColor:"#ccc", shadowOffset:{width:1, height:1}, shadowOpacity:0.8, paddingRight:10, paddingLeft:10}}>
- <Card.Body>
- <RadioButtons
- options={ options }
- onSelection={ setSelectedOption.bind(this) }
- selectedOption={this.state.selectedOption }
- renderOption={ renderOption }
- renderContainer={ renderContainer }
- />
- </Card.Body>
- </Card>
- </View>
- <View style={styles.propertyWrpr}>
- <Text style={styles.mainTextWrpr}>Property Type</Text>
- <Card style={{margin:0, marginTop:10, paddingTop:10, paddingBottom:10, shadowColor:"#ccc", shadowOffset:{width:1, height:1}, shadowOpacity:0.8, paddingRight:10, paddingLeft:10}}>
- <Card.Body>
- <View style={{justifyContent:"space-between", flexDirection:'row', marginBottom:10}}>
- <Text style={styles.checkboxTextWrpr}>Home stay</Text>
- <Checkbox name='Home stay'style={{color:'#666', borderWidth: 1}} onChange={(property_type,checked) => this.Check(property_type, checked)}/>
- </View>
- <View style={{justifyContent:"space-between", flexDirection:'row', marginBottom:10}}>
- <Text style={styles.checkboxTextWrpr}>Apartment</Text>
- <Checkbox name='Apartment' style={{color:'#666', borderWidth: 1}} onChange={(property_type,checked) => this.Check(property_type, checked)}/>
- </View>
- <View style={{justifyContent:"space-between", flexDirection:'row', marginBottom:10}}>
- <Text style={styles.checkboxTextWrpr}>Hotel</Text>
- <Checkbox name='Hotel' style={{color:'#666', borderWidth: 1}} onChange={(property_type,checked) => this.Check(property_type, checked)}/>
- </View>
- <View style={{justifyContent:"space-between", flexDirection:'row', marginBottom:10}}>
- <Text style={styles.checkboxTextWrpr}>Hostel</Text>
- <Checkbox name='Hostel' style={{color:'#666', borderWidth: 1}} onChange={(property_type,checked) => this.Check(property_type, checked)}/>
- </View>
- <View style={{justifyContent:"space-between", flexDirection:'row', marginBottom:10}}>
- <Text style={styles.checkboxTextWrpr}>Villa</Text>
- <Checkbox name='Villa' style={{color:'#666', borderWidth: 1}} onChange={(property_type,checked) => this.Check(property_type, checked)}/>
- </View>
- <View style={{justifyContent:"space-between", flexDirection:'row', marginBottom:10}}>
- <Text style={styles.checkboxTextWrpr}>Guest House</Text>
- <Checkbox name='Guest House' style={{color:'#666', borderWidth: 1}} onChange={(property_type,checked) => this.Check(property_type, checked)}/>
- </View>
- <View style={{justifyContent:"space-between", flexDirection:'row', marginBottom:10}}>
- <Text style={styles.checkboxTextWrpr}>Motor Home</Text>
- <Checkbox name='Motor Home' style={{color:'#666', borderWidth: 1}} onChange={(property_type,checked) => this.Check(property_type, checked)}/>
- </View>
- <View style={{justifyContent:"space-between", flexDirection:'row'}}>
- <Text style={styles.checkboxTextWrpr}>Bungalow</Text>
- <Checkbox name='Bungalow' style={{color:'#666', borderWidth: 1}} onChange={(property_type,checked) => this.Check(property_type, checked)}/>
- </View>
- </Card.Body>
- </Card>
- </View>
- <View style={styles.propertyWrpr}>
- <Text style={styles.mainTextWrpr}>Ameneties</Text>
- <Card style={{margin:0, marginTop:10, shadowColor:"#ccc", shadowOffset:{width:1, height:1}, shadowOpacity:0.8, paddingRight:10, paddingLeft:10, paddingTop:10}}>
- <Card.Body>
- <ListView
- dataSource={this.state.Ameneties_Array}
- renderRow={(rowData) => this.renderRow(rowData)}
- navigator={this.props.navigator}
- />
- </Card.Body>
- </Card>
- </View>
- </View>
- </ScrollView>
- </View>
- );
- }
- }
- const styles = StyleSheet.create({
- slider: {
- height: 5,
- margin: 10,
- },
- mainWraprFilter:{
- // padding:20,
- paddingLeft:20,
- paddingRight:20,
- paddingBottom:40
- },
- roomTypeWrpr:{
- marginBottom:15,
- marginTop:10
- },
- mainCheckboxWrpr:{
- shadowColor:"#ddd",
- shadowOffset:{width:2, height:2},
- shadowOpacity:0.8,
- paddingTop:5,
- paddingRight:15,
- paddingLeft:15,
- marginTop:20
- },
- sliderWrapr:{
- shadowColor:"#ddd",
- shadowOffset:{width:2, height:2},
- shadowOpacity:0.8,
- paddingTop:5,
- paddingRight:15,
- paddingLeft:15,
- marginTop:20,
- paddingBottom:10,
- },
- mainTextWrpr:{
- flexDirection:'row',
- fontSize:15,
- marginTop:20,
- fontFamily:'Lato-Regular',
- color:'#666'
- },
- roomTypeFilterWrpr:{
- flexDirection:'row'
- },
- checkBoxWrpr:{
- flexDirection:'row',
- alignItems:'flex-end',
- marginBottom:5,
- },
- 'checkBoxWrpr:last-child':{
- marginBottom:0,
- },
- checkboxTextWrpr:{
- flexDirection:'row',
- color:'#666',
- fontSize:14,
- fontFamily:'Lato-Light',
- marginTop:2
- },
- checkBoxNative:{
- flexDirection:'row',
- },
- priceWrpr:{
- marginBottom:5
- },
- propertyWrpr:{
- },
- amenty:{
- justifyContent:"space-between",
- flexDirection:'row',
- marginBottom:10
- },
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement