Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions app/containers/UIKit/DatePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { StyleSheet, Text, unstable_batchedUpdates, View } from 'react-native';
import DateTimePicker, { Event } from '@react-native-community/datetimepicker';
import Touchable from 'react-native-platform-touchable';
import { BlockContext } from '@rocket.chat/ui-kit';
Expand Down Expand Up @@ -48,11 +48,15 @@ export const DatePicker = ({ element, language, action, context, loading, value,
// timestamp as number exists in Event
// @ts-ignore
const onChange = ({ nativeEvent: { timestamp } }: Event, date?: Date) => {
const newDate = date || new Date(timestamp);
onChangeDate(newDate);
action({ value: moment(newDate).format('YYYY-MM-DD') });
if (isAndroid) {
onShow(false);
if (date || timestamp) {
const newDate = date || new Date(timestamp);
unstable_batchedUpdates(() => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this unstable_batchedUpdates to avoid double re-render of the calendar when using Android

onChangeDate(newDate);
if (isAndroid) {
onShow(false);
}
});
action({ value: moment(newDate).format('YYYY-MM-DD') });
}
};

Expand Down Expand Up @@ -85,7 +89,13 @@ export const DatePicker = ({ element, language, action, context, loading, value,
}

const content = show ? (
<DateTimePicker mode='date' display='default' value={currentDate} onChange={onChange} textColor={themes[theme].titleText} />
<DateTimePicker
mode='date'
display={isAndroid ? 'default' : 'inline'}
value={currentDate}
onChange={onChange}
textColor={themes[theme].titleText}
/>
) : null;

return (
Expand Down