Skip to content

Instantly share code, notes, and snippets.

@fotoflo
Created February 25, 2019 04:39
Show Gist options
  • Save fotoflo/39572c6759c3bc5b344b9b6964fa2224 to your computer and use it in GitHub Desktop.
Save fotoflo/39572c6759c3bc5b344b9b6964fa2224 to your computer and use it in GitHub Desktop.
import React from 'react';
import { connect } from 'react-redux'
import moment from 'moment'
import {
Container, Content, Text, Button, DatePicker, Title
} from 'native-base';
class Example extends React.Component {
constructor(props) {
super(props);
this.state = { chosenDate: new Date() };
}
setDate(newDate) {
this.setState({ chosenDate: newDate });
}
render() {
let [ count, intervals] = moment(this.state.chosenDate).fromNow(true).split(" ");
intervals = intervals.charAt(0).toUpperCase() + intervals.slice(1);;
return (
<Container>
<Content>
<Title>Title</Title>
{
intervals == "Years" || intervals == "Months" ? (
<Content>
<Text>it's been</Text>
<Button transparent onPress={this.DatePicker.showDatePicker}>
<Title>{count}</Title>
</Button>
<Text>{intervals}</Text>
</Content>
) : (
<Content>
<Text>When was it?</Text>
<DatePicker
ref={ref => this.DatePicker = ref}
defaultDate={new Date(2018, 4, 4)}
minimumDate={new Date(1960, 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={(newDate) => this.setDate(newDate)}
disabled={false}
modalVis
/>
<Text>
Date: {this.state.chosenDate.toString().substr(4, 12)}
</Text>
</Content>
)
}
<Button
onPress={() => this.navigateToNext()}>
<Text>Next</Text>
</Button>
</Content>
</Container>
);
}
}
const mapStateToProps = (state) => {
return { };
}
const mapDispatchToProps = (dispatch) => {
return {}
}
export default
connect(mapStateToProps, mapDispatchToProps)(Example)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment