[FIX] UiKit/DatePicker is broken (#4607)
* [FIX] UiKit/DatePicker is broken * minor tweak
This commit is contained in:
parent
d99bcf9c92
commit
736e409b8b
|
@ -1,5 +1,5 @@
|
||||||
import React, { useState } from 'react';
|
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 DateTimePicker, { Event } from '@react-native-community/datetimepicker';
|
||||||
import Touchable from 'react-native-platform-touchable';
|
import Touchable from 'react-native-platform-touchable';
|
||||||
import { BlockContext } from '@rocket.chat/ui-kit';
|
import { BlockContext } from '@rocket.chat/ui-kit';
|
||||||
|
@ -48,12 +48,16 @@ export const DatePicker = ({ element, language, action, context, loading, value,
|
||||||
// timestamp as number exists in Event
|
// timestamp as number exists in Event
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const onChange = ({ nativeEvent: { timestamp } }: Event, date?: Date) => {
|
const onChange = ({ nativeEvent: { timestamp } }: Event, date?: Date) => {
|
||||||
|
if (date || timestamp) {
|
||||||
const newDate = date || new Date(timestamp);
|
const newDate = date || new Date(timestamp);
|
||||||
|
unstable_batchedUpdates(() => {
|
||||||
onChangeDate(newDate);
|
onChangeDate(newDate);
|
||||||
action({ value: moment(newDate).format('YYYY-MM-DD') });
|
|
||||||
if (isAndroid) {
|
if (isAndroid) {
|
||||||
onShow(false);
|
onShow(false);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
action({ value: moment(newDate).format('YYYY-MM-DD') });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let button = placeholder ? <Button title={textParser([placeholder])} onPress={() => onShow(!show)} loading={loading} /> : null;
|
let button = placeholder ? <Button title={textParser([placeholder])} onPress={() => onShow(!show)} loading={loading} /> : null;
|
||||||
|
@ -85,7 +89,13 @@ export const DatePicker = ({ element, language, action, context, loading, value,
|
||||||
}
|
}
|
||||||
|
|
||||||
const content = show ? (
|
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;
|
) : null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in New Issue