Giter VIP home page Giter VIP logo

react-native-persian-calendar-picker's Introduction

React Native Jalaali (Persian) Calendar

NPM Version Build Status

This is a Jalaali (Persian) Calendar Picker Component for React Native

The package is both Android and iOS compatible.

Installation

$ yarn add react-native-persian-calendar-picker

or

$ npm install react-native-persian-calendar-picker --save

Prerequisites

CalendarPicker requires Moment JS. Date props may be anything parseable by Moment: Javascript Date, Moment date, or ISO8601 datetime string.

Usage

How to use it:

import React from 'react';
import {
  StyleSheet,
  Text,
  View,
} from 'react-native';
import PersianCalendarPicker from 'react-native-persian-calendar-picker';

class PersianCalendarPickerExample extends React.Component {
  constructor(props) {
		super(props);

    this.state = {
      selectedStartDate: null,
    };

		this.onDateChange = this.onDateChange.bind(this);
  }

  onDateChange(date) {
    this.setState({ selectedStartDate: date });
  }

  render() {
    const { selectedStartDate } = this.state;
    const startDate = selectedStartDate ? selectedStartDate.toString() : '';
    return (
      <View style={styles.container}>

        <PersianCalendarPicker
          onDateChange={this.onDateChange}
				/>

        <View>
          <Text>SELECTED DATE:{ startDate }</Text>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#FFFFFF',
    marginTop: 100,
  },
});

PersianCalendarPicker props

Prop Type Description
isRTL Boolean Optional. Force layout to be RTL. Default is false
weekdays Array Optional. List of week days. Eg. ['Sat', 'Sun', ...] Must be 7 days
months Array Optional. List of months names. Eg. ['Farvardin', 'Ordibehesht', ...] Must be 12 months
allowRangeSelection Boolean Optional. Allow to select date ranges. Default is false
previousTitle String Optional. Title of button for previous month. Default is Previous
nextTitle String Optional. Title of button for next month. Default is Next
selectedDayColor String Optional. Color for selected day
selectedDayStyle ViewStyle Optional. Style for selected day. May override selectedDayColor.
selectedDayTextColor String Optional. Text color for selected day
selectedRangeStartStyle ViewStyle Optional. Style for range selected start day.
selectedRangeEndStyle ViewStyle Optional. Style for range selected end day.
selectedRangeStyle ViewStyle Optional. Style for all days in range selection.
disabledDates Array or Function Optional. Specifies dates that cannot be selected. Array of Dates, or a function that returns true for a given Moment date (apologies for the inverted logic).
selectedStartDate Date Optional. Specifies a selected Start Date.
selectedEndDate Date Optional. Specifies a selected End Date.
minRangeDuration Number or Array Optional. Specifies a minimum range duration when using allowRangeSelection. Can either pass a number to be used for all dates or an Array of objects if the minimum range duration depends on the date {date: Moment-parsable date, minDuration: Number
maxRangeDuration Number or Array Optional. Specifies a maximum range duration when using allowRangeSelection. Can either pass a number to be used for all dates or an Array of objects if the maximum range duration depends on the date {date: Moment-parsable date, maxDuration: Number
todayBackgroundColor String Optional. Background color for today. Default is #cccccc
todayTextStyle TextStyle Optional. Text styling for today.
textStyle Object Optional. Style overall text. Change fontFamily, color, etc.
customDatesStyles Array Optional. Style individual date(s). Array of objects {date: Moment-parseable date, containerStyle: ViewStyle, style: ViewStyle, textStyle: TextStyle}
scaleFactor Number Optional. Default (375) scales to window width
minDate Date Optional. Specifies minimum date to be selected
maxDate Date Optional. Specifies maximum date to be selected
initialDate Date Optional. Date that calendar opens to. Defaults to today.
width Number Optional. Width of CalendarPicker's container. Defaults to Dimensions width.
height Number Optional. Height of CalendarPicker's container. Defaults to Dimensions height.
swipeConfig Object Optional. Config passed to Swiper.
enableSwipe Boolean Optional. Whether to enable swiping. Default is true
enableDateChange Boolean Optional. Whether to enable pressing on day. Default is true
onDateChange Function Optional. Callback when a date is selected. Returns Moment date as first parameter.
onMonthChange Function Optional. Callback when Previous / Next month is pressed. Returns Moment date as first parameter.
onSwipe Function Optional. Callback when swipe event is triggered. Returns swipe direction as first parameter.
dayShape String Optional. Shape of the Day component. Default is circle. Available options are circle and square.
headingLevel Number Optional. Sets the aria-level for the calendar title heading when on Web. Default is 1.

Styles

Some styles will overwrite some won't. For instance:

  • If you provide textStyle with fontFamily and color, out of ranges dates will not apply your color, just fontFamily.

Order of precedence:

  • defaultColor => textStyle => selectedDayColor
  • defaultTodayBackgroundColor => todayBackgroundColor
  • defaultBackgroundColor => selectedDayColor
  • defaultTextStyles => textStyle => selectedDayTextColor

Suggestions?

Open Issues. Submit PRs.

react-native-persian-calendar-picker's People

Contributors

farzadso avatar javadi69 avatar msabaeian avatar rezania1619 avatar rghorbani 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-native-persian-calendar-picker's Issues

date today does not change after 00:00

persianCalender don't update today date when is mobile clock or simulator clock after 00:00.
and when select date and check date with onDateChange date is one day ahead.

please check it.
thank's

Feature request

You would be so kind to add these features if u could.

  • Go to today button
  • Show holidays

Thank

ایراد در تغییر ماه

وقتی روز روی ۳۱ باشه و ماه بعد ۳۰ روز باشه، و روی ماه بعد تپ کنم، خطای تبدیل تاریخ میده

when edit date i want to show it in picker

i mean when i choose a date, for exp. like this-> 1397/02/01
after a few a minute i want edit it to -> 1397/02/02
but i must press many on button Previous
i want to show 1397/02/01 when before that i choose
how?
plz help me

onSwipe in rtl need chagne direction

 onSwipe(gestureName) {
    switch (gestureName) {
      case SWIPE_LEFT:
        this.handleOnPressNext();
        break;
      case SWIPE_RIGHT:
        this.handleOnPressPrevious();
        break;
    }
}

in line 191 in index need change when select rtl , I had to change the module manually

Range select while isRTL is true !

just try the situation below and watch the start and end days :))
(by the way, cool library and I'm absolutely using it in my application where I need to select a single day.)

allowRangeSelection = {true}
isRTL = {true}

selectedStartDate works strangely

Hi Mr @rghorbani
I am working on a project and I needed date picker so I used your package.
but in selectedStartDate prop I found a strange thing happening
The date picker convert the passed date to yesterday date for example if I pass "1350/6/18" to this props , the selected date in date picker would be "1350/6/17"
I checked my codes and there is no mutation or anything else
Please check this out.
This is badly stopping me.

Some props not working

HI thanks for the package. Some props like selectedDayTextColor or selectedDayColor aren't working at all...

React Native: 0.51.0
react: 16.0.0

next and previous year item

i want to next and previous icon or item show in date
can i active it?
because for show next year i must 12 click on next month... it is too bad

Throw error, when i used minDate and maxDate props.

Hi everyone.
First of all, i must say Thank you Mr. @rghorbani for publish this valuable package.
As you know, when i wrote the below code, i received :
Warning: Failed prop type: Invalid prop "minDate" of type "Date" supplied to "Days", expected instance of "jMoment".

My code is here to checkout :

class FreeTime extends Component { 
    constructor(props) {
        super(props);
        this.state = {
            date: new Date(),
            prevDay: (d => new Date(d.setDate(d.getDate() - 1)))(new Date()),
        };
        this.onDateChange = this.onDateChange.bind(this);
    }

    onDateChange(date) {
    this.setState({ date });
    }
    
    render() {
        const { date, prevDay} = this.state;
        return (
            <View style={styles.container}>
                <NavBar
                    title={'انتخاب تاریخ'}
                    icon="ios-arrow-back-outline"
                    onPress={() => console.log('21')}
                />
                <PersianCalendarPicker
                    selectedDate={date}
                    onDateChange={this.onDateChange}
                    screenWidth={Dimensions.get('window').width}
                    minDate={prevDay}
                />
        
        </View>
        );
    }
}

My goal of using minDate is that the user will not be able to choose the days before the current date.
For this problem, what should i pass to minDate props ?

Also when i want to limit user to choose only between next 7 days in react-native-persian-calendar-picker, what should i pass to maxDate props ?

Date Cells Changes

I have a problem changing the style of each cell. "CustomDatesStyles" just applies to the current day of months. How can I change the styles of all cells? I'm using this repository on react native android.

ایراد در تغییر ماه و روز

با تشکر از ساختن این کامپوننت بسیار کاربردی
ماه قبل و بعد کار نمیکنه
وقتی روی روز تپ میکنم، رنگش تغییر نمیکنه

change month on farvardin to esfand

زمانیکه ماه از فروردین به اسفند میره (کلیک روی دکمه قبلی) تاریخ رو (در متد onMonthChange) به جای یک سال دو سال عقب برمیگردونه. و همینطور اگر از اسفند بعدی بزنیم تاریخ رو دو سال بعد میده.
onMonthChange={(date)=>console.log(date)}

Wrong date output

After using onDateChange or other props for showing the current date , the output is Gregorian calendar for GMT +0000 time instead of Persian calendar
Screenshot_1556956677

use datepicker as modal

hello
how to use this calendar as modal?
if add isVisible that set true or false as props or other ways we can show/hide calendar ?

unexpected token

I got unexpected token in last version of react-native.
I copy/pasted all of your codes from here npm

screenshot_1517745990

Poor performance

This package takes too much time to load and very slow to response especially on Android.

Time is Incorrect

Hi and thank a lots
I get a problem and this is: Time
current time is 17:00 but onDateChange callback date time is 13:30!!!
How to fix this issues?

Development suggestion

Hi, I have a suggestion to add event feature

Now that all the systems are connected to the Internet, I suggest you implement the connection with the calendar APIs, in this good source as well.
I use this service a lot myself
https://apieco.ir/api/farsicalendar

Provides good information such as events by day and receive events in solar, lunar and Gregorian mode.

asyncstorage

hi
I'm in my project To take a picture https://reactnativecode.com/select-pick-image-capture-camera-gallery-react-native/ And the calendar of https://yarnpkg.com/en/package/react-native-persian-calendar-picker I use How can I save a picture with asyncstorage every day??? In fact, every day of the week the user chooses to take a specific photo or view

سلام من در پروژه ام
برای گرفتن عکس
https://reactnativecode.com/select-pick-image-capture-camera-gallery-react-native/
و تقویمم از
https://yarnpkg.com/en/package/react-native-persian-calendar-picker
استفاده می کنم
چطور می تونم با asyncstorage در هر روز مشخص یه عکس ذخیره کنم
در واقع هر روز هفته که کاربر انتخاب کرد یه عکس مشخص سیو کنه و یا ببینه
و مثلا اطلاعات روز 6مرداد با 5مرداد متفاوت باشه
ممون میشم اگه راهنماییم کنید

How to use this plugin in functional components?

Hello

As you know React native is migrating toward functional components
Examples of this plugin all have already been written in class components
It there any possibility that you provide an example in function component?

Wrong weekday!

Hello, Thanks for this good library,
Today is (سه‌شنبه 21 فروردین 1397) but library show today is (چهارشنبه 21 فروردین 1397) !
screenshot_2018-04-10-19-07-25

Installation guide

Hi, thank you for this great component, I guess you should change the installation guide on readme file.

Failed prop type: Invalid prop `customDatesStyles[0].date`

no matter what scenario I try, I keep getting this warning when trying to use customDatesStyles prop immediately after opening a modal containing react-native-persian-calendar-picker. the app functions as should. but the warning also persists.

my component:

<PersianCalendarPicker onDateChange={(value) => { this.returnDate(value) }} isRTL={true} // selectedDayStyle={{ backgroundColor: '#EAA83A'}} // selectedDayTextColor= "white" textStyle={{ fontFamily: 'iransansmobile'}} todayTextStyle={{ color: 'white'}} minDate={moment('1397/01/01', 'jYYYY/jM/jD').endOf('Day')} maxDate={moment('1400/12/29', 'jYYYY/jM/jD').endOf('Day')} weekdays={['ش','ی','د','س','چ','پ','ج']} selectedDayStyle={{backgroundColor:'#EAA83A'}} customDatesStyles={[{date: moment('1400/1/1' ,'jYYYY/jM/jD').endOf('Day'), containerStyle: {backgroundColor:'#EAA83A'},style: {}, textStyle: {}}]} previousTitle="‹" nextTitle="›" />

the error:

[Tue Apr 13 2021 13:32:22.238] ERROR Warning: Failed prop type: Invalid prop customDatesStyles[0].datesupplied toDaysGridView. in DaysGridView (at src/index.js:373) in PersianCalendarPicker (at DatePickerModal.js:58) in RCTView (at View.js:34) in View (at DatePickerModal.js:57) in RCTView (at View.js:34) in View (at createAnimatedComponent.js:165) in AnimatedComponent (at createAnimatedComponent.js:215) in ForwardRef(AnimatedComponentWrapper) (at createAnimatableComponent.js:599) in withAnimatable(View) (created by ReactNativeModal) in RCTView (at View.js:34) in View (at KeyboardAvoidingView.js:218) in KeyboardAvoidingView (created by ReactNativeModal) in RCTView (at View.js:34) in View (at AppContainer.js:106) in RCTView (at View.js:34) in View (at AppContainer.js:132) in AppContainer (at Modal.js:220) in RCTView (at View.js:34) in View (at Modal.js:242) in RCTModalHostView (at Modal.js:228) in Modal (created by ReactNativeModal) in ReactNativeModal (at DatePickerModal.js:44) in DatePickerModal (at Deadlines.js:96) in RCTView (at View.js:34) in View (at SafeAreaView.js:41) in ForwardRef(SafeAreaView) (at Deadlines.js:86) in Deadlines (created by ConnectFunction) in ConnectFunction (at SceneView.tsx:122) in StaticContainer in StaticContainer (at SceneView.tsx:115) in EnsureSingleNavigator (at SceneView.tsx:114) in SceneView (at useDescriptors.tsx:150) in RCTView (at View.js:34) in View (at CardContainer.tsx:222) in RCTView (at View.js:34) in View (at CardContainer.tsx:221) in RCTView (at View.js:34) in View (at CardSheet.tsx:33) in ForwardRef(CardSheet) (at Card.tsx:573) in RCTView (at View.js:34) in View (at createAnimatedComponent.js:165) in AnimatedComponent (at createAnimatedComponent.js:215) in ForwardRef(AnimatedComponentWrapper) (at Card.tsx:555) in PanGestureHandler (at GestureHandlerNative.tsx:13) in PanGestureHandler (at Card.tsx:549) in RCTView (at View.js:34) in View (at createAnimatedComponent.js:165) in AnimatedComponent (at createAnimatedComponent.js:215) in ForwardRef(AnimatedComponentWrapper) (at Card.tsx:544) in RCTView (at View.js:34) in View (at Card.tsx:538) in Card (at CardContainer.tsx:190) in CardContainer (at CardStack.tsx:621) in RCTView (at View.js:34) in View (at Screens.tsx:84) in MaybeScreen (at CardStack.tsx:614) in RCTView (at View.js:34) in View (at Screens.tsx:54) in MaybeScreenContainer (at CardStack.tsx:496) in CardStack (at StackView.tsx:462) in KeyboardManager (at StackView.tsx:458) in RNCSafeAreaProvider (at SafeAreaContext.tsx:74) in SafeAreaProvider (at SafeAreaProviderCompat.tsx:42) in SafeAreaProviderCompat (at StackView.tsx:455) in GestureHandlerRootView (at GestureHandlerRootView.android.js:31) in GestureHandlerRootView (at StackView.tsx:454) in StackView (at createStackNavigator.tsx:87) in StackNavigator (at App.js:126) in EnsureSingleNavigator (at BaseNavigationContainer.tsx:396) in ForwardRef(BaseNavigationContainer) (at NavigationContainer.tsx:91) in ThemeProvider (at NavigationContainer.tsx:90) in ForwardRef(NavigationContainer) (at App.js:95) in Provider (at App.js:94) in App (at renderApplication.js:45) in RCTView (at View.js:34) in View (at AppContainer.js:106) in RCTView (at View.js:34) in View (at AppContainer.js:132) in AppContainer (at renderApplication.js:39)

the screenshot:

Screenshot_2021-04-13-13-33-48

How to pic year?

Thank you very much for this great component, but is there any way of picking year?
for example to pick a date in 1365 what can I do?!

Convert persian date to gregorian

how can convert persian date to gregorian?
for example: select year for go to this year 1395,1,1
how to set exmple date for selectedStartDate

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.