简体   繁体   English

如何使用模态日期时间选择器显示日历

[英]How to display the calendar using modal datetime picker

I am using the react-native-modal-datetime-picker library and I am trying to use the display prop to display the calendar.我正在使用react-native-modal-datetime-picker库,我正在尝试使用 display 道具来显示日历。 If you look at my reproducible example found on snack expo here , you can see the issue I am having.如果您在此处查看我在零食 expo上找到的可重现示例,您可以看到我遇到的问题。 I have also posted the code below.我还在下面发布了代码。

The issue I am having is that when you hit 'Show Data Picker', you can see it renders this bottom modal with the current date.我遇到的问题是,当您点击“显示数据选择器”时,您可以看到它使用当前日期呈现了这个底部模态。 If you press the date, the calendar renders.如果您按下日期,日历就会呈现。 How can I skip the first bottom modal that gets rendered?如何跳过第一个呈现的底部模态? I just want to go straight to the calendar.我只想go直挂日历。

import React, { useState } from "react";
import { Button, View } from "react-native";
import DateTimePickerModal from "react-native-modal-datetime-picker";

const Example = () => {
  const [isDatePickerVisible, setDatePickerVisibility] = useState(false);

  const showDatePicker = () => {
    setDatePickerVisibility(true);
  };

  const hideDatePicker = () => {
    setDatePickerVisibility(false);
  };

  const handleConfirm = (date) => {
    console.warn("A date has been picked: ", date);
    hideDatePicker();
  };

  return (
    <View style={{justifyContent: 'center', alignItems: 'center', flex: 1, backgroundColor: 'pink'}}>
      <Button title="Show Date Picker" onPress={showDatePicker} />
      <DateTimePickerModal
        isVisible={isDatePickerVisible}
        mode="date"
        onConfirm={handleConfirm}
        onCancel={hideDatePicker}
        display={"default"}
      />
    </View>
  );
};

export default Example;

The calendar I want, but without the bottom modal that renders, I want just the calendar.我想要的日历,但没有呈现的底部模式,我只想要日历。 在此处输入图像描述

set display prop to inline instead of calendardisplay道具设置为inline而不是calendar

display={"inline"}

for more details see the documentation about this: here有关详细信息,请参阅有关此的文档: 此处

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 react-native-community/datetimepicker,如何在 Android 上显示日期时间选择器? - Using react-native-community/datetimepicker, How Can I Display a DateTime Picker on Android? 反应本机模态日期时间选择器不起作用 - React native modal datetime picker not working 在终端中使用“npm install react-native-modal-datetime-picker”时出错 - getting an error when using `npm install react-native-modal-datetime-picker` in terminal 如何将 react-native-datetime-modal-picker 与输入一起使用? - how can I use the react-native-datetime-modal-picker with input? 日期范围在react-native-modal-datetime-picker? - Date ranges on react-native-modal-datetime-picker? “react-native-modal-datetime-picker”年列表不滚动 - "react-native-modal-datetime-picker" years list is not scrolling react-native-modal-datetime-picker 上的 minuteInterval 道具不起作用 - minuteInterval prop on react-native-modal-datetime-picker not working 更改 react-native-modal-datetime-picker 上的分钟增量 - Change minute increment on react-native-modal-datetime-picker React 本机模态日期时间选择器在打开时不显示 - React native modal datetime picker not showing up when opened 来自“react-native-modal-datetime-picker”的 React Native DateTimePickerModal 不允许我在一个组件中添加 2 个 DateTime 选择器 - React Native DateTimePickerModal from "react-native-modal-datetime-picker" Not letting me add 2 DateTime picker in one component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM