From 57b7388cb7124f65c1cb4b6e02c8c6edc111dca1 Mon Sep 17 00:00:00 2001 From: Aksels Ledins Date: Mon, 14 Jan 2019 22:11:43 +0100 Subject: [PATCH] (c) RouteSearchForm : we can now change date/hour on android devices --- src/components/RouteSearchForm/index.js | 90 +++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 7 deletions(-) diff --git a/src/components/RouteSearchForm/index.js b/src/components/RouteSearchForm/index.js index e9b2471..acdbf26 100644 --- a/src/components/RouteSearchForm/index.js +++ b/src/components/RouteSearchForm/index.js @@ -5,7 +5,17 @@ import { bindActionCreators } from 'redux'; import moment from 'moment'; -import { View, Button, StyleSheet, Text, DatePickerIOS, TouchableOpacity } from 'react-native'; +import { + Platform, + View, + Button, + StyleSheet, + Text, + DatePickerIOS, + DatePickerAndroid, + TouchableOpacity, + TimePickerAndroid, +} from 'react-native'; import { LinearGradient, Constants, Location, Permissions } from 'expo'; import { Ionicons, MaterialIcons } from '@expo/vector-icons'; @@ -15,8 +25,6 @@ import { white, black, blue, red } from '@/utils/colors'; import NavigationService from '@/services/Navigation'; -import SearchLocation from '../SearchLocation'; - class RouteSearchForm extends Component { state = { dateOptionsOpened: false, @@ -60,6 +68,43 @@ class RouteSearchForm extends Component { }); }; + changeDateOnAndroid = async () => { + const { date } = this.props.searchParameters; + + const { action, year, month, day } = await DatePickerAndroid.open({ + date: new Date(date), + }); + + if (action === DatePickerAndroid.dismissedAction) return; + const newDate = moment(date); + newDate.set({ + year, + month, + date: day, + }); + + this.setDate(newDate.toISOString()); + }; + changeHourOnAndroid = async () => { + const { date } = this.props.searchParameters; + const momentDate = moment(date); + + const { action, hour, minute } = await TimePickerAndroid.open({ + hour: momentDate.get('hour'), + minute: momentDate.get('minutes'), + is24Hour: true, + }); + + if (action === TimePickerAndroid.dismissedAction) return; + + const newDate = moment(date); + newDate.set({ + hour, + minute, + }); + this.setDate(newDate.toISOString()); + }; + reverseFromTo = () => { const { fromText, toText } = this.props.formValues; const { from, to } = this.props.searchParameters; @@ -164,7 +209,7 @@ class RouteSearchForm extends Component { style={{ display: 'flex', flexDirection: 'row', - justifyContent: 'center', + justifyContent: 'space-evenly', alignItems: 'center', }}>