import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import DatePicker from 'react-native-date-picker';
import DeviceInfo from 'react-native-device-info';
import DateChange from '../propPickers/DateChange';
import FadeToColor from '../propPickers/FadeToColor';
import LocalePicker from '../propPickers/LocalePicker';
import MinMaxDateChange from '../propPickers/MinMaxDateChange';
import ModePicker from '../propPickers/ModePicker';
import TextColor from '../propPickers/TextColor';
import TimeZoneOffsetInMinutes from '../propPickers/TimeZoneOffsetInMinutes';
import PropSlider from '../PropSlider';
import MinuteInterval from '../propPickers/MinuteInterval';
Date.prototype.addHours = function (h) {
this.setTime(this.getTime() + (h * 60 * 60 * 1000));
return this;
}
export const defaultMinDate = new Date().addHours(-24 * 5);
export const defaultMaxDate = new Date().addHours(24 * 5);
export const readableDate = date => date ? date.toISOString().substr(0, 19).replace('T', ' ') : 'undefined'
export default class Advanced extends Component {
state = {
chosenDate: new Date(),
searchTerm: '',
textColor: '#000000',
selectedProp: 'mode',
locale: DeviceInfo.getDeviceLocale(),
mode: 'datetime',
minDate: defaultMinDate,
maxDate: defaultMaxDate,
timeZoneOffsetInMinutes: undefined,
minuteInterval: 1,
}
render() {
return (
Picker date: {readableDate(this.state.chosenDate)}
Change prop:
Prop value:
{this.selectedPropData().component}
)
}
propertyList = () => [
{
name: 'mode', component:
this.setState({ mode })} />
},
{
name: 'locale', component:
this.setState({ locale })} />
},
{
name: 'timeZoneOffset', component:
this.setState({ timeZoneOffsetInMinutes })} />
},
{
name: 'date', component:
this.setState({ chosenDate })} />
},
{
name: 'minuteInterval', component:
this.setState({ minuteInterval })} />
},
{
name: 'minDate', component:
this.setState({ minDate })}
defaultDate={defaultMinDate}
/>
},
{
name: 'maxDate', component:
this.setState({ maxDate })}
defaultDate={defaultMaxDate} />
},
{
name: 'fadeToColor', component:
this.props.setBackground(randomColor())} />
},
{
name: 'textColor', component:
this.setState({ textColor: randomColor() })} />
},
]
selectedPropData = () => this.propertyList().find(p => p.name === this.state.selectedProp)
onSelect = selectedProp => this.setState({ selectedProp })
setDate = newDate => this.setState({ chosenDate: newDate })
}
const styles = StyleSheet.create({
container: {
alignItems: 'center',
justifyContent: 'center',
marginTop: 15,
backgroundColor: 'transparent',
flex: 1,
},
item: {
borderWidth: 1,
marginTop: -1,
borderColor: 'rgba(0,0,0,1)',
padding: 3,
width: 100,
alignItems: 'center',
},
})
const randomColor = () => '#' + pad(Math.floor(Math.random() * 16777215).toString(16), 6);
function pad(n, width) {
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n;
}