Glow-Inc / GLCalendarView

A fully customizable calendar view acting as a date range picker
MIT License
855 stars 106 forks source link

Ranges turn into single selections #31

Open wilkinnh opened 8 years ago

wilkinnh commented 8 years ago

screenshot 2016-09-12 10 20 07

Not sure how to describe this, but sometimes the range shows correctly, and sometimes it shows up like the attached screenshot. I also noticed that if the range looked correct, then I scrolled the range off the screen, then scrolled back, some of these symptoms also showed up. Any thoughts?

ltebean commented 8 years ago

Make sure all the calls to the calendar api are in the main thread

wilkinnh commented 8 years ago

Yup, all calls are on the main thread. I'm not doing anything terribly complex, just setting a couple ranges and scrolling. Is anyone else seeing this issue?

ltebean commented 8 years ago

Can you share me the code so I can check what's wrong with it.

wilkinnh commented 8 years ago

Sure, thanks for the help! A good portion of this is boilerplate code I took from the example, and then I added some pre-defined ranges.

`- (void)viewDidLoad { [super viewDidLoad];

self.calendarView = ({
    GLCalendarView *calendarView = [[GLCalendarView alloc] initWithFrame:CGRectZero];
    calendarView.firstDate = [[NSDate datesForCurrentWeek] firstObject];
    calendarView.lastDate = [calendarView.firstDate dateByAddingTimeInterval:TimeIntervalDay * 365];
    calendarView.delegate = self;

    [self.view addSubview:calendarView];

    [calendarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_topLayoutGuide);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.mas_bottomLayoutGuide);
    }];

    [calendarView layoutIfNeeded];
    [calendarView setNeedsLayout];

    NSInteger screenWidth = self.view.bounds.size.width;
    CGFloat paddingAll = screenWidth % 7 + 7;
    [GLCalendarView appearance].rowHeight = (screenWidth - paddingAll) / 7 + 3;
    [GLCalendarView appearance].padding = paddingAll / 2;

    [GLCalendarView appearance].weekDayTitleAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:8], NSForegroundColorAttributeName:[UIColor grayColor]};
    [GLCalendarView appearance].monthCoverAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:30]};

    [GLCalendarDayCell appearance].dayLabelAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20], NSForegroundColorAttributeName:[UIColor colorWithHex:@"555555"]};
    [GLCalendarDayCell appearance].monthLabelAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:8]};

    [GLCalendarDayCell appearance].editCoverBorderWidth = 1;
    [GLCalendarDayCell appearance].editCoverBorderColor = [UIColor colorWithHex:@"366aac"];
    [GLCalendarDayCell appearance].editCoverPointSize = 14;

    [GLCalendarDayCell appearance].todayBackgroundColor = [UIColor colorWithHex:@"366aac"];
    [GLCalendarDayCell appearance].todayLabelAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20]};

    [GLCalendarDayCell appearance].rangeDisplayMode = RANGE_DISPLAY_MODE_CONTINUOUS;

    if (self.program)
    {
        GLCalendarDateRange *range = [[GLCalendarDateRange alloc] init];
        range.beginDate = self.program.startDate;
        range.endDate = self.program.endDate;
        range.backgroundColor = [RLNavStyles defaultBackgroundColor];
        range.editable = NO;

        [calendarView addRange:range];

        [calendarView scrollToDate:self.program.startDate animated:NO];

        self.selectedRange = range;
    }

    for (RLProgram *scheduledProgram in self.session.programManager.scheduledPrograms)
    {
        if ([scheduledProgram.subID isEqualToString:self.program.subID] == NO)
        {
            GLCalendarDateRange *range = [[GLCalendarDateRange alloc] init];
            range.beginDate = scheduledProgram.startDate;
            range.endDate = scheduledProgram.endDate;
            range.backgroundColor = [[RLColorStyleKit prologueBlue01] colorWithAlphaComponent:0.2];
            range.editable = NO;

            [calendarView addRange:range];
        }
    }

    calendarView;
});

}`

ltebean commented 8 years ago

Did you call [calenderView reload] in viewWillAppear? And remove these two lines in viewDidLoad

 [calendarView layoutIfNeeded];
 [calendarView setNeedsLayout];
wilkinnh commented 8 years ago

No, I did not have [calendarView reload] in viewWillAppear, but I added it and I can still see the issue.

Regarding taking out those lines, if I remove them I get a crash:

*\ Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'negative sizes are not supported in the flow layout'

Just based on the behavior, this looks like this might be a cell reuse issue. Any other thoughts?