Skip to content

Commit

Permalink
(c) RouteSearchForm : we can now change date/hour on android devices
Browse files Browse the repository at this point in the history
  • Loading branch information
AkselsLedins committed Jan 14, 2019
1 parent d102658 commit 57b7388
Showing 1 changed file with 83 additions and 7 deletions.
90 changes: 83 additions & 7 deletions src/components/RouteSearchForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -164,7 +209,7 @@ class RouteSearchForm extends Component {
style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
justifyContent: 'space-evenly',
alignItems: 'center',
}}>
<Button
Expand All @@ -176,21 +221,52 @@ class RouteSearchForm extends Component {
<View style={{ display: 'flex', flexDirection: 'row' }}>
<TouchableOpacity onPress={this.setArriveBy(false)}>
<LinearGradient
colors={arriveBy ? [] : ['#5f6fee', '#5f8eee']}
colors={arriveBy ? ['#FFF', '#FFF'] : ['#5f6fee', '#5f8eee']}
style={{ padding: 15, alignItems: 'center', borderRadius: 5 }}>
<Text style={{ color: arriveBy ? black : white }}>Partir à</Text>
</LinearGradient>
</TouchableOpacity>
<TouchableOpacity onPress={this.setArriveBy(true)}>
<LinearGradient
colors={arriveBy ? ['#5f6fee', '#5f8eee'] : []}
colors={arriveBy ? ['#5f6fee', '#5f8eee'] : ['#FFF', '#FFF']}
style={{ padding: 15, alignItems: 'center', borderRadius: 5 }}>
<Text style={{ color: arriveBy ? white : black }}>Arriver à</Text>
</LinearGradient>
</TouchableOpacity>
</View>
</View>
<DatePickerIOS date={date} onDateChange={this.setDate} />
{Platform.OS === 'ios' && <DatePickerIOS date={date} onDateChange={this.setDate} />}
{Platform.OS === 'android' && (
<View
style={{
padding: 16,
display: 'flex',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
alignContent: 'center',
}}>
<TouchableOpacity onPress={this.changeDateOnAndroid}>
<LinearGradient
colors={['#5f6fee', '#5f8eee']}
style={{ padding: 8, borderRadius: 5 }}>
<Text style={{ textAlign: 'center', color: 'white' }}>
{moment(date).format('DD/MM/YYYY')}
</Text>
</LinearGradient>
</TouchableOpacity>
<Text style={{ textAlign: 'center' }}> à </Text>
<TouchableOpacity onPress={this.changeHourOnAndroid}>
<LinearGradient
colors={['#5f6fee', '#5f8eee']}
style={{ padding: 8, borderRadius: 5 }}>
<Text style={{ textAlign: 'center', color: 'white' }}>
{moment(date).format('HH:mm')}
</Text>
</LinearGradient>
</TouchableOpacity>
</View>
)}
</View>
)}
</View>
Expand Down

0 comments on commit 57b7388

Please sign in to comment.