简体   繁体   English

如何向 react-native-calendars 中的 Agenda 组件添加功能

[英]How to add functionality to the Agenda component in react-native-calendars

I am building a simple to do list and calendar/agenda to teach myself javascript and react native.我正在构建一个简单的待办事项列表和日历/议程来自学 javascript 并做出本机反应。 I found react-native-calendars and I really like how it looks.我找到了 react-native-calendars,我真的很喜欢它的外观。

What my question is, is actually adding an item to the agenda via user input.我的问题是,实际上是通过用户输入将项目添加到议程中。

Please refer to the code below:请参考以下代码:

I created a Button and Modal component for reusability.我创建了一个 Button 和 Modal 组件以实现可重用性。

Here is the calendar component.这是日历组件。 As of right now it shows an empty agenda, a simple + button, with a modal that pops up on click.截至目前,它显示了一个空议程,一个简单的 + 按钮,点击时会弹出一个模式。

import * as React from 'react';
import {View, StyleSheet, Text, TouchableOpacity, Platform} from 'react-native';
import {Agenda} from 'react-native-calendars';
import Ionicons from 'react-native-vector-icons/Ionicons';
import {useEffect, useState} from "react";
import {addDays, format} from 'date-fns';


//Class Imports
import {Button} from "../../components/Button"
import {Modal} from "../../components/Modal"


export default function CalendarView() {


    const [isModalVisible, setIsModalVisible] = React.useState(false);
    const handleModal = () => setIsModalVisible(() => !isModalVisible);

    return (
        <View style={styles.container}>
            <Agenda
                    style={styles.calendarWrapper}
                    scrollEnabled={true}
                    theme={{
                        // calendarBackground: '#000000'
                        todayTextColor: '#00adf5',
                    }}>
            </Agenda>

            <View style={styles.absolute}
                  behavior={Platform.OS === "ios" ? "padding" : "height"}>
                <Button onPress={handleModal}/>
                <Modal isVisible={isModalVisible}>
                    <Modal.Container>
                        <Modal.Header title="Placeholder"/>
                        <Modal.Body>
                            <Text style={styles.text}>Placeholder Text</Text>
                        </Modal.Body>
                        <Modal.Footer>
                            <Button onPress={handleModal}/>
                        </Modal.Footer>
                    </Modal.Container>
                </Modal>
            </View>
        </View>
    )
}

const styles = StyleSheet.create({
    absolute: {
      position: 'absolute',
        bottom: 80,
        right: 20
    },
    container: {
        position: 'static',
        flex: 1,
        backgroundColor: '#E8EAED',
    },
    calendarWrapper: {},
    items: {},
    dayPressColor: {
        backgroundColor: '#000000'
    },
    itemContainer: {
        backgroundColor: 'white',
        margin: 5,
        borderRadius: 15,
        justifyContent: 'center',
        alignItems: 'center',
        flex: 1,
    },
    text: {
        fontSize: 16,
        fontWeight: "400",
        textAlign: "center",
    },

})

My goal is to use this modal to enter in information about the event (let's say time, date, title), click "Add", and have that information added into the agenda.我的目标是使用此模式输入有关事件的信息(比如时间、日期、标题),单击“添加”,并将该信息添加到议程中。

Any help would be appreciated.任何帮助,将不胜感激。 Thank you.谢谢你。

Also, if you need more information please let me know, I will provide anything I can.另外,如果您需要更多信息,请告诉我,我会尽我所能提供。

import React, {useState} from 'react';
import {Agenda} from 'react-native-calendars';

// States
const [events, setEvents] = useState({});
const [marksDate, setMarksDate] = useState({});
const [refreshCalender, setRefreshCalender] = useState(false);

// On Add Function
const onAddEventSubmit = () => {
    setRefreshCalender(true);
    let items = events;
    let mark = {};
    let eventDetails = {
        date: "2022-02-23", // Modal Value
        title: "Your Event Title" // Modal Value
    }

    if (!items[eventDetails.date]) {
        items[eventDetails.date] = [];
    }

    items[eventDetails.date].push(eventDetails);


    mark[eventDetails.date] = {
        customStyles: {
          container: {
            backgroundColor: '#0f0',
          },
          text: {
            color: 'white',
            fontWeight: 'bold',
          },
        },
    };

    setEvents(items);
    setMarksDate(mark);
    setRefreshCalender(false);
}



<Agenda
    items={events}
    loadItemsForMonth={loadItems} // Function
    refreshing={refreshCalender}
    renderItem={(item) => {
        return (
            <View>
                <Text>{item.title}</Text>
            </view>
        )
    }}
    markingType={'custom'}
    markedDates={marksDate}
    // ..other props
/>

暂无
暂无

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

相关问题 react-native-calendars ExpandableCalendar 在本机反应中不能与 RTL 一起正常工作 - react-native-calendars ExpandableCalendar not worknig propely with RTL in react native 如何动态更改 react-native-calendars 的 items 道具中日期键的日期 - How to dynamically change the date for the date key in the items prop for react-native-calendars react-native-calendars npm 模块的 CalendarList 组件中的日历天在正常模式下似乎被禁用/变灰,但在调试模式下工作正常 - Calendar days in CalendarList component of react-native-calendars npm module seems disabled/grayed out in normal mode but works fine in debug mode React-native-Agenda 如何将新项目添加到议程中 - React-native-Agenda how to add a new item to the Agenda 需要帮助弄清楚我的数据操作/道具传递 React-Native/react-native-calendars - Need help figuring out my data manipulation/prop passing React-Native/react-native-calendars 如何将 HTML 和 JS 功能添加到 React 组件? - How to add HTML and JS functionality to a React component? React-Native-如何替换React-Native核心组件的功能 - React-Native - How to replace functionality of a react-native core component 如何在此计时器中添加暂停功能? 反应母语 - How can i add a pause functionality in this timer ? React-Native ReactJS:如何在我的应用程序中默认向任何 React 组件添加功能 - ReactJS: how to add a functionality to any React Component by default in my app 如何在反应本机日历中设置多个选定的日期颜色? - How to set multiple selected date colors in react native calendars?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM