Esempio n. 1
0
        private void changeOffset(CGPoint point)
        {
            if (!isActive || itemIndexPath == null)
            {
                return;
            }

            var currentPointWithOffest = new CGPoint(point.X, point.Y - verticalOffset);

            var newStartTime = NewStartTimeWithStaticDuration(currentPointWithOffest, allItemsStartAndEndTime, calendarItem.Duration);

            LastPoint = point;
            var now = timeService.CurrentDateTime;

            if (newStartTime + calendarItem.Duration > newStartTime.Date.AddDays(1))
            {
                return;
            }

            calendarItem = calendarItem
                           .WithStartTime(newStartTime);

            itemIndexPath = dataSource.UpdateItemView(itemIndexPath, calendarItem.StartTime, calendarItem.Duration(now));

            if (previousStartTime != newStartTime)
            {
                selectionFeedback.SelectionChanged();
                previousStartTime = newStartTime;
            }

            var topY    = Layout.PointAtDate(calendarItem.StartTime).Y;
            var bottomY = Layout.PointAtDate(calendarItem.EndTime(now)).Y;

            if (topY < TopAutoScrollLine && !CollectionView.IsAtTop() && didDragUp)
            {
                StartAutoScrollUp(changeOffset);
            }
            else if (bottomY > BottomAutoScrollLine && !CollectionView.IsAtBottom() && didDragDown)
            {
                StartAutoScrolDown(changeOffset);
            }
            else
            {
                StopAutoScroll();
            }
        }
        private void changeOffset(CGPoint point)
        {
            if (!isActive || itemIndexPath == null)
            {
                return;
            }

            if (Math.Abs(LastPoint.Y - point.Y) < CalendarCollectionViewLayout.HourHeight / 4)
            {
                return;
            }

            LastPoint = point;
            var startPoint = new CGPoint(LastPoint.X, LastPoint.Y - verticalOffset);
            var startTime  = Layout.DateAtPoint(startPoint).ToLocalTime().RoundDownToClosestQuarter();

            if (startTime + calendarItem.Duration > startTime.Date.AddDays(1))
            {
                return;
            }

            calendarItem = calendarItem
                           .WithStartTime(startTime);

            itemIndexPath = dataSource.UpdateItemView(itemIndexPath, calendarItem.StartTime, calendarItem.Duration);
            selectionFeedback.SelectionChanged();

            var topY    = Layout.PointAtDate(calendarItem.StartTime).Y;
            var bottomY = Layout.PointAtDate(calendarItem.EndTime).Y;

            if (topY < TopAutoScrollLine && !CollectionView.IsAtTop() && didDragUp)
            {
                StartAutoScrollUp(changeOffset);
            }
            else if (bottomY > BottomAutoScrollLine && !CollectionView.IsAtBottom() && didDragDown)
            {
                StartAutoScrolDown(changeOffset);
            }
            else
            {
                StopAutoScroll();
            }
        }