Tuesday, 21 January 2020

NativeBase DatePicker

import React, { Component } from 'react';
import { Image } from 'react-native';
import {
  Container, Header, Title, Content, Footer,
  FooterTab, Button, Left, Right, Body, Icon, Text,
  Accordion, Card, CardItem, Thumbnail, ListItem,
  CheckBox, DatePicker,
} from 'native-base';

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      chosenDate: new Date()
    };
  }

  setDate = (date) => {
    this.setState({ chosenDate: date })
  }

  render() {
    return (
      <Container>
        <Header>
          <Body>
            <Title>Date Picker</Title>
          </Body>
        </Header>
        <Content>
          <DatePicker
            defaultDate={new Date(2018, 4, 4)}
            minimumDate={new Date(2018, 1, 1)}
            maximumDate={new Date(2018, 12, 31)}
            locale={"en"}
            timeZoneOffsetInMinutes={undefined}
            modalTransparent={false}
            animationType={"fade"}
            androidMode={"default"}
            placeHolderText="Select date"
            textStyle={{ color: "green" }}
            placeHolderTextStyle={{ color: "#d3d3d3" }}
            onDateChange={(e) => this.setDate(e)}
            disabled={false}
          />
          <Text>
            Date: {this.state.chosenDate.toString().substr(4, 12)}
          </Text>
        </Content>
      </Container>
    );
  }
}

No comments:

Post a Comment