Git Product home page Git Product logo

react-native-timetable's Introduction

react-native-timetable

timetable library for React Native

demo-3

Real world example

real-world-example

Download at App Store, Get it On Play Store

INSTALLATION

npm install react-native-timetable

No need to link just install it.

Example

import React, { Component } from 'react';
import {
  SafeAreaView,
  StyleSheet,
  View,
  Alert,
} from 'react-native';
import TimeTableView, { genTimeBlock } from 'react-native-timetable';
const events_data = [
  {
    title: "Math",
    startTime: genTimeBlock("MON", 9),
    endTime: genTimeBlock("MON", 10, 50),
    location: "Classroom 403",
    extra_descriptions: ["Kim", "Lee"],
  },
  {
    title: "Math",
    startTime: genTimeBlock("WED", 9),
    endTime: genTimeBlock("WED", 10, 50),
    location: "Classroom 403",
    extra_descriptions: ["Kim", "Lee"],
  },
  {
    title: "Physics",
    startTime: genTimeBlock("MON", 11),
    endTime: genTimeBlock("MON", 11, 50),
    location: "Lab 404",
    extra_descriptions: ["Einstein"],
  },
  {
    title: "Physics",
    startTime: genTimeBlock("WED", 11),
    endTime: genTimeBlock("WED", 11, 50),
    location: "Lab 404",
    extra_descriptions: ["Einstein"],
  },
  {
    title: "Mandarin",
    startTime: genTimeBlock("TUE", 9),
    endTime: genTimeBlock("TUE", 10, 50),
    location: "Language Center",
    extra_descriptions: ["Chen"],
  },
  {
    title: "Japanese",
    startTime: genTimeBlock("FRI", 9),
    endTime: genTimeBlock("FRI", 10, 50),
    location: "Language Center",
    extra_descriptions: ["Nakamura"],
  },
  {
    title: "Club Activity",
    startTime: genTimeBlock("THU", 9),
    endTime: genTimeBlock("THU", 10, 50),
    location: "Activity Center",
  },
  {
    title: "Club Activity",
    startTime: genTimeBlock("FRI", 13, 30),
    endTime: genTimeBlock("FRI", 14, 50),
    location: "Activity Center",
  },
];

export default class App extends Component {
  constructor(props) {
    super(props);
    this.numOfDays = 5;
    this.pivotDate = genTimeBlock('mon');
  }

  scrollViewRef = (ref) => {
    this.timetableRef = ref;
  };

  onEventPress = (evt) => {
    Alert.alert("onEventPress", JSON.stringify(evt));
  };

  render() {
    return (
      <SafeAreaView style={{flex: 1}}>
        <View style={styles.container}>
          <TimeTableView
            scrollViewRef={this.scrollViewRef}
            events={events_data}
            pivotTime={9}
            pivotEndTime={20}
            pivotDate={this.pivotDate}
            nDays={this.numOfDays}
            onEventPress={this.onEventPress}
            headerStyle={styles.headerStyle}
            formatDateHeader="dddd"
            locale="ko"
          />
        </View>
      </SafeAreaView>
    );
  }
};

const styles = StyleSheet.create({
  headerStyle: {
    backgroundColor: '#81E1B8'
  },
  container: {
    flex: 1,
    backgroundColor: '#F8F8F8',
  },
});

TimeTableView Props

  • scrollViewRef (Function(ref)) function that takes timetableView's ref as parameter
  • events (array of event)
  • nDays (Number) it must be one of 3, 5, 6, 7
  • pivotTime (Number default: 8) it tells what time to start timetable view
  • pivotEndTime (Number default: 22) it tells what time to end timetable view
  • pivotDate (Date, default monday, return value of genTimeBlock)
  • onEventPress (function(event) callBackFunction that triggered when event is pressed
  • headerStyle (object) style for header
  • formatDateHeader (string default "dddd") dddd -> Monday, ddd -> Mon checkout more details
  • locale (string) country code

scrollViewRef

Type: Function

function that takes timetableView's ref as parameter

Usage:

<TimeTableView 
  scrollViewRef={(ref) => {
    this.timetableRef = ref;
  }}
/>

events

Type: array of event

event

Type: Object

  • title: String
  • startTime: Date (result of genTimeBlock)
  • endTime: Date (result of genTimeBlock)
  • location: String
  • extra_descriptions: Array Of String

e.g.)

{
    title: String,
    startTime: Date, // I surely recommend to make Date using genTimeBlock function
    endTime: Date,
    location: String,
    extra_descriptions: Array Of String,
}

headerStyle

Type: object

e.g.)

headerStyle: {
  backgroundColor: '#81E1B8'
}

locale

Type: string (e.g. en-US)

Check the locale options from momentjs.

Helper Functions

  • genTimeBlock (function(String, Number, Number)) returns Date

genTimeBlock

Type: Function

params

  • dayOfWeek (String, One of "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT")
  • hours (Number, default 0)
  • minutes (Number, default 0)

Inspirations

https://github.com/hoangnm/react-native-week-view

react-native-timetable's People

Contributors

dependabot[bot] avatar gomjellie avatar melindley avatar rubycho avatar sancodes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

react-native-timetable's Issues

Add test codes & linting

To increase reliability.

  • Add testing library
  • Add linting library
  • ...Test Items, TBD
  • ...Lint Violations, TBD
  • Apply Github actions

Fixing items would have to start after typescript & hook issue is resolved. #13 #17
If you're interested, check the lint-test branch.

Typescript support

It would be great to add type definition file to your library, then it can be more useful in projects that developed using typescript.

Refactor function or property names

common

  • acc will be named as {type}Acc
  • item will be named as {type}

utils.js

  • getFormattedDate(date, format) to formatDate(date, format)
  • getCurrentMonth(date) will be removed by lint
  • genDayOfWeek(DayOfWeekString) to genDateBlock(dayOW), which dayOW means dayOfWeek
  • str2numberString in genDayOfWeek to dayOWMap
  • genTimeBlock(dayOfWeek, hours, minutes) to genTimeBlock(dayOW, hours, minutes)
  • addColor(events) to assignColor(events)
  • hashString(s) will be removed by lint
  • colorGenerator(num) to pickColor(idx), color_list to colorList

TimeTableView.js

  • props numberOfDays to nDays
  • props formatDateHeader to dateHeaderFormat
  • props selectedDate and pivotDate should be fixed and linted
  • state currentMoment to currentDate
  • generateTimes(pivotTime, endPivotTime) to genTimes(pivotTime, endPivotTime) or better syntax

Header.js

  • getFontSizeHeader(numberOfDays) to headerFontSize(nDays)
  • getDayTextStyles(numberOfDays) to dayTextStyle(nDays)
  • getColumns(numberOfDays, selectedDate) to datesFrom...(nDays, ...)
  • Columns({ columns, numberOfDays, format}) to DaysHeader({ dates, nDays, format }) and remove Column Component.
  • Title role seems to be speicifed. It is empty.
  • WeekViewHeader props numberOfDays to nDays
  • WeekViewHeader props selectedDate to ...
  • WeekViewHeader props formatDate to dateFormat

Events.js

  • Events to EventTable
  • getEventsByNumberOfDays(numberOfDays, events, selectedDate) to catEventsByDays(nDays, events, ...)
  • getStyleForEvent(item) to calcEventStyle(event)
  • getEventsWithPosition(totalEvents) to adjustEventStyle(allEvents)
  • getEventItemWidth; change as const (if hooks)
  • sortEventByDates(events) to sortEventsByDate(events)
  • Events props numberOfDays to nDays
  • Events props selectedDate to ...

Event.js

  • currently no item available

selectedDate

  • TimeTableView is saving props pivotDate to state currentMoment. And in UNSAFE_componentWillReceiveProps, it updates currentMoment as undocumented props selectedDate. And currentMoment is injected to child components. Will there be scenarios using selectedDate? In my current view, we could just remove that state and just use pivotDate, renaming all selectedDate items to pivotDate.

Extra alert

  • Variable names on function could also change, based on new function name.
  • Using old function names which is revealed to user, will be allowed until future v.1.0.6; with aliasing + deprecation notice in documentation. After that we may remove the alias codes.

Please feel free to comment for discussion, related to above items.

Update example project

This issue will try to fix directory structure and problems with example project.

  • Create new expo-based example project. (no eject)
  • Take out files on src/* to root.
  • Add files option on package.json.

how to pass value to events_data from API fetch

i have function that fetch data same as events_data
i want to pass the values returned from this function to the object events_data

function getvals() {

    return fetch('http://***********/users/timetable')
        .then(response => response.json())
        .then((responseData) => {
            console.log(responseData);
            return responseData;
        })

        .catch(error => console.log(error))
}

so here responseData it returned something like this:
[{"day": "FRI", "end_time": 11, "start_time": 9}, {"day": "MON", "end_time": 1, "start_time": 11}, {"day": "WED", "end_time": 3, "start_time": 2}, {"day": "TUE", "end_time": 12, "start_time": 10}]

for example I want to set the value of day name in events_data to the value of day coming from getvals() function

Component not showing

Hello even I've copied and pasted the example into my app it shows very bad

BTW I'm trying to debug and adapt it in web as any other app react app

image

Can you provide some guidance?

Yarn/NPM install issue

Hi I have an issue with the code installed through Yarn

using yarn install react-native-timetable

The package is added but the index.js cannot be resolved as it is at root rather then under /src

Here is the react-native-timetable directory in my node_module folder:
image

This seems to be fixable by adding the index.js under /src

See below for the full debug output:

error: bundling failed: Error: While trying to resolve module `react-native-timetable` from file `/home/marco/StudioProjects/LesBâtons-mobile-cdski/src/pages/home-page.js`, the package `/home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/react-native-timetable/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/react-native-timetable/src/index.js`. Indeed, none of these files exist:

  * /home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/react-native-timetable/src/index.js(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.svg|.native.svg|.svg)
  * /home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/react-native-timetable/src/index.js/index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.svg|.native.svg|.svg)
    at ResolutionRequest.resolveDependency (/home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:65:15)
    at DependencyGraph.resolveDependency (/home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/metro/src/node-haste/DependencyGraph.js:282:16)
    at Object.resolve (/home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/metro/src/lib/transformHelpers.js:267:42)
    at dependencies.map.result (/home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/metro/src/DeltaBundler/traverseDependencies.js:426:31)
    at Array.map (<anonymous>)
    at resolveDependencies (/home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/metro/src/DeltaBundler/traverseDependencies.js:423:18)
    at /home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/metro/src/DeltaBundler/traverseDependencies.js:275:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (/home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/metro/src/DeltaBundler/traverseDependencies.js:87:24)
    at _next (/home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/metro/src/DeltaBundler/traverseDependencies.js:107:9)
::1 - - [06/Jan/2020:14:15:53 +0000] "GET /index.bundle?platform=android&dev=true&minify=false HTTP/1.1" 500 - "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) ReactNativeDebugger/0.10.1 Chrome/76.0.3809.146 Electron/6.0.10 Safari/537.36"
 BUNDLE  [android, dev] ./index.js ▓▓▓▓▓▓▓▓▓▓▓▓▓░░░ 82.7% (1430/1646), failed.

Using the npm command provided I get an error on install:

npm WARN optional Skipping failed optional dependency /jest-haste-map/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]
npm ERR! Linux 5.0.0-37-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "react-native-timetable"
npm ERR! node v8.10.0
npm ERR! npm  v3.5.2
npm ERR! path /home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/react-native-paper/node_modules/react-native-safe-area-view
npm ERR! code EISGIT

npm ERR! git Appears to be a git repo or submodule.
npm ERR! git     /home/marco/StudioProjects/LesBâtons-mobile-cdski/node_modules/react-native-paper/node_modules/react-native-safe-area-view
npm ERR! git Refusing to remove it. Update manually,
npm ERR! git or move it out of the way first.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/marco/StudioProjects/LesBâtons-mobile-cdski/android/npm-debug.log

EDIT:
using yarn install [email protected] solves the problem.
The bug must have been introduced with version 1.0.2

startTime and endTime are not set to current date

when I log the data of events the starttime and end time are shown like this :

"endTime": 2019-07-01T13:00:00.000Z,
"startTime": 2019-07-01T11:00:00.000Z,

Why year and month always set to 2019-07 ?
when I checked the utils.js file i fount this

return new Date(``2019-07-${str2numberString[DayOfWeekString.toLowerCase()]}T00:00:00``);

so how to make it set automatically based on the current date of adding the event data?

The component doesn't show correctly

Hi! Thanks for your component:-D
But it seems cannot work one my expo app
IMG_45DF4AFD98B0-1
My code is copied from README

import React, { Component } from 'react';
import {
    SafeAreaView,
    StyleSheet,
    View,
    Alert,
} from 'react-native';
import TimeTableView, { genTimeBlock } from 'react-native-timetable';
const events_data = [
    {
        title: "Math",
        startTime: genTimeBlock("MON", 9),
        endTime: genTimeBlock("MON", 10, 50),
        location: "Classroom 403",
        extra_descriptions: ["Kim", "Lee"],
    },
    {
        title: "Math",
        startTime: genTimeBlock("WED", 9),
        endTime: genTimeBlock("WED", 10, 50),
        location: "Classroom 403",
        extra_descriptions: ["Kim", "Lee"],
    },
    {
        title: "Physics",
        startTime: genTimeBlock("MON", 11),
        endTime: genTimeBlock("MON", 11, 50),
        location: "Lab 404",
        extra_descriptions: ["Einstein"],
    },
    {
        title: "Physics",
        startTime: genTimeBlock("WED", 11),
        endTime: genTimeBlock("WED", 11, 50),
        location: "Lab 404",
        extra_descriptions: ["Einstein"],
    },
    {
        title: "Mandarin",
        startTime: genTimeBlock("TUE", 9),
        endTime: genTimeBlock("TUE", 10, 50),
        location: "Language Center",
        extra_descriptions: ["Chen"],
    },
    {
        title: "Japanese",
        startTime: genTimeBlock("FRI", 9),
        endTime: genTimeBlock("FRI", 10, 50),
        location: "Language Center",
        extra_descriptions: ["Nakamura"],
    },
    {
        title: "Club Activity",
        startTime: genTimeBlock("THU", 9),
        endTime: genTimeBlock("THU", 10, 50),
        location: "Activity Center",
    },
    {
        title: "Club Activity",
        startTime: genTimeBlock("FRI", 13, 30),
        endTime: genTimeBlock("FRI", 14, 50),
        location: "Activity Center",
    },
];

export default class scheduler extends Component {
    constructor(props) {
        super(props);
        this.numOfDays = 5;
        this.pivotDate = genTimeBlock('mon');
    }

    scrollViewRef = (ref) => {
        this.timetableRef = ref;
    };

    onEventPress = (evt) => {
        Alert.alert("onEventPress", JSON.stringify(evt));
    };

    render() {
        return (
            <SafeAreaView style={{flex: 1}}>
                <View style={styles.container}>
                    <TimeTableView
                        scrollViewRef={this.scrollViewRef}
                        events={events_data}
                        pivotTime={9}
                        pivotTime={20}
                        pivotDate={this.pivotDate}
                        numberOfDays={this.numOfDays}
                        onEventPress={this.onEventPress}
                        headerStyle={styles.headerStyle}
                        formatDateHeader="dddd"
                        locale="ko"
                    />
                </View>
            </SafeAreaView>
        );
    }
};

const styles = StyleSheet.create({
    headerStyle: {
        backgroundColor: '#81E1B8'
    },
    container: {
        flex: 1,
        backgroundColor: '#F8F8F8',
    },
});


Could someone help me? Thanks a lot

The weekly timetable is not responsive to another calander

I have been used this perfect tool a few days ago and noticed that there is a problem with the "genDayOfWeek" utils function.

In my local calendar, we are counting the week from Sunday to Saturday and unfortunately, when I use the function "genTimeBlock" that uses the "genDayOfWeek" function, it does not count from "Sunday" and the "Sunday" that in my local calendar is the beginning of the week, the function count "Sunday" like it's in the next week, and not as the beginning of the week.

The source of the problem is in this row:

return new Date(2019-07-${str2numberString[DayOfWeekString.toLowerCase()]}T00:00:00);
because it looks at a specific week in 2019, that is the 1st day of the month is on "Monday".

To solve it locally, I created my own function and changed the number of days to make it count the "Sunday" as the first day of the week.

My suggestion is to make this function more general by adding some "What is your first day of the week?"

Code of the functions:

const genDayOfWeek = (DayOfWeekString) => {
  /*
    DayOfWeekString : SUN, MON, TUE, WED, THU, FRI, SAT
      type : string
   */
  if (typeof DayOfWeekString !== 'string') {
    throw new Error(`genDayOfWeek got parameter type: ${typeof DayOfWeekString}, but string expected`);
  }
  const str2numberString = {
    'mon': '01',
    'tue': '02',
    'wed': '03',
    'thu': '04',
    'fri': '05',
    'sat': '06',
    'sun': '07',
    '월': '01',
    '화': '02',
    '수': '03',
    '몊': '04',
    '금': '05',
    '토': '06',
  };

  return new Date(`2019-07-${str2numberString[DayOfWeekString.toLowerCase()]}T00:00:00`);
};

const genTimeBlock = (dayOfWeek, hours = 0, minutes = 0) => {
  const date = genDayOfWeek(dayOfWeek);
  date.setHours(hours);
  if (minutes != null) {
    date.setMinutes(minutes);
  }
  return date;
};

Change library to typescript and react hooks

Hello
Small and nice library!

Do you have plans to use react hooks in the near future? Because now it gives a warning for classic lifetime methods like ComponentDidMount

Thanks

How to add user input to the timetable (URGENTLY NEED FAST HELP)

Hi,

I am trying to add user input (have the user add, delete, edit etc the timetable) to this timetable GUI. I installed and pasted the timetable example into my code, changing a few variables and it is now showing successfully. I now am just stuck on the next steps on how to create user input for this timetable. I am a beginner in React-native so if anyone has done/knows how to do this, it would be greatly appreciated if you share it with me!

I am using the timetable for a major grade project due in a few days and it is extremely urgent I do this.
Any help from anyone (sharing code + videos + advice) on adding user interactions to this would be greatly appreciated!!

p.s. has anyone managed to get the timetable to swipe from side to side as well as up and down? if so, please share!

Thanks!

@MELindley @gomjellie @rubycho @sancodes

Pass events data or signle value of the event array data on press function

Hi,
as known that the events are all array and then showing in the timetable view based on time and day, so if one of these events pressed, the onEventPress function will pass its value to the function.
what I did is as follow:

<TimeTableView
                                        //scrollViewRef={scrollViewRef}
                                        events={data}
                                        pivotTime={8}
                                        pivotDate={pivotDate}
                                        numberOfDays={numOfDays}
                                        onEventPress={() => onEventPress(data)}
                                        headerStyle={styles.headerStyle}
                                        formatDateHeader="dddd"
                                        locale="en"
                                    />

so I passed the events data through onEventPress(data) however, when I console.log(data) in the onEventPress() after it has been passed, it pass all the data of the array of all events in the timetable view not only the pressed event data.
but I want only the pressed event data to be passed.
i hope that is clear and someone can help me to solve this issue.

Timetable body not showing

Hello,
First your library is very good it helped me a lot but i am having an issue. I used your library for a project and it was working. Then i updated my navigation library from react-navigation v3 to v5 and the body of the timetable stopped showing i think that the issue may be from the upgrade of react navigation. I tried it on a fresh project with only dependencies the ones for react navigation 5 still did not work (the data i used is the data provided by your example) the dependencies of the project are:
"dependencies": {
"@react-native-community/masked-view": "^0.1.7",
"@react-navigation/bottom-tabs": "^5.0.0",
"@react-navigation/drawer": "^5.0.0",
"@react-navigation/native": "^5.0.0",
"@react-navigation/stack": "^5.0.0",
"react": "16.9.0",
"react-native": "0.61.5",
"react-native-gesture-handler": "^1.5.6",
"react-native-reanimated": "^1.7.0",
"react-native-safe-area-context": "^0.7.2",
"react-native-screens": "^2.0.0-beta.2",
"react-native-timetable": "^1.0.4",
"react-native-vector-icons": "^6.6.0"
}
This is the file containing the code:
Home.zip
Sorry if there is something missing in this report it is my first time doing it.
Thanks in advance for you time.

Navigation not working on Android build

This library is working on the development time tested on the expo app. But after the APK build the navigation stopped working, even the back button was not working and the timetable view was working as expected.

video_2022-07-22_22-12-53.mp4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.