1.0.6 • Published 1 year ago

react-native-calendar-timetable v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

react-native-calendar-timetable

Timetable (schedule) component for React Native applications

1 2

Installation

npm install react-native-calendar-timetable
yarn add react-native-calendar-timetable
expo install react-native-calendar-timetable

Usage

Initialization example

import React from "react";
import moment from "moment";
import Timetable from "react-native-calendar-timetable";

export default function App() {
    /**
     * By default Timetable renders one column.
     * This sets date for that column, by default equals to new Date().
     * Can be instance of Date or an ISO string.
     * Essentially, a shortcut for range {from: date, till: date}.
     */
    const [date] = React.useState(new Date());

    /**
     * If you would like to have multiple columns (e.g. from Monday to Sunday),
     * you can specify range of dates. Each day of said range will have its own column.
     *
     * 'from' and 'till', just like 'date', can be instances of Date or an ISO strings.
     *
     * It is safe to keep 'from' and 'till' in separate states if you need to
     * because Timetable only check if 'from' or 'till' had changed and
     * not the object that contains them.
     */
    const [from] = React.useState(moment().subtract(3, 'days').toDate());
    const [till] = React.useState(moment().add(3, 'days').toISOString());
    const range = {from, till};

    const [items] = React.useState([
        {
            title: 'Some event',
            startDate: moment().subtract(1, 'hour').toDate(),
            endDate: moment().add(1, 'hour').toDate(),
        },
    ]);

    return (
        <ScrollView>
            <Timetable
                // these two are required
                items={items}
                renderItem={props => <YourComponent {...props}/>}

                // provide only one of these
                date={date}
                range={range}
            />
        </ScrollView>
    );
}

YourComponent example

/**
 * Example item component
 * @param style Object with pre-calculated values, looks like {position: 'absolute', zIndex: 3, width: Number, height: Number, top: Number, left: Number}
 * @param item One of items supplied to Timetable through 'items' property
 * @param dayIndex For multiday items inicates current day index
 * @param daysTotal For multiday items indicates total amount of days
 */
export default function YourComponent({style, item, dayIndex, daysTotal}) {
    return (
        <View style={{
            ...style, // apply calculated styles, be careful not to override these accidentally (unless you know what you are doing)
            backgroundColor: 'red',
            borderRadius: 10,
            elevation: 5,
        }}>
            <Text>{item.title}</Text>
            <Text>{dayIndex} of {daysTotal}</Text>
        </View>
    );
}

Customization

Styles

All of these keys must be defined on style prop, e.g. style.container.

:warning: Please be careful while customizing styles as some properties may override those calculated by Timetable, such as width and height of style.headerContainer. They were not ignored to allow customization in some extreme edge cases. Refer to Layout segment for layout customization.

KeyStyle typeDescription
containerViewStyles of the main container
headerContainerViewStyles of the container of column's header
headerTextTextStyles of the Text of column's header
headersContainerViewStyles of the View that wraps all header containers
contentContainerViewStyles of the container of lines and cards
timeContainerViewStyles of time containers
timeTextStyles of time text
linesViewStyles of Views that render lines
nowLine.dotView*Styles of the circle of the 'current time' line
nowLine.lineView**Styles of the line of the 'current time' line

*, ** due to how these Views are used, their customization options were limited:

*: width, height, backgroundColor, borderRadius, zIndex, elevation

**: height, backgroundColor, zIndex, elevation

Layout

KeyTypeDefaultDescription
widthNumberuseWindowDimensions().widthWidth of whole component
timeWidthNumber50Width of time containers
hourHeightNumber60Height of hour row
itemMinHeightInMinutesNumber25Item min height in minutes
columnWidthNumberwidth - (timeWidth - linesLeftInset)Width of day columns
columnHeaderHeightNumberhourHeight / 2Height of the container of column's header
linesTopOffsetNumber18How far the lines are from top border
linesLeftInsetNumber15How far the lines are moved left from time's right border
columnHorizontalPaddingNumber10Space between column borders and column cards

Misc

KeyTypeDefaultDescription
hideNowLineBooleanundefinedHiding line, example if you don't want to show line on other days
enableSnappingBooleanundefinedEnables snapping to columns on scroll
scrollViewPropsObjectProps for horizontal ScrollView
renderHeaderFunction, BooleanDetermines if headers should be rendered and how. By default headers are hidden if there's one column and shown otherwise. Pass false to hide headers or pass function that renders column header text ({date, start, end}) => {} where start and end are start and end of the day (column)
renderHourFunctionFunction that renders time component for a given hour
startPropertyString'startDate'Name of the property that has item's start date
endPropertyString'endDate'Name of the property that has item's end date
fromHourNumber0First hour of the timetable
toHourNumber24Last hour of the timetable
is12HourBooleanOption to set time to 12h mode

License

MIT

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

0.9.0

1 year ago

0.9.2

1 year ago

0.9.1

1 year ago

0.4.8

1 year ago

0.4.7

1 year ago

0.4.6

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago