Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-calendar-timetable

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-calendar-timetable

Timetable (schedule) component for React Native applications

  • 1.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

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

Keywords

FAQs

Package last updated on 12 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc