Giter Club home page Giter Club logo

reactnativecalendarandroid's Introduction

react-native-calendar-android

A simple material-themed calendar for react native android

Demo Screen Capture

Installation Android

  1. npm install --save react-native-calendar-android

Note: Since [email protected], you should use [email protected] and above

  1. In android/settings.gradle

    ...
    include ':ReactNativeCalendarAndroid', ':app'
    project(':ReactNativeCalendarAndroid').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-calendar-android/android')
  2. In android/app/build.gradle

    ...
    dependencies {
        ...
        compile project(':ReactNativeCalendarAndroid')
    }
  3. Register module (in MainActivity.java)

    4.1. With RN < 0.19.0

     ```java
     import com.chymtt.reactnativecalendar.CalendarPackage; // <----- import
    
     public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
       ......
    
       @Override
       protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         mReactRootView = new ReactRootView(this);
    
         mReactInstanceManager = ReactInstanceManager.builder()
           .setApplication(getApplication())
           .setBundleAssetName("index.android.bundle")
           .setJSMainModuleName("index.android")
           .addPackage(new MainReactPackage())
           .addPackage(new CalendarPackage())              // <------ add here
           .setUseDeveloperSupport(BuildConfig.DEBUG)
           .setInitialLifecycleState(LifecycleState.RESUMED)
           .build();
    
         mReactRootView.startReactApplication(mReactInstanceManager, "ExampleRN", null);
    
         setContentView(mReactRootView);
       }
       ......
     }
     ```
    

    4.2. With RN >= 0.19.0

     ```java
     import com.chymtt.reactnativecalendar.CalendarPackage; // <----- import
    
     public class MainActivity extends ReactActivity {
         ...
    
         @Override
         protected List<ReactPackage> getPackages() {
           return Arrays.<ReactPackage>asList(
             new MainReactPackage(),
             new CalendarPackage() // <------ add here
           );
         }
     }
     ```
    

Usage

var Calendar = require('react-native-calendar-android');
...

  render() {
    return (
      <Calendar
          width={300}
          topbarVisible={true}
          arrowColor="#dafacd"
          firstDayOfWeek="monday"
          showDate="all"
          currentDate={[ "2016/12/01" ]}
          selectionMode="multiple"
          selectionColor="#dadafc"
          selectedDates={[ "2015/11/20", "2015/11/30", 1448745712382 ]}
          onDateChange={(data) => {
            console.log(data);
          }} />
    );
  }

Notes

The view is a grid with 7 tiles wide and 8 tiles high (with topbarVisible=true), or 7 tiles high (with topbarVisible=false)

The size of each tile is automatically calculated based on the provided width.

Props

int width (required)

Provide the width of the calendar. The height will be calculated based on width and topbarVisible.

boolean topbarVisible (default = true)

Show/hide the top bar which contains the month's title and arrows to go to previous or next months.

string arrowColor

A string color in the format #RRGGBB or #AARRGGBB. It changes color of the top bar's arrows accordingly.

enum firstDayOfWeek (default = 'sunday')

enum [ 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' ]

Set the first day of the week.

enum showDate (default = 'current')

enum [ 'all', 'current' ]

If set to current, only show dates within current month. If set to all, show dates from previous and current months too.

array currentDate

Set the focus of the calendar. Due to some limitations, you must provide an array with only one element, which is the currentDate. currentDate can be a string in the format yyyy/mm/dd or a timestamp.

enum selectionMode (default = 'single')

enum [ 'none', 'single', 'multiple' ]

Set the selection mode.

  • none: you cannot select date
  • single: you can only select one date at a time
  • multiple: you can select multiple dates

string selectionColor

Set the color of the selection circle. Should be a color in the format #RRGGBB or #AARRGGBB.

array selectedDates

An array of dates in the format yyyy/mm/dd or timestamp. Set the selected dates on the calendar.

Event

onDateChange(data)

Called when user select/deselect a date. The returned data is { date: 'yyyy/mm/dd', selected: boolean }

Questions or suggestions?

Feel free to open an issue Pull requests are also welcome

Credit

Big thanks to @prolificinteractive for their awesome Material Calendar View

reactnativecalendarandroid's People

Contributors

chymtt avatar sevenswen avatar vond 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

Watchers

 avatar  avatar  avatar

reactnativecalendarandroid's Issues

Make it invisible

Only when user click on textbox, then it may show the calendar. I wonder the current ReactNativeCalendarAndroid can do so.

Properties don't seem to be having an effect

It looks like setting properties like selectionColor etc does not take effect. I have the following Calendar component

<Calendar
          width={300}
          topbarVisible={true}
          arrowColor="#dafacd"
          firstDayOfWeek="monday"
          showDate="all"
          currentDate={[ "2016/02/03" ]}
          selectionMode='none'
          selectionColor="#FF0000"
          selectedDates={[ '2016/02/01']} />

However as can be seen from the screenshot below, none of those seem to be having an effect (e.g selectionColor is Green instead of FF0000 (red) and the arrowColor is not light green, but black.

Any ideas on how to fix this ?

screen shot 2016-02-13 at 1 46 52 am

Issue with only seeing red border

So I have an exact issue as this guy: http://stackoverflow.com/questions/34897521/react-native-android-calendar-wont-load

I'm using react 0.19.0.

I'm also not sure about where to override the onCreate method. There is in fact a MainActivity.java but there is no onCreate method inside yet. I've just put the whole chunk of code inside for now.

edit: console throws this:

W/ReactNativeJS( 3598): Warning: Native component for "Calendar" does not exist

Help would be appreciated,

Sincerely, Jan

Does not compile - react-native: 0.45.+

Sorry for my english, I use google translate

I'm using:
"React": "16.0.0-alpha.12",
"React-native": "0.45.1",

And when installing this component, use react-native link and when launching the simulator, I get the following error:

A problem occurred configuring project ':ReactNativeCalendarAndroid'.

Could not resolve all dependencies for configuration ':ReactNativeCalendarAndroid:_debugPublishCopy'.
Could not find any version that matches com.facebook.react:react-native:0.32.+.
Versions that do not match:
0.20.1
0.20.0
0.19.1
0.19.0
0.18.0
+ 13 more
Required by:
AwesomeProject:ReactNativeCalendarAndroid:unspecified

Is this component obsolete? Do you support? I see that it has not been updated for a long time. Any help would be appreciated

Screenshots Please

May you please add screenshots (ideally GIF) of this in action in readme? There is a link right now but its broken.

selectedDates change does not clear old selected dates

Hi,

Thanks for the lib!
Updating the array of selected dates sets the new dates as selected, but does not clear the old ones that are no longer present in the array.
That's really not intuitive in a React context, where you'd expect the selected dates to always mirror the prop and to not depend on a previous state.
I can submit a PR if you're ok to change that API.

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.