Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View for notification #122

Closed
grosch opened this issue Dec 24, 2017 · 10 comments
Closed

View for notification #122

grosch opened this issue Dec 24, 2017 · 10 comments
Labels

Comments

@grosch
Copy link
Contributor

grosch commented Dec 24, 2017

This looks like an awesome library. Is there a way to customize the view so it just shows the time around a specific timeframe? I'd like to use this in a custom UI for a rich push notification but obviously I don't want to show the whole day, just a couple hours before and after the event that's pushed to the user.

@richardtop
Copy link
Owner

Hi @grosch,

CalendarKit was meant to be a set of separate modules, so you could use it to create your own UI components.

For your task, I'd recommend using just TimelineView, it should serve the purpose perfectly.

If you'd like to have a higher-level abstraction over TimelineView, you may wrap it into TimelineContainer to support scrolling to specific hour or the first event.

@grosch
Copy link
Contributor Author

grosch commented Dec 25, 2017

Thanks, @richardtop. Could you give a bit more of a specific example please? I'm looking at TimeLineView and none of the stuff in there is public so I'm not sure how to use this by itself.

@richardtop
Copy link
Owner

At first, I recommend you taking a look at the "parent" view, i.e. TimelinePagerView. The method important for us is updateTimeline:

  func updateTimeline(_ timeline: TimelineView) {
    guard let dataSource = dataSource else {return}
    let date = timeline.date.dateOnly()
    let events = dataSource.eventsForDate(date)
    let day = TimePeriod(beginning: date,
                         chunk: TimeChunk.dateComponents(days: 1))
    let validEvents = events.filter{$0.datePeriod.overlaps(with: day)}
    timeline.eventDescriptors = validEvents
  }

The last line shows, how the information in form of [EventDescriptor] is passed to the Timeline.

Also, you'll need to position your view in the parent view, i.e. set it's frame's y to some arbitrary number:

let hourToScroll = 18 // Scroll to 18:00
let fullHeight = timeline.fullHeight
let yOffset = fullHeight * hourToScroll/24
timeline.frame = CGrect(x: 0, y: yOffset, width: ...., height: ...)

@grosch
Copy link
Contributor Author

grosch commented Dec 26, 2017

Thanks. Still not there though. Everything seems to be internal variables. I can put a TimelinePagerView on my screen and it draws fine. However, updateTimeline wants to use the internal timeline variable to get the internal date variable so I can't actually set what the date is that I'm looking at.

@grosch
Copy link
Contributor Author

grosch commented Dec 26, 2017

Is there any chance you can just provide an example view controller that displays a day view set to a specific date with some events?

@richardtop
Copy link
Owner

richardtop commented Dec 26, 2017

I'll send you an example in a moment.
One important note: as what you're trying to achieve is not a "standard" iOS calendar, so you are free to change access modifiers and make them public instead of internal

@richardtop
Copy link
Owner

@grosch I've added example in #126
It looks like this:
image

You may want to tweak the library to meet specific requirements. Feel free to change it and open a pull request.

@grosch
Copy link
Contributor Author

grosch commented Dec 26, 2017

Thanks! Please remember to update the cocoapod as well. It's still pulling 0.2.1

@richardtop
Copy link
Owner

Done. Feel free to close this issue, if you don't have other questions related to the Notification view.

@grosch
Copy link
Contributor Author

grosch commented Dec 26, 2017

Thanks much. I've almost got this working now. Might need to make a couple more things public, like is24hClock. I'll open a new item on what I'm finding though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants