├── .circleci └── config.yml ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .husky ├── .npmignore ├── commit-msg └── pre-commit ├── .yarnrc ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── assets ├── day-view-schedule.png └── week-view-schedule.png ├── babel.config.js ├── example ├── app.json ├── babel.config.js ├── index.js ├── metro.config.js ├── package.json ├── src │ └── App.tsx ├── tsconfig.json ├── webpack.config.js └── yarn.lock ├── package.json ├── scripts └── bootstrap.js ├── src ├── Content │ ├── Cell.tsx │ ├── Header.tsx │ ├── Scheduling.tsx │ ├── index.tsx │ └── styles.ts ├── ScheduleContext.ts ├── Sidebar │ ├── index.tsx │ └── styles.ts ├── __tests__ │ └── selectedDate.test.tsx ├── constants.ts ├── index.tsx ├── styles.ts ├── types.ts └── utils.ts ├── tsconfig.build.json ├── tsconfig.json └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: circleci/node:10 7 | working_directory: ~/project 8 | 9 | commands: 10 | attach_project: 11 | steps: 12 | - attach_workspace: 13 | at: ~/project 14 | 15 | jobs: 16 | install-dependencies: 17 | executor: default 18 | steps: 19 | - checkout 20 | - attach_project 21 | - restore_cache: 22 | keys: 23 | - dependencies-{{ checksum "package.json" }} 24 | - dependencies- 25 | - restore_cache: 26 | keys: 27 | - dependencies-example-{{ checksum "example/package.json" }} 28 | - dependencies-example- 29 | - run: 30 | name: Install dependencies 31 | command: | 32 | yarn install --cwd example --frozen-lockfile 33 | yarn install --frozen-lockfile 34 | - save_cache: 35 | key: dependencies-{{ checksum "package.json" }} 36 | paths: node_modules 37 | - save_cache: 38 | key: dependencies-example-{{ checksum "example/package.json" }} 39 | paths: example/node_modules 40 | - persist_to_workspace: 41 | root: . 42 | paths: . 43 | 44 | lint: 45 | executor: default 46 | steps: 47 | - attach_project 48 | - run: 49 | name: Lint files 50 | command: | 51 | yarn lint 52 | 53 | typescript: 54 | executor: default 55 | steps: 56 | - attach_project 57 | - run: 58 | name: Typecheck files 59 | command: | 60 | yarn typescript 61 | 62 | unit-tests: 63 | executor: default 64 | steps: 65 | - attach_project 66 | - run: 67 | name: Run unit tests 68 | command: | 69 | yarn test --coverage 70 | - store_artifacts: 71 | path: coverage 72 | destination: coverage 73 | 74 | build-package: 75 | executor: default 76 | steps: 77 | - attach_project 78 | - run: 79 | name: Build package 80 | command: | 81 | yarn prepare 82 | 83 | workflows: 84 | build-and-test: 85 | jobs: 86 | - install-dependencies 87 | - lint: 88 | requires: 89 | - install-dependencies 90 | - typescript: 91 | requires: 92 | - install-dependencies 93 | - unit-tests: 94 | requires: 95 | - install-dependencies 96 | - build-package: 97 | requires: 98 | - install-dependencies 99 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .classpath 35 | .cxx 36 | .gradle 37 | .idea 38 | .project 39 | .settings 40 | local.properties 41 | android.iml 42 | 43 | # Cocoapods 44 | # 45 | example/ios/Pods 46 | 47 | # node.js 48 | # 49 | node_modules/ 50 | npm-debug.log 51 | yarn-debug.log 52 | yarn-error.log 53 | 54 | # BUCK 55 | buck-out/ 56 | \.buckd/ 57 | android/app/libs 58 | android/keystores/debug.keystore 59 | 60 | # Expo 61 | .expo/* 62 | 63 | # generated by bob 64 | lib/ 65 | -------------------------------------------------------------------------------- /.husky/.npmignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn commitlint -E HUSKY_GIT_PARAMS 5 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | yarn lint && yarn typescript 5 | -------------------------------------------------------------------------------- /.yarnrc: -------------------------------------------------------------------------------- 1 | # Override Yarn command so we can automatically setup the repo on running `yarn` 2 | 3 | yarn-path "scripts/bootstrap.js" 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. 4 | 5 | ## Development workflow 6 | 7 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package: 8 | 9 | ```sh 10 | yarn 11 | ``` 12 | 13 | > While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development. 14 | 15 | While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app. 16 | 17 | To start the packager: 18 | 19 | ```sh 20 | yarn example start 21 | ``` 22 | 23 | To run the example app on Android: 24 | 25 | ```sh 26 | yarn example android 27 | ``` 28 | 29 | To run the example app on iOS: 30 | 31 | ```sh 32 | yarn example ios 33 | ``` 34 | 35 | To run the example app on Web: 36 | 37 | ```sh 38 | yarn example web 39 | ``` 40 | 41 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 42 | 43 | ```sh 44 | yarn typescript 45 | yarn lint 46 | ``` 47 | 48 | To fix formatting errors, run the following: 49 | 50 | ```sh 51 | yarn lint --fix 52 | ``` 53 | 54 | Remember to add tests for your change if possible. Run the unit tests by: 55 | 56 | ```sh 57 | yarn test 58 | ``` 59 | 60 | ### Commit message convention 61 | 62 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 63 | 64 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 65 | - `feat`: new features, e.g. add new method to the module. 66 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 67 | - `docs`: changes into documentation, e.g. add usage example for the module.. 68 | - `test`: adding or updating tests, e.g. add integration tests using detox. 69 | - `chore`: tooling changes, e.g. change CI config. 70 | 71 | Our pre-commit hooks verify that your commit message matches this format when committing. 72 | 73 | ### Linting and tests 74 | 75 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 76 | 77 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 78 | 79 | Our pre-commit hooks verify that the linter and tests pass when committing. 80 | 81 | ### Publishing to npm 82 | 83 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc. 84 | 85 | To publish new versions, run the following: 86 | 87 | ```sh 88 | yarn release 89 | ``` 90 | 91 | ### Scripts 92 | 93 | The `package.json` file contains various scripts for common tasks: 94 | 95 | - `yarn bootstrap`: setup project by installing all dependencies and pods. 96 | - `yarn typescript`: type-check files with TypeScript. 97 | - `yarn lint`: lint files with ESLint. 98 | - `yarn test`: run unit tests with Jest. 99 | - `yarn example start`: start the Metro server for the example app. 100 | - `yarn example android`: run the example app on Android. 101 | - `yarn example ios`: run the example app on iOS. 102 | 103 | ### Sending a pull request 104 | 105 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github). 106 | 107 | When you're sending a pull request: 108 | 109 | - Prefer small pull requests focused on one change. 110 | - Verify that linters and tests are passing. 111 | - Review the documentation to make sure it looks good. 112 | - Follow the pull request template when opening a pull request. 113 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 114 | 115 | ## Code of Conduct 116 | 117 | ### Our Pledge 118 | 119 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 120 | 121 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 122 | 123 | ### Our Standards 124 | 125 | Examples of behavior that contributes to a positive environment for our community include: 126 | 127 | - Demonstrating empathy and kindness toward other people 128 | - Being respectful of differing opinions, viewpoints, and experiences 129 | - Giving and gracefully accepting constructive feedback 130 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 131 | - Focusing on what is best not just for us as individuals, but for the overall community 132 | 133 | Examples of unacceptable behavior include: 134 | 135 | - The use of sexualized language or imagery, and sexual attention or 136 | advances of any kind 137 | - Trolling, insulting or derogatory comments, and personal or political attacks 138 | - Public or private harassment 139 | - Publishing others' private information, such as a physical or email 140 | address, without their explicit permission 141 | - Other conduct which could reasonably be considered inappropriate in a 142 | professional setting 143 | 144 | ### Enforcement Responsibilities 145 | 146 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 147 | 148 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 149 | 150 | ### Scope 151 | 152 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 153 | 154 | ### Enforcement 155 | 156 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. 157 | 158 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 159 | 160 | ### Enforcement Guidelines 161 | 162 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 163 | 164 | #### 1. Correction 165 | 166 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 167 | 168 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 169 | 170 | #### 2. Warning 171 | 172 | **Community Impact**: A violation through a single incident or series of actions. 173 | 174 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 175 | 176 | #### 3. Temporary Ban 177 | 178 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 179 | 180 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 181 | 182 | #### 4. Permanent Ban 183 | 184 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 185 | 186 | **Consequence**: A permanent ban from any sort of public interaction within the community. 187 | 188 | ### Attribution 189 | 190 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 191 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 192 | 193 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 194 | 195 | [homepage]: https://www.contributor-covenant.org 196 | 197 | For answers to common questions about this code of conduct, see the FAQ at 198 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 199 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Fatasy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fantastic React Native Schedule 2 | 3 | Flexible scheduling library with more built-in features and enhanced customization options 4 | 5 | ## Installation 6 | 7 | ```sh 8 | yarn add f-react-native-schedule 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | import Schedule from 'f-react-native-schedule'; 15 | // ... 16 | 17 | ; 18 | ``` 19 | 20 | ## Day View 21 | 22 | 23 | 24 | 25 | 26 | ## Week View 27 | 28 | 29 | 30 | 31 | 32 | ## Properties API 33 | 34 | None of the following properties are required. A simple Will still render an empty schedule. 35 | 36 | <<<<<<< HEAD 37 | | Prop | Description | Default | Type | 38 | | --------------------------- | --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | 39 | | **`schedules`** | Array of schedules, to configure the field names use the `schedulingSettings` property. | `Empty Array` | `Array` | 40 | | **`selectedDate`** | To mark the active (current) date in the schedule. | `new Date()` | Date | 41 | | **`startHour`** | It is used to specify the start time, from which the Schedule starts to be displayed. | `00:00` | string | 42 | | **`endHour`** | It is used to specify the end time at which the schedule ends. | `24:00` | string | 43 | | **`currentView`** | Schedule view type. | `day` | `day` or `week` | 44 | | **`cellDimensions`** | Cell width and height configuration, header cell, sidebar cell and content cell. | `{height?: number, width?: number}` | {height: 80, width: 100} | 45 | | **`schedulingSettings`** | Scheduling configuration. | [Default Scheduling Settings](https://github.com/fatasy/f-react-native-schedule/blob/e3df449b645b412e8ce63bcd8d88c20a0601545a/src/constants.ts#L11) | [Type](https://github.com/fatasy/f-react-native-schedule/blob/e3df449b645b412e8ce63bcd8d88c20a0601545a/src/types.ts#L40) | 46 | | **`headerSettings`** | Header configuration. | [Default Header Settings](https://github.com/fatasy/f-react-native-schedule/blob/e3df449b645b412e8ce63bcd8d88c20a0601545a/src/constants.ts#L35) | [Type](https://github.com/fatasy/f-react-native-schedule/blob/e3df449b645b412e8ce63bcd8d88c20a0601545a/src/types.ts#L46) | 47 | | **`sidebarSettings`** | Sidebar configuration. | [Default Sidebar Settings](https://github.com/fatasy/f-react-native-schedule/blob/e3df449b645b412e8ce63bcd8d88c20a0601545a/src/constants.ts#L30) | [Type](https://github.com/fatasy/f-react-native-schedule/blob/e3df449b645b412e8ce63bcd8d88c20a0601545a/src/types.ts#L56) | 48 | | **`CellSettings `** | Cell content configuration. | [Default Cell Content Settings](https://github.com/fatasy/f-react-native-schedule/blob/e3df449b645b412e8ce63bcd8d88c20a0601545a/src/constants.ts#L39) | [Type](https://github.com/fatasy/f-react-native-schedule/blob/e3df449b645b412e8ce63bcd8d88c20a0601545a/src/types.ts#L23) | 49 | | **`showVerticalScrollbar`** | Specify if the vertical scrollbar should be displayed | `true` | boolean | 50 | | **`showHorizontalScrollbar`** | Specify if the horizontal scrollbar should be displayed | `true` | boolean | 51 | | **`onCellPress`** | Return function for pressing a cell | `-` | (date event) => void | 52 | | **`onCellLongPress`** | Return function for long pressing a cell. | `-` | (date event) => void | 53 | | **`onSchedulingPress`** | Return function for pressing a scheduling | `-` | (scheduling, event) => void | 54 | | **`onSchedulingLongPress`** | Return function for long pressing a scheduling. | `-` | (scheduling, event) => void | 55 | 56 | ## Contributing 57 | 58 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. 59 | -------------------------------------------------------------------------------- /assets/day-view-schedule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatasy/f-react-native-schedule/06db70ebc8bd84545d5265145fe40d8ad44511b0/assets/day-view-schedule.png -------------------------------------------------------------------------------- /assets/week-view-schedule.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fatasy/f-react-native-schedule/06db70ebc8bd84545d5265145fe40d8ad44511b0/assets/week-view-schedule.png -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "f-react-native-schedule-example", 3 | "displayName": "FReactNativeSchedule Example", 4 | "expo": { 5 | "name": "f-react-native-schedule-example", 6 | "slug": "f-react-native-schedule-example", 7 | "description": "Example app for f-react-native-schedule", 8 | "privacy": "public", 9 | "version": "1.0.0", 10 | "platforms": [ 11 | "ios", 12 | "android", 13 | "web" 14 | ], 15 | "ios": { 16 | "supportsTablet": true 17 | }, 18 | "assetBundlePatterns": [ 19 | "**/*" 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const pak = require('../package.json'); 3 | 4 | module.exports = function (api) { 5 | api.cache(true); 6 | 7 | return { 8 | presets: ['babel-preset-expo'], 9 | plugins: [ 10 | [ 11 | 'module-resolver', 12 | { 13 | extensions: ['.tsx', '.ts', '.js', '.json'], 14 | alias: { 15 | // For development, we want to alias the library to the source 16 | [pak.name]: path.join(__dirname, '..', pak.source), 17 | }, 18 | }, 19 | ], 20 | ], 21 | }; 22 | }; 23 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { registerRootComponent } from 'expo'; 2 | 3 | import App from './src/App'; 4 | 5 | // registerRootComponent calls AppRegistry.registerComponent('main', () => App); 6 | // It also ensures that whether you load the app in the Expo client or in a native build, 7 | // the environment is set up appropriately 8 | registerRootComponent(App); 9 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const blacklist = require('metro-config/src/defaults/blacklist'); 3 | const escape = require('escape-string-regexp'); 4 | const pak = require('../package.json'); 5 | 6 | const root = path.resolve(__dirname, '..'); 7 | 8 | const modules = Object.keys({ 9 | ...pak.peerDependencies, 10 | }); 11 | 12 | module.exports = { 13 | projectRoot: __dirname, 14 | watchFolders: [root], 15 | 16 | // We need to make sure that only one version is loaded for peerDependencies 17 | // So we blacklist them at the root, and alias them to the versions in example's node_modules 18 | resolver: { 19 | blacklistRE: blacklist( 20 | modules.map( 21 | (m) => 22 | new RegExp(`^${escape(path.join(root, 'node_modules', m))}\\/.*$`) 23 | ) 24 | ), 25 | 26 | extraNodeModules: modules.reduce((acc, name) => { 27 | acc[name] = path.join(__dirname, 'node_modules', name); 28 | return acc; 29 | }, {}), 30 | }, 31 | 32 | transformer: { 33 | getTransformOptions: async () => ({ 34 | transform: { 35 | experimentalImportSupport: false, 36 | inlineRequires: true, 37 | }, 38 | }), 39 | }, 40 | }; 41 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "f-react-native-schedule-example", 3 | "description": "Example app for f-react-native-schedule", 4 | "version": "0.0.1", 5 | "private": true, 6 | "main": "index", 7 | "scripts": { 8 | "android": "expo start --android", 9 | "ios": "expo start --ios", 10 | "web": "expo start --web", 11 | "start": "expo start", 12 | "test": "jest" 13 | }, 14 | "dependencies": { 15 | "@react-native-community/datetimepicker": "3.5.2", 16 | "dayjs": "^1.10.8", 17 | "expo": "^42.0.0", 18 | "expo-splash-screen": "~0.11.2", 19 | "react": "16.13.1", 20 | "react-dom": "16.13.1", 21 | "react-native": "0.63.4", 22 | "react-native-date-picker": "^4.2.0", 23 | "react-native-datepicker": "^1.7.2", 24 | "react-native-fab": "^1.0.18", 25 | "react-native-numeric-input": "^1.9.1", 26 | "react-native-radio-buttons-group": "^2.2.10", 27 | "react-native-safe-area-context": "3.2.0", 28 | "react-native-safe-area-view": "^1.1.1", 29 | "react-native-unimodules": "~0.14.5", 30 | "react-native-web": "~0.13.12" 31 | }, 32 | "devDependencies": { 33 | "@babel/core": "~7.9.0", 34 | "@babel/runtime": "^7.9.6", 35 | "babel-plugin-module-resolver": "^4.0.0", 36 | "babel-preset-expo": "8.3.0", 37 | "expo-cli": "^4.0.13" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /example/src/App.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable react-native/no-inline-styles */ 2 | import dayjs from 'dayjs'; 3 | import * as React from 'react'; 4 | 5 | import { StyleSheet, View, Text } from 'react-native'; 6 | import { SafeAreaView } from 'react-native-safe-area-context'; 7 | import DatePicker from 'react-native-datepicker'; 8 | import Schedule from '../../src'; 9 | import type { ScheduleView } from '../../src/types'; 10 | import { useState } from 'react'; 11 | import RadioGroup, { RadioButtonProps } from 'react-native-radio-buttons-group'; 12 | import FAB from 'react-native-fab'; 13 | 14 | const dates = [ 15 | dayjs().subtract(1, 'hour'), 16 | dayjs().add(1, 'day').add(1, 'hour'), 17 | dayjs().add(2, 'day').subtract(2, 'hour'), 18 | dayjs().add(4, 'day').subtract(6, 'hour'), 19 | ]; 20 | 21 | const schedules = dates.map((date) => ({ 22 | id: date.day(), 23 | subject: `scheduling ${date.day()}`, 24 | start_time: date.format('YYYY-MM-DD HH:mm:ss'), 25 | end_time: date.add(1, 'hour').format('YYYY-MM-DD HH:mm:ss'), 26 | })); 27 | 28 | const typeOfViewOptions: RadioButtonProps[] = [ 29 | { 30 | id: '1', 31 | label: 'Day', 32 | value: 'day', 33 | }, 34 | { 35 | id: '2', 36 | label: 'Week', 37 | value: 'week', 38 | selected: true, 39 | }, 40 | ]; 41 | 42 | export default function App() { 43 | const [date, setDate] = useState(new Date()); 44 | const [radioButtons, setRadioButtons] = useState(typeOfViewOptions); 45 | const [currentView, setCurrentView] = useState('week'); 46 | 47 | function onCurrentViewChange(nextRadioButtons: RadioButtonProps[]) { 48 | const nextCurrentView = nextRadioButtons.find(({ selected }) => selected); 49 | setCurrentView(nextCurrentView.value as ScheduleView); 50 | setRadioButtons(nextRadioButtons); 51 | } 52 | 53 | return ( 54 | 55 | 56 | 57 | Selected Date 58 | 64 | 65 | Type of View 66 | 72 | 73 | 74 | 79 | { 83 | console.log('FAB pressed'); 84 | }} 85 | visible={true} 86 | iconTextComponent={+} 87 | /> 88 | 89 | 90 | ); 91 | } 92 | 93 | const styles = StyleSheet.create({ 94 | container: { 95 | flex: 1, 96 | }, 97 | box: { 98 | width: 60, 99 | height: 60, 100 | marginVertical: 20, 101 | }, 102 | }); 103 | -------------------------------------------------------------------------------- /example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": {}, 3 | "extends": "expo/tsconfig.base" 4 | } 5 | -------------------------------------------------------------------------------- /example/webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const createExpoWebpackConfigAsync = require('@expo/webpack-config'); 3 | const { resolver } = require('./metro.config'); 4 | 5 | const root = path.resolve(__dirname, '..'); 6 | const node_modules = path.join(__dirname, 'node_modules'); 7 | 8 | module.exports = async function (env, argv) { 9 | const config = await createExpoWebpackConfigAsync(env, argv); 10 | 11 | config.module.rules.push({ 12 | test: /\.(js|jsx|ts|tsx)$/, 13 | include: path.resolve(root, 'src'), 14 | use: 'babel-loader', 15 | }); 16 | 17 | // We need to make sure that only one version is loaded for peerDependencies 18 | // So we alias them to the versions in example's node_modules 19 | Object.assign(config.resolve.alias, { 20 | ...resolver.extraNodeModules, 21 | 'react-native-web': path.join(node_modules, 'react-native-web'), 22 | }); 23 | 24 | return config; 25 | }; 26 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "f-react-native-schedule", 3 | "version": "0.1.5", 4 | "description": "Flexible scheduling library with more built-in features and enhanced customization options", 5 | "main": "lib/commonjs/index", 6 | "module": "lib/module/index", 7 | "types": "lib/typescript/index.d.ts", 8 | "react-native": "src/index", 9 | "source": "src/index", 10 | "files": [ 11 | "src", 12 | "lib", 13 | "android", 14 | "ios", 15 | "cpp", 16 | "f-react-native-schedule.podspec", 17 | "!lib/typescript/example", 18 | "!android/build", 19 | "!ios/build", 20 | "!**/__tests__", 21 | "!**/__fixtures__", 22 | "!**/__mocks__" 23 | ], 24 | "scripts": { 25 | "test": "jest", 26 | "typescript": "tsc --noEmit", 27 | "lint": "eslint \"**/*.{js,ts,tsx}\"", 28 | "prepare": "bob build", 29 | "release": "release-it", 30 | "example": "yarn --cwd example", 31 | "pods": "cd example && pod-install --quiet", 32 | "bootstrap": "yarn example && yarn && yarn pods" 33 | }, 34 | "keywords": [ 35 | "react-native", 36 | "ios", 37 | "android", 38 | "schedule", 39 | "calendar", 40 | "tasks", 41 | "agenda", 42 | "react-native-schedule", 43 | "react-schedule" 44 | ], 45 | "repository": "https://github.com/fatasy/f-react-native-schedule", 46 | "author": "Fatasy (https://github.com/fatasy)", 47 | "license": "MIT", 48 | "bugs": { 49 | "url": "https://github.com/fatasy/f-react-native-schedule/issues" 50 | }, 51 | "homepage": "https://github.com/fatasy/f-react-native-schedule#readme", 52 | "publishConfig": { 53 | "registry": "https://registry.npmjs.org/" 54 | }, 55 | "devDependencies": { 56 | "@commitlint/config-conventional": "^11.0.0", 57 | "@react-native-community/eslint-config": "^2.0.0", 58 | "@release-it/conventional-changelog": "^2.0.0", 59 | "@testing-library/jest-native": "^4.0.4", 60 | "@testing-library/react-native": "^9.0.0", 61 | "@types/jest": "^26.0.0", 62 | "@types/react": "^16.9.19", 63 | "@types/react-native": "0.62.13", 64 | "commitlint": "^11.0.0", 65 | "eslint": "^7.2.0", 66 | "eslint-config-prettier": "^7.0.0", 67 | "eslint-plugin-prettier": "^3.1.3", 68 | "husky": "^6.0.0", 69 | "jest": "^26.0.1", 70 | "pod-install": "^0.1.0", 71 | "prettier": "^2.0.5", 72 | "react": "16.13.1", 73 | "react-native": "0.63.4", 74 | "react-native-builder-bob": "^0.18.0", 75 | "react-test-renderer": "^17.0.2", 76 | "release-it": "^14.2.2", 77 | "typescript": "^4.1.3" 78 | }, 79 | "peerDependencies": { 80 | "react": "*", 81 | "react-native": "*" 82 | }, 83 | "jest": { 84 | "preset": "react-native", 85 | "modulePathIgnorePatterns": [ 86 | "/example/node_modules", 87 | "/lib/" 88 | ] 89 | }, 90 | "commitlint": { 91 | "extends": [ 92 | "@commitlint/config-conventional" 93 | ] 94 | }, 95 | "release-it": { 96 | "git": { 97 | "commitMessage": "chore: release ${version}", 98 | "tagName": "v${version}" 99 | }, 100 | "npm": { 101 | "publish": true 102 | }, 103 | "github": { 104 | "release": true 105 | }, 106 | "plugins": { 107 | "@release-it/conventional-changelog": { 108 | "preset": "angular" 109 | } 110 | } 111 | }, 112 | "eslintConfig": { 113 | "root": true, 114 | "extends": [ 115 | "@react-native-community", 116 | "prettier" 117 | ], 118 | "rules": { 119 | "prettier/prettier": [ 120 | "error", 121 | { 122 | "quoteProps": "consistent", 123 | "singleQuote": true, 124 | "tabWidth": 2, 125 | "trailingComma": "es5", 126 | "useTabs": false 127 | } 128 | ] 129 | } 130 | }, 131 | "eslintIgnore": [ 132 | "node_modules/", 133 | "lib/" 134 | ], 135 | "prettier": { 136 | "quoteProps": "consistent", 137 | "singleQuote": true, 138 | "tabWidth": 2, 139 | "trailingComma": "es5", 140 | "useTabs": false 141 | }, 142 | "react-native-builder-bob": { 143 | "source": "src", 144 | "output": "lib", 145 | "targets": [ 146 | "commonjs", 147 | "module", 148 | [ 149 | "typescript", 150 | { 151 | "project": "tsconfig.build.json" 152 | } 153 | ] 154 | ] 155 | }, 156 | "dependencies": { 157 | "dayjs": "^1.10.8" 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /scripts/bootstrap.js: -------------------------------------------------------------------------------- 1 | const os = require('os'); 2 | const path = require('path'); 3 | const child_process = require('child_process'); 4 | 5 | const root = path.resolve(__dirname, '..'); 6 | const args = process.argv.slice(2); 7 | const options = { 8 | cwd: process.cwd(), 9 | env: process.env, 10 | stdio: 'inherit', 11 | encoding: 'utf-8', 12 | }; 13 | 14 | if (os.type() === 'Windows_NT') { 15 | options.shell = true; 16 | } 17 | 18 | let result; 19 | 20 | if (process.cwd() !== root || args.length) { 21 | // We're not in the root of the project, or additional arguments were passed 22 | // In this case, forward the command to `yarn` 23 | result = child_process.spawnSync('yarn', args, options); 24 | } else { 25 | // If `yarn` is run without arguments, perform bootstrap 26 | result = child_process.spawnSync('yarn', ['bootstrap'], options); 27 | } 28 | 29 | process.exitCode = result.status; 30 | -------------------------------------------------------------------------------- /src/Content/Cell.tsx: -------------------------------------------------------------------------------- 1 | import React, { useContext } from 'react'; 2 | import type { Dayjs } from 'dayjs'; 3 | import { 4 | TouchableOpacity, 5 | TouchableOpacityProps, 6 | ViewProps, 7 | StyleSheet, 8 | GestureResponderEvent, 9 | View, 10 | } from 'react-native'; 11 | import { defaultCellSettings } from '../constants'; 12 | import ScheduleContext from '../ScheduleContext'; 13 | 14 | export type onCellPress = (date: Dayjs, event: GestureResponderEvent) => void; 15 | export type onCellLongPress = ( 16 | date: Dayjs, 17 | event: GestureResponderEvent 18 | ) => void; 19 | 20 | type CellProps = { 21 | date: Dayjs; 22 | } & ViewProps & 23 | TouchableOpacityProps; 24 | 25 | const Cell: React.FC = ({ date, style: styleProp, ...props }) => { 26 | const { cellSettings, onCellPress, onCellLongPress } = 27 | useContext(ScheduleContext); 28 | const { render, style } = cellSettings; 29 | 30 | const touchableOpacityProps = { 31 | ...(typeof onCellPress === 'function' && { 32 | onPress: (event) => onCellPress(date, event), 33 | }), 34 | ...(typeof onCellLongPress === 'function' && { 35 | onLongPress: (event) => onCellLongPress(date, event), 36 | }), 37 | } as TouchableOpacityProps; 38 | 39 | return ( 40 | 45 | {render && render(date)} 46 | 47 | ); 48 | }; 49 | 50 | const styles = StyleSheet.create({ 51 | container: { 52 | position: 'absolute', 53 | alignItems: 'center', 54 | justifyContent: 'center', 55 | height: 80, 56 | width: 100, 57 | borderWidth: 1, 58 | borderBottomWidth: 0, 59 | borderLeftWidth: 0, 60 | ...defaultCellSettings.style, 61 | }, 62 | content: { 63 | flex: 1, 64 | }, 65 | }); 66 | 67 | export default Cell; 68 | -------------------------------------------------------------------------------- /src/Content/Header.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable react-native/no-inline-styles */ 2 | import React from 'react'; 3 | import dayjs from 'dayjs'; 4 | import { useContext } from 'react'; 5 | import { Text, View, StyleSheet, ScrollView } from 'react-native'; 6 | import ScheduleContext from '../ScheduleContext'; 7 | 8 | const Header: React.FC = () => { 9 | const { selectedDate, days, headerSettings, cellDimensions } = 10 | useContext(ScheduleContext); 11 | const { cellRender, currentDayColor } = headerSettings; 12 | 13 | function renderDayWeek(dayNumber: number) { 14 | const day = dayjs(selectedDate).day(dayNumber); 15 | const isCurrentDay = day.format('DD-MM') === dayjs().format('DD-MM'); 16 | 17 | return ( 18 | 19 | {cellRender && cellRender(day)} 20 | {!cellRender && ( 21 | 22 | 27 | {day.format('dd')} 28 | 29 | 36 | {day.format('DD')} 37 | 38 | 39 | )} 40 | 41 | ); 42 | } 43 | 44 | return ( 45 | 46 | 47 | {days.map((day) => renderDayWeek(day))} 48 | 49 | 50 | ); 51 | }; 52 | 53 | const styles = StyleSheet.create({ 54 | container: { 55 | flexDirection: 'row', 56 | }, 57 | card: { 58 | height: 50, 59 | width: 100, 60 | }, 61 | content: { 62 | flex: 1, 63 | borderWidth: 1, 64 | borderRightWidth: 0, 65 | borderBottomWidth: 0, 66 | justifyContent: 'center', 67 | alignContent: 'center', 68 | alignItems: 'center', 69 | flexDirection: 'column', 70 | borderColor: '#ebedf2', 71 | backgroundColor: '#f3f6f9', 72 | }, 73 | }); 74 | 75 | export default Header; 76 | -------------------------------------------------------------------------------- /src/Content/Scheduling.tsx: -------------------------------------------------------------------------------- 1 | import dayjs, { Dayjs } from 'dayjs'; 2 | import React, { useContext } from 'react'; 3 | import { 4 | TouchableOpacity, 5 | TouchableOpacityProps, 6 | View, 7 | ViewProps, 8 | Text, 9 | StyleSheet, 10 | GestureResponderEvent, 11 | } from 'react-native'; 12 | import type { Scheduling as SchedulingType } from '../types'; 13 | import ScheduleContext from '../ScheduleContext'; 14 | 15 | export type onSchedulingPress = ( 16 | scheduling: SchedulingType, 17 | event: GestureResponderEvent 18 | ) => void; 19 | export type onSchedulingLongPress = ( 20 | scheduling: SchedulingType, 21 | event: GestureResponderEvent 22 | ) => void; 23 | 24 | type SchedulingProps = { 25 | date: Dayjs; 26 | scheduling: SchedulingType; 27 | } & ViewProps & 28 | TouchableOpacityProps; 29 | 30 | function getSchedulingHeight( 31 | startTime: string, 32 | endTime: string, 33 | height: number 34 | ) { 35 | const time = dayjs(endTime).diff(dayjs(startTime), 'hours', true); 36 | return height * time; 37 | } 38 | 39 | const Scheduling: React.FC = ({ 40 | date, 41 | scheduling, 42 | style: styleProp, 43 | ...props 44 | }) => { 45 | const { 46 | cellDimensions, 47 | schedulingSettings, 48 | onSchedulingPress, 49 | onSchedulingLongPress, 50 | } = useContext(ScheduleContext); 51 | const { fields, render, style } = schedulingSettings; 52 | const { 53 | subject: { name: subjectFieldName, style: subjectStyle }, 54 | startTime: { name: startTimeFieldName }, 55 | endTime: { name: endTimeFieldName }, 56 | } = fields; 57 | const { 58 | [subjectFieldName]: subject, 59 | [startTimeFieldName]: startTime, 60 | [endTimeFieldName]: endTime, 61 | } = scheduling; 62 | const { height: cellHeight } = cellDimensions; 63 | 64 | const touchableOpacityProps = { 65 | ...(typeof onSchedulingPress === 'function' && { 66 | onPress: (event) => onSchedulingPress(scheduling, event), 67 | }), 68 | ...(typeof onSchedulingLongPress === 'function' && { 69 | onLongPress: (event) => onSchedulingLongPress(scheduling, event), 70 | }), 71 | } as TouchableOpacityProps; 72 | 73 | return ( 74 | 85 | {render && render(scheduling, date)} 86 | {!render && ( 87 | 88 | 89 | {subject} 90 | 91 | 92 | {dayjs(startTime).format('HH:mm')} -{' '} 93 | {dayjs(endTime).format('HH:mm')} 94 | 95 | 96 | )} 97 | 98 | ); 99 | }; 100 | 101 | const styles = StyleSheet.create({ 102 | container: { 103 | position: 'absolute', 104 | height: 80, 105 | width: 100, 106 | zIndex: 999, 107 | elevation: 4, 108 | }, 109 | content: { 110 | flex: 1, 111 | borderRadius: 4, 112 | backgroundColor: '#fff', 113 | zIndex: 999, 114 | }, 115 | subject: { 116 | color: '#464e5f', 117 | }, 118 | time: { 119 | fontSize: 11, 120 | color: '#464e5f', 121 | }, 122 | }); 123 | 124 | export default Scheduling; 125 | -------------------------------------------------------------------------------- /src/Content/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useContext, useEffect, useMemo, useState } from 'react'; 2 | import { ScrollView, ViewStyle } from 'react-native'; 3 | import ScheduleContext from '../ScheduleContext'; 4 | import Header from './Header'; 5 | import Cell from './Cell'; 6 | import dayjs, { Dayjs } from 'dayjs'; 7 | import styles from './styles'; 8 | 9 | import isBetween from 'dayjs/plugin/isBetween'; 10 | import Scheduling from './Scheduling'; 11 | import { getScrollViewContainerWidth, isUndefined } from '../utils'; 12 | 13 | dayjs.extend(isBetween); 14 | 15 | const Content: React.FC = () => { 16 | const { 17 | selectedDate, 18 | rawSchedules, 19 | days, 20 | hours, 21 | currentView, 22 | cellDimensions, 23 | schedulingSettings, 24 | } = useContext(ScheduleContext); 25 | const [schedules, setSchedules] = useState>([]); 26 | const { fields } = schedulingSettings; 27 | const { 28 | startTime: { name: startTimeFieldName }, 29 | endTime: { name: endTimeFieldName }, 30 | } = fields; 31 | 32 | const dates = useMemo(() => { 33 | return hours 34 | .map((hour) => { 35 | return days.map((day) => { 36 | return dayjs(selectedDate).day(day).hour(hour).minute(0).second(0); 37 | }); 38 | }) 39 | .flat(); 40 | }, [selectedDate, days, hours]); 41 | 42 | function getItemStyle(day: number, hour: number) { 43 | return { 44 | ...cellDimensions, 45 | left: 46 | currentView === 'day' ? 0 : day > 0 ? cellDimensions.width * day : 0, 47 | top: 48 | hour > 0 ? cellDimensions.height * (hour + 1) : cellDimensions.height, 49 | margin: 0, 50 | } as ViewStyle; 51 | } 52 | 53 | function renderItem(date: Dayjs, index: number) { 54 | const scheduling = schedules[date.valueOf()]; 55 | 56 | if (isUndefined(scheduling)) { 57 | return ( 58 | 63 | ); 64 | } 65 | 66 | return ( 67 | 73 | ); 74 | } 75 | 76 | useEffect(() => { 77 | const nextSchedules = [] as Array; 78 | rawSchedules?.forEach((scheduling) => { 79 | const { [startTimeFieldName]: startTime, [endTimeFieldName]: endTime } = 80 | scheduling; 81 | const date = dates.find((d) => d.isBetween(startTime, endTime)); 82 | 83 | if (date === undefined) return; 84 | nextSchedules[date.valueOf()] = scheduling; 85 | }); 86 | setSchedules(nextSchedules); 87 | }, [startTimeFieldName, endTimeFieldName, dates, rawSchedules]); 88 | 89 | return ( 90 | 103 |
104 | {dates.map(renderItem)} 105 | 106 | ); 107 | }; 108 | 109 | export default Content; 110 | -------------------------------------------------------------------------------- /src/Content/styles.ts: -------------------------------------------------------------------------------- 1 | import { StyleSheet } from 'react-native'; 2 | 3 | export default StyleSheet.create({ 4 | container: { 5 | flex: 1, 6 | }, 7 | card: { 8 | alignItems: 'center', 9 | justifyContent: 'center', 10 | height: 80, 11 | width: 100, 12 | borderWidth: 1, 13 | borderBottomWidth: 0, 14 | borderLeftWidth: 0, 15 | }, 16 | }); 17 | -------------------------------------------------------------------------------- /src/ScheduleContext.ts: -------------------------------------------------------------------------------- 1 | import { createContext } from 'react'; 2 | 3 | import type { onCellLongPress, onCellPress } from './Content/Cell'; 4 | import type { 5 | onSchedulingLongPress, 6 | onSchedulingPress, 7 | } from './Content/Scheduling'; 8 | import type { 9 | CellDimensions, 10 | CellSettings, 11 | DaysWeek, 12 | EndHour, 13 | HeaderSettings, 14 | Hours, 15 | ScheduleView, 16 | Scheduling, 17 | SchedulingSettings, 18 | SelectedDate, 19 | SidebarSettings, 20 | StartHour, 21 | } from './types'; 22 | 23 | type ScheduleContext = { 24 | /** 25 | * To mark the active (current) date in the schedule. 26 | * The default is the current system date. 27 | * 28 | * @default 'new Date()' 29 | */ 30 | selectedDate: SelectedDate; 31 | /** 32 | * It is used to specify the start time, from which the Schedule starts to be displayed. 33 | * 34 | * @default '00:00' 35 | */ 36 | startHour: StartHour; 37 | /** 38 | * It is used to specify the end time at which the schedule ends. It also accepts a time string. 39 | * 40 | * @default '24:00' 41 | */ 42 | endHour: EndHour; 43 | /** 44 | * To set the active view on the schedule 45 | * 46 | * * day 47 | * * week 48 | * 49 | * @default 'week' 50 | */ 51 | currentView: ScheduleView; 52 | schedules: Array; 53 | rawSchedules: Array; 54 | days: Array; 55 | hours: Hours; 56 | daysWeek: DaysWeek; 57 | cellDimensions: CellDimensions; 58 | headerSettings: HeaderSettings; 59 | sidebarSettings: SidebarSettings; 60 | cellSettings: CellSettings; 61 | schedulingSettings: SchedulingSettings; 62 | onCellPress?: onCellPress; 63 | onCellLongPress?: onCellLongPress; 64 | onSchedulingPress?: onSchedulingPress; 65 | onSchedulingLongPress?: onSchedulingLongPress; 66 | }; 67 | 68 | const ScheduleContext = createContext({} as ScheduleContext); 69 | 70 | export default ScheduleContext; 71 | -------------------------------------------------------------------------------- /src/Sidebar/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import dayjs from 'dayjs'; 3 | import { useContext } from 'react'; 4 | import { Text, View } from 'react-native'; 5 | import ScheduleContext from '../ScheduleContext'; 6 | 7 | import styles from './styles'; 8 | 9 | const Sidebar: React.FC = () => { 10 | const { hours, sidebarSettings, cellDimensions } = 11 | useContext(ScheduleContext); 12 | const { hourColor, hourFormat, cellRender } = sidebarSettings; 13 | const { height } = cellDimensions; 14 | function renderHour(hour: number) { 15 | return ( 16 | 17 | {cellRender && cellRender(hour)} 18 | {!cellRender && ( 19 | 20 | 21 | {dayjs().hour(hour).format(hourFormat)} 22 | 23 | 24 | )} 25 | 26 | ); 27 | } 28 | 29 | return ( 30 | 31 | {hours?.map(renderHour)} 32 | 33 | ); 34 | }; 35 | 36 | export default Sidebar; 37 | -------------------------------------------------------------------------------- /src/Sidebar/styles.ts: -------------------------------------------------------------------------------- 1 | import { StyleSheet } from 'react-native'; 2 | 3 | export default StyleSheet.create({ 4 | container: { 5 | width: 80, 6 | }, 7 | card: { 8 | flex: 1, 9 | alignItems: 'center', 10 | justifyContent: 'center', 11 | height: 80, 12 | width: 80, 13 | borderRightWidth: 1, 14 | borderTopWidth: 1, 15 | borderColor: '#ebedf2', 16 | }, 17 | hour: { 18 | color: '#b5b5c3', 19 | }, 20 | }); 21 | -------------------------------------------------------------------------------- /src/__tests__/selectedDate.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react-native'; 3 | import Schedule from 'f-react-native-schedule'; 4 | import dayjs from 'dayjs'; 5 | import { DaysWeek } from '../constants'; 6 | 7 | test('change selectedDate in day view', () => { 8 | const { rerender, getByText } = render(); 9 | getByText(new Date().getDate().toString()); 10 | 11 | const selectedDate = new Date('2022-12-11 09:45:00'); 12 | rerender(); 13 | getByText(selectedDate.getDate().toString()); 14 | }); 15 | 16 | test('change selectedDate in week view', () => { 17 | const { rerender, getByText } = render(); 18 | DaysWeek.forEach((day) => getByText(dayjs().day(day).format('DD'))); 19 | 20 | const selectedDate = dayjs('2022-12-11 09:45:00'); 21 | rerender( 22 | 23 | ); 24 | DaysWeek.forEach((day) => getByText(selectedDate.day(day).format('DD'))); 25 | }); 26 | -------------------------------------------------------------------------------- /src/constants.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | CellDimensions, 3 | CellSettings, 4 | HeaderSettings, 5 | SidebarSettings, 6 | } from './types'; 7 | 8 | export const DaysWeek = [0, 1, 2, 3, 4, 5, 6]; 9 | export const Hours = Array.from(Array(24).keys()); 10 | 11 | export const defaultSchedulingSettings = { 12 | fields: { 13 | subject: { 14 | name: 'subject', 15 | }, 16 | startTime: { 17 | name: 'start_time', 18 | }, 19 | endTime: { 20 | name: 'end_time', 21 | }, 22 | }, 23 | }; 24 | 25 | export const defaultCellDimensions: CellDimensions = { 26 | height: 80, 27 | width: 100, 28 | }; 29 | 30 | export const defaultSidebarSettings: SidebarSettings = { 31 | hourColor: '#b5b5c3', 32 | hourFormat: 'HH:00', 33 | }; 34 | 35 | export const defaultHeaderSettings: HeaderSettings = { 36 | currentDayColor: '#1a73e8', 37 | }; 38 | 39 | export const defaultCellSettings: CellSettings = { 40 | style: { 41 | borderColor: '#ebedf2', 42 | backgroundColor: '#f3f6f9', 43 | }, 44 | }; 45 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useMemo } from 'react'; 2 | import { View, ScrollView, ViewStyle } from 'react-native'; 3 | 4 | import Sidebar from './Sidebar'; 5 | import Content from './Content'; 6 | 7 | import styles from './styles'; 8 | 9 | import { 10 | DaysWeek, 11 | defaultCellDimensions, 12 | defaultCellSettings, 13 | defaultHeaderSettings, 14 | defaultSchedulingSettings, 15 | defaultSidebarSettings, 16 | } from './constants'; 17 | import { 18 | getCellDimensions, 19 | getDays, 20 | getHours, 21 | getSchedulingSettings, 22 | } from './utils'; 23 | 24 | import ScheduleContext from './ScheduleContext'; 25 | import type { 26 | CellDimensions, 27 | CellSettings, 28 | ScheduleSchedulingSettings, 29 | } from './types'; 30 | 31 | export type ScheduleProps = { 32 | style?: ViewStyle; 33 | schedulingSettings?: Partial; 34 | cellSettings?: Partial; 35 | cellDimensions?: Partial; 36 | showVerticalScrollbar?: boolean; 37 | showHorizontalScrollbar?: boolean; 38 | } & Partial< 39 | Pick< 40 | ScheduleContext, 41 | | 'schedules' 42 | | 'selectedDate' 43 | | 'startHour' 44 | | 'endHour' 45 | | 'currentView' 46 | | 'daysWeek' 47 | | 'headerSettings' 48 | | 'sidebarSettings' 49 | | 'onCellPress' 50 | | 'onCellLongPress' 51 | | 'onSchedulingPress' 52 | | 'onSchedulingLongPress' 53 | > 54 | >; 55 | 56 | const Schedule: React.FC = ({ 57 | schedules = [], 58 | currentView = 'week', 59 | selectedDate = new Date(), 60 | startHour = '00:00', 61 | endHour = '24:00', 62 | daysWeek = DaysWeek, 63 | cellDimensions = defaultCellDimensions, 64 | headerSettings = defaultHeaderSettings, 65 | sidebarSettings = defaultSidebarSettings, 66 | cellSettings = defaultCellSettings, 67 | schedulingSettings = defaultSchedulingSettings, 68 | showVerticalScrollbar = true, 69 | showHorizontalScrollbar = true, 70 | onCellPress, 71 | onCellLongPress, 72 | onSchedulingPress, 73 | onSchedulingLongPress, 74 | style, 75 | }) => { 76 | const value = useMemo( 77 | () => ({ 78 | schedules, 79 | currentView, 80 | selectedDate, 81 | rawSchedules: schedules, 82 | startHour, 83 | endHour, 84 | days: getDays(selectedDate, currentView, daysWeek), 85 | hours: getHours(startHour, endHour), 86 | daysWeek, 87 | headerSettings: { ...defaultHeaderSettings, ...headerSettings }, 88 | sidebarSettings: { ...defaultSidebarSettings, ...sidebarSettings }, 89 | schedulingSettings: getSchedulingSettings(schedulingSettings), 90 | showVerticalScrollbar, 91 | showHorizontalScrollbar, 92 | cellDimensions: getCellDimensions(currentView, { 93 | ...defaultCellDimensions, 94 | ...cellDimensions, 95 | }), 96 | cellSettings, 97 | onCellPress, 98 | onCellLongPress, 99 | onSchedulingPress, 100 | onSchedulingLongPress, 101 | }), 102 | [ 103 | schedules, 104 | startHour, 105 | endHour, 106 | daysWeek, 107 | selectedDate, 108 | currentView, 109 | cellDimensions, 110 | headerSettings, 111 | sidebarSettings, 112 | cellSettings, 113 | schedulingSettings, 114 | showVerticalScrollbar, 115 | showHorizontalScrollbar, 116 | onCellPress, 117 | onCellLongPress, 118 | onSchedulingPress, 119 | onSchedulingLongPress, 120 | ] 121 | ); 122 | 123 | return ( 124 | 125 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | ); 137 | }; 138 | 139 | export default Schedule; 140 | -------------------------------------------------------------------------------- /src/styles.ts: -------------------------------------------------------------------------------- 1 | import { StyleSheet } from 'react-native'; 2 | 3 | export default StyleSheet.create({ 4 | container: { 5 | flex: 1, 6 | }, 7 | content: { 8 | flex: 1, 9 | flexDirection: 'row', 10 | }, 11 | }); 12 | -------------------------------------------------------------------------------- /src/types.ts: -------------------------------------------------------------------------------- 1 | import type { Dayjs } from 'dayjs'; 2 | import type { TextStyle, ViewStyle } from 'react-native'; 3 | 4 | export type Scheduling = { 5 | [startTimeFieldName: string]: string; 6 | } & { 7 | [endTimeFieldName: string]: string; 8 | } & { 9 | [titleFieldName: string]: string; 10 | } & any; 11 | 12 | export type StartHour = string; 13 | export type EndHour = string; 14 | export type Hours = Array; 15 | export type SelectedDate = Date; 16 | export type ScheduleView = 'day' | 'week'; 17 | export type DaysWeek = Array; 18 | export type CellDimensions = { 19 | height: number; 20 | width: number; 21 | }; 22 | 23 | export type CellSettings = { 24 | style?: ViewStyle; 25 | render?: (date: Dayjs) => JSX.Element; 26 | }; 27 | 28 | export type SchedulingField = { 29 | name: string; 30 | style?: TextStyle; 31 | render?: (value: string, scheduling: Scheduling) => JSX.Element; 32 | }; 33 | 34 | export type SchedulingFields = { 35 | subject: SchedulingField; 36 | startTime: SchedulingField; 37 | endTime: SchedulingField; 38 | }; 39 | 40 | export type SchedulingSettings = { 41 | fields: SchedulingFields; 42 | style?: ViewStyle; 43 | render?: (scheduling: Scheduling, date: Dayjs) => JSX.Element; 44 | }; 45 | 46 | export type HeaderSettings = { 47 | cellRender?: (date: Dayjs) => JSX.Element; 48 | /** 49 | * Current day color 50 | * 51 | * @default '#1a73e8' 52 | */ 53 | currentDayColor?: string; 54 | }; 55 | 56 | export type SidebarSettings = { 57 | cellRender?: (hour: number) => JSX.Element; 58 | /** 59 | * @default '#b5b5c3' 60 | */ 61 | hourColor?: string; 62 | /** 63 | * if you want to display the period, set 'HH:00 A' 64 | * @link https://day.js.org/docs/en/display/format 65 | * @default 'HH:00' 66 | */ 67 | hourFormat?: string; 68 | }; 69 | 70 | export type ScheduleSchedulingSettings = { 71 | fields: Partial; 72 | } & Omit; 73 | -------------------------------------------------------------------------------- /src/utils.ts: -------------------------------------------------------------------------------- 1 | import dayjs from 'dayjs'; 2 | import { defaultSchedulingSettings, Hours } from './constants'; 3 | 4 | import isSameOrAfter from 'dayjs/plugin/isSameOrAfter'; 5 | import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'; 6 | import { Dimensions } from 'react-native'; 7 | import type { 8 | CellDimensions, 9 | DaysWeek, 10 | EndHour, 11 | ScheduleSchedulingSettings, 12 | ScheduleView, 13 | SchedulingSettings, 14 | SelectedDate, 15 | StartHour, 16 | } from './types'; 17 | 18 | dayjs.extend(isSameOrAfter); 19 | dayjs.extend(isSameOrBefore); 20 | 21 | export function getHours(startHourRaw: StartHour, endHourRaw: EndHour) { 22 | const [startHour, startMinute = '00'] = startHourRaw.split(':'); 23 | const [endHour, endMinute = '00'] = endHourRaw.split(':'); 24 | 25 | const start = dayjs() 26 | .hour(parseInt(startHour, 10)) 27 | .minute(parseInt(startMinute, 10)); 28 | const end = dayjs() 29 | .hour(parseInt(endHour, 10)) 30 | .minute(parseInt(endMinute, 10)); 31 | 32 | const hours = Hours; 33 | 34 | Hours.forEach((hour, key) => { 35 | const hourMoment = dayjs().hour(hour); 36 | 37 | if (!hourMoment.isSameOrAfter(start, 'hour')) { 38 | delete hours[key]; 39 | } 40 | 41 | if (!hourMoment.isSameOrBefore(end, 'hour')) { 42 | delete hours[key]; 43 | } 44 | }); 45 | 46 | return hours; 47 | } 48 | 49 | export function getDays( 50 | selectedDate: SelectedDate, 51 | currentView: ScheduleView, 52 | daysWeek: DaysWeek 53 | ): DaysWeek { 54 | if (currentView === 'day') return [dayjs(selectedDate).day()]; 55 | return daysWeek; 56 | } 57 | 58 | export function getCellDimensions( 59 | view: ScheduleView, 60 | settings: CellDimensions 61 | ): CellDimensions { 62 | if (view === 'day') { 63 | return { 64 | width: Dimensions.get('window').width - 50, 65 | height: settings.height, 66 | }; 67 | } 68 | 69 | return settings; 70 | } 71 | 72 | export function getScrollViewContainerWidth( 73 | view: ScheduleView, 74 | days: DaysWeek, 75 | cellWidth: number 76 | ) { 77 | if (view === 'day') return Dimensions.get('window').width - 80; 78 | return cellWidth * days.length; 79 | } 80 | 81 | export function isUndefined(value: any): boolean { 82 | return value === undefined; 83 | } 84 | 85 | export function getSchedulingSettings( 86 | settings: Partial 87 | ): SchedulingSettings { 88 | const { fields, style, render } = settings; 89 | return { 90 | fields: { 91 | subject: { 92 | ...defaultSchedulingSettings.fields.subject, 93 | ...(fields?.subject && { 94 | ...fields.subject, 95 | }), 96 | }, 97 | startTime: { 98 | ...defaultSchedulingSettings.fields.startTime, 99 | ...(fields?.startTime && { 100 | ...fields.startTime, 101 | }), 102 | }, 103 | endTime: { 104 | ...defaultSchedulingSettings.fields.endTime, 105 | ...(fields?.endTime && { 106 | ...fields.endTime, 107 | }), 108 | }, 109 | }, 110 | style, 111 | render, 112 | } as SchedulingSettings; 113 | } 114 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "extends": "./tsconfig", 4 | "exclude": ["example"] 5 | } 6 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "./", 4 | "paths": { 5 | "f-react-native-schedule": ["./src/index"] 6 | }, 7 | "allowUnreachableCode": false, 8 | "allowUnusedLabels": false, 9 | "esModuleInterop": true, 10 | "importsNotUsedAsValues": "error", 11 | "forceConsistentCasingInFileNames": true, 12 | "jsx": "react", 13 | "lib": ["esnext"], 14 | "module": "esnext", 15 | "moduleResolution": "node", 16 | "noFallthroughCasesInSwitch": true, 17 | "noImplicitReturns": true, 18 | "noImplicitUseStrict": false, 19 | "noStrictGenericChecks": false, 20 | "noUnusedLocals": true, 21 | "noUnusedParameters": true, 22 | "resolveJsonModule": true, 23 | "skipLibCheck": true, 24 | "declaration": true, 25 | "strict": true, 26 | "target": "esnext" 27 | } 28 | } 29 | --------------------------------------------------------------------------------