Commit 79e92a53 authored by Collin Jackson's avatar Collin Jackson

Add haptic feedback to date picker

parent 4cd223a7
......@@ -4,6 +4,7 @@
import 'dart:async';
import 'package:sky/mojo/activity.dart';
import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/theme/typography.dart' as typography;
import 'package:sky/widgets.dart';
......@@ -43,12 +44,14 @@ class DatePicker extends StatefulComponent {
DatePickerMode _mode = DatePickerMode.day;
void _handleModeChanged(DatePickerMode mode) {
userFeedback.performHapticFeedback(HapticFeedbackType_VIRTUAL_KEY);
setState(() {
_mode = mode;
});
}
void _handleYearChanged(DateTime dateTime) {
userFeedback.performHapticFeedback(HapticFeedbackType_VIRTUAL_KEY);
setState(() {
_mode = DatePickerMode.day;
});
......@@ -56,6 +59,12 @@ class DatePicker extends StatefulComponent {
onChanged(dateTime);
}
void _handleDayChanged(DateTime dateTime) {
userFeedback.performHapticFeedback(HapticFeedbackType_VIRTUAL_KEY);
if (onChanged != null)
onChanged(dateTime);
}
static const double _calendarHeight = 210.0;
Widget build() {
......@@ -69,7 +78,7 @@ class DatePicker extends StatefulComponent {
case DatePickerMode.day:
picker = new MonthPicker(
selectedDate: selectedDate,
onChanged: onChanged,
onChanged: _handleDayChanged,
firstDate: firstDate,
lastDate: lastDate,
itemExtent: _calendarHeight
......@@ -167,6 +176,7 @@ class DayPicker extends Component {
}) {
assert(selectedDate != null);
assert(currentDate != null);
assert(onChanged != null);
assert(displayedMonth != null);
}
......@@ -239,7 +249,6 @@ class DayPicker extends Component {
item = new Listener(
onGestureTap: (_) {
DateTime result = new DateTime(year, month, day);
if (onChanged != null)
onChanged(result);
},
child: new Container(
......@@ -277,6 +286,7 @@ class MonthPicker extends ScrollableWidgetList {
double itemExtent
}) : super(itemExtent: itemExtent) {
assert(selectedDate != null);
assert(onChanged != null);
assert(lastDate.isAfter(firstDate));
}
......@@ -354,6 +364,7 @@ class YearPicker extends ScrollableWidgetList {
this.lastDate
}) : super(itemExtent: 50.0) {
assert(selectedDate != null);
assert(onChanged != null);
assert(lastDate.isAfter(firstDate));
}
DateTime selectedDate;
......@@ -381,7 +392,6 @@ class YearPicker extends ScrollableWidgetList {
key: new Key(label),
onGestureTap: (_) {
DateTime result = new DateTime(year, selectedDate.month, selectedDate.day);
if (onChanged != null)
onChanged(result);
},
child: new InkWell(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment