Skip to main content

DATE PICKER REACT NATIVE USING FLATLIST

import React, { Component, Fragment } from "react";
import { StyleSheet, View, FlatList, Image, Text} from "react-native";
import { Appbar, TextInput, Caption, List, Button} from "react-native-paper";
import { Formik } from 'formik';
import * as yup from 'yup';
import DatePicker from 'react-native-date-picker';

const DATE_SCHEMA = yup.object().shape({
 
  start_date: yup.string()
    .required('Start Date Required'),
  end_date: yup.string()
    .required('End Date Required'),

});
const IMAGE = require("../assets/voice/flag-blue.png");

export default class AlertButton extends Component {

  state = {
    start_date : new Date(),
    end_date : new Date(),
    files : [],
    efiles : [{
      "id": "No Media",
      "userid": "No Media",         
      "filename": ""
    }]
   }

  searchMedia(values){

    var startobjdate = values.start_date.getFullYear()+'-'+(values.start_date.getMonth()+1)+'-'+values.start_date.getDate()+' '+values.start_date.toLocaleTimeString();
   
    var endobjdate = values.end_date.getFullYear()+'-'+(values.end_date.getMonth()+1)+'-'+values.end_date.getDate()+' '+values.end_date.toLocaleTimeString();;


    fetch('http://xxxxxxx/services/searchBydate?startdate='+ startobjdate + '&enddate=' + endobjdate)
    .then(response => response.json())
    .then(data => {
      if(data.status == true){
        this.setState({ files : data.result })
      }
      else {
        this.setState({ files : this.state.efiles })
      }
   
    });

  }

  render() {

    const { files, efiles } = this.state;
    return (
      <View style={styles.container}>  
          <Appbar.Header>
            <Appbar.BackAction
              onPress={this._goBack}
            />
            <Appbar.Content
              title="SELECT MEDIA"
            />       
          </Appbar.Header>   
        <View style={{ paddingVertical : 30 }}>      
          <Formik                           
                initialValues={{ start_date: this.state.start_date, end_date: this.state.end_date }}
                onSubmit={values => this.searchMedia(values)}
                validationSchema={DATE_SCHEMA}
                >
                {({ values, handleReset, handleChange, errors, setFieldTouched, touched, isValid, handleSubmit }) => (
                  <Fragment>
                    <View >
                    <View >
                    <Caption> Select start date</Caption>
                      <DatePicker
                        mode='datetime'
                        fadeToColor='red'
                        textColor='#AA0310'
                        locale= 'en-US'
                        date={values.start_date}
                        onDateChange={handleChange('start_date')}
                        style={{ backgroundColor : "#52B8FF", height : 70, width : 400}}
                      />
                      {touched.start_date && errors.start_date &&
                      <Text style={styles.errorInput} >{errors.start_date}</Text>
                      } 
                      </View>
                    
                      <View >  
                      <Caption> Select end date</Caption>
                      <DatePicker
                        mode='datetime'
                        textColor='#ffffff'
                        date={values.end_date}
                        onDateChange={handleChange('end_date')}
                        style={{ backgroundColor : "#FF5D5D", height : 70, width : 400}}
                      />
                         {touched.end_date && errors.end_date &&
                          <Text style={styles.errorInput} >{errors.end_date}</Text>
                        }                    
                      </View>
                    <View style={styles.inputError}>
                      <Text style={styles.errorApi}>{this.props.error}</Text>
                    </View>                          
                    <View>
                      <Button 
                        mode="contained"  
                        disabled={isValid ? false : true}                  
                        onPress={handleSubmit}
                        style={{ marginHorizontal : 30}}
                        loadingProps={{ size: "small", color: "white" }} 
                        theme={{ colors: { text: '#ffffff', primary: '#08D13E',  underlineColor: 'transparent',} }}               
                      > SEARCH MEDIA                 
                      </Button>
                      <Button 
                        mode="contained"                                         
                        onPress={handleReset}
                        style={{ marginHorizontal : 30, marginTop : 10}}                      
                        theme={{ colors: { text: '#ffffff', primary: '#ccc',  underlineColor: 'transparent',} }}               
                      > RESET                
                      </Button>
                    </View>
                    </View>   
                  
                    </Fragment>
                    )}
                    </Formik> 
       </View>
       
        <FlatList
          keyExtractor={item => item.id}         
          data={files.length > 0 ? files : efiles}
          renderItem={({item}) => this.renderMedia(item)}
          onRefresh={this.renderRefresh}
          refreshing={false}
          onEndReached={this.handleLoadMore}
          onMomentumScrollEnd={this.onMomentumScrollEnd}
          onMomentumScrollBegin={this.onMomentumScrollBegin}
          onEndReachedThreshold={50}
        />
      </View>
    );
  }
  renderRefresh = () => {
    console.log("SEARCH REFRESH")
  }
  handleLoadMore =()=>{
    console.log("SEARCH REFRESH REACHED END")
  }
 
renderMedia(item){
    return(
    <View>
       <List.Item
        title={item.id}
        description={item.filename}
        left={props => <List.Icon {...props} icon="photo" />}
        right={props => <Image {...props} source={IMAGE} style={{ width : 50, height : 50}} />}
      />
    </View>
  )
}

}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#F5FCFF"
  }
});

Comments

Popular posts from this blog

KrutiDev To Unicode Conversion

http://wrd.bih.nic.in/font_KtoU.htm ___________________________________ <html> <head> <title>KrutiDev <=> Unicode Conversion</title> </title> <link rel="stylesheet" href="style.css">       <script src='script.js'></script> </head> <!--       body of the HTML starts here. one text box is provided each for input and output. --> <body bgcolor='#99CCFF'> <P style='text-align:center; font-family: Arial, Helvetica, sans-serif; font-size: 14pt; font-weight:bold; background-color: #FF6600; color: #FFFFFF'> Conversion between Krutidev-010 and Unicode क्रुतिदेव-०१० और यूनिकोड के बीच रूपांतरण </P> <form name="form1"> <p style='font-size:10pt'>क्रुतिदेव-०१० (Kruti Dev 010) फॉन्ट में टंकिट टेक्स्ट को "क्रुतिदेव-०१०" नामक टेक्स्ट बॉक्स में टाईप या पेस्ट करें तथा इसे यूनिकोड में रूपांतरित करने के लिए अधोमुख तीर वाल...

Array Difference, Radio Button Js,

$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"); $a2=array("e"=>"red","f"=>"green","g"=>"blue"); $result=array_diff($a1,$a2); print_r($result); ______________________________________________________ <script type="text/javascript">  $(document).ready(function(){       $("input[type='radio']").click(function(){             var radioValue = $("input[name='duration']:checked").val();             if(radioValue){                 alert("Your are a - " + radioValue);             }         });  }); </script>   $(document).on("click", ".upappdesc", function(){ // alert($(this).data('id'));  var option = $(this).data("cat").split(",");  // alert($(this).data(...

Update Node on Mac and Windows

Using brew: brew update brew upgrade node Using nvm:   NVM (Node Version Manager) is a tool that allows you to manage multiple versions of Node on your system. You can use nvm to install, update, and switch between different versions of Node. To update your version of Node using nvm, do the following: 1. Check if you already have nvm installed on your system:   
nvm --version 2. If it's not installed, install nvm using this command:    
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash 3. Once nvm is installed, check your current version of Node by running the following command: 
node -v 4. Then update your version of Node using the following command:   
nvm install node --reinstall-packages-from=node 5. And finally, verify that your update is complete by rechecking your Node version:   
node -v ———————————————————————————————————— Using NPM: To update Node using NPM, do the following: 1. Open the Terminal and check your curren...