Skip to content

Commit

Permalink
feat: remove defaultProps
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `defaultProps` are not supported anymore.
  • Loading branch information
ruamess authored Aug 22, 2024
1 parent 56cc719 commit 3e2f3fc
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/DateTimePickerModal.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@ import DateTimePicker from "@react-native-community/datetimepicker";
const areEqual = (prevProps, nextProps) => {
return (
prevProps.isVisible === nextProps.isVisible &&
prevProps.date.getTime() === nextProps.date.getTime()
(prevProps.date?.getTime() === nextProps.date?.getTime())
);
};

const DateTimePickerModal = memo(
({ date, mode, isVisible, onCancel, onConfirm, onHide, ...otherProps }) => {
({
date = new Date(),
mode = 'date',
isVisible = false,
onCancel,
onConfirm,
onHide = () => { },
...otherProps
}) => {
const currentDateRef = useRef(date);
const [currentMode, setCurrentMode] = useState(null);

useEffect(() => {
if (isVisible && currentMode === null) {
setCurrentMode(mode === "time" ? "time" : "date");
setCurrentMode(mode === 'time' ? 'time' : 'date');
} else if (!isVisible) {
setCurrentMode(null);
}
Expand All @@ -26,18 +34,18 @@ const DateTimePickerModal = memo(
if (!isVisible || !currentMode) return null;

const handleChange = (event, date) => {
if (event.type === "dismissed") {
if (event.type === 'dismissed') {
onCancel();
onHide(false);
return;
}
let nextDate = date;
if (mode === "datetime") {
if (currentMode === "date") {
setCurrentMode("time");
if (mode === 'datetime') {
if (currentMode === 'date') {
setCurrentMode('time');
currentDateRef.current = new Date(date);
return;
} else if (currentMode === "time") {
} else if (currentMode === 'time') {
const year = currentDateRef.current.getFullYear();
const month = currentDateRef.current.getMonth();
const day = currentDateRef.current.getDate();
Expand All @@ -62,6 +70,8 @@ const DateTimePickerModal = memo(
areEqual
);

export default DateTimePickerModal;

DateTimePickerModal.propTypes = {
date: PropTypes.instanceOf(Date),
isVisible: PropTypes.bool,
Expand All @@ -72,10 +82,4 @@ DateTimePickerModal.propTypes = {
minimumDate: PropTypes.instanceOf(Date),
};

DateTimePickerModal.defaultProps = {
date: new Date(),
isVisible: false,
onHide: () => {},
};

export { DateTimePickerModal };
export { DateTimePickerModal };

0 comments on commit 3e2f3fc

Please sign in to comment.