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

How can I get specific eventView without any gesture? #329

Open
qubyedev opened this issue Jan 19, 2022 · 7 comments
Open

How can I get specific eventView without any gesture? #329

qubyedev opened this issue Jan 19, 2022 · 7 comments

Comments

@qubyedev
Copy link

Hi,

I'd like to know is there anyway to get specific eventview without any gesture such as tap or longpress?

The scerino will be I get a data from server, then i want to find the event match the data, and show a popover with the eventview's source rect. So the whole workaround will not have any user interaction.

@richardtop
Copy link
Owner

No, there is no currently support for such a functionality.
I've marked it as an enhancement.

If you wish to implement it yourself, please add the following API to the DayView:

func eventViewFor(eventDescriptor: EventDescriptor) -> EventView {
/// Ask a lower layer for the EventView:
/// DayView -> TimelinePager -> Timeline -> Implement the algorithm on the Timeline class
}

@qubyedev
Copy link
Author

Hi @richardtop , after checking it, i dont really get it.

After implement the func in TimelineView.shift, how can I use it from viewcontroller?

@richardtop
Copy link
Owner

Hi, yes, you'll need to propagate the the call from the DayViewController to the TimelineView.

So, add this functionality to the DayViewController first, then it should call the DayView (you can even use the same method signature). The DayView should call TimelinePagerView and it in turn should call the TimelineView thru the TimelineContainer.

Then you just return the result back up the chain.

Please, submit a pull request to the library, I'm interested in having this functionality integrated.

@qubyedev
Copy link
Author

Hi @richardtop , thanks a lot!!
It did work 🥳🥳🥳

I'd like to submit a pull request, but I fork this project from last Octobor and I have modified a lot.
So I will find time to fork again and add just this func then submit.

Thank you again, you save my day!

@richardtop
Copy link
Owner

I've looked at your implementation, I see a few issues:

  • EventDescriptor is required to be an Object type, i.e. have an identity semantic
  • In your code you're simply comparing some properties of the EventDescriptor you're passing to the other properties of the EventDescriptor stored in the EventView.

This might not always work.

I suggest you changing the code to the following:

  • either compare that it's the same instance (I recommend this one): use === operator
  • Or just make EventDescriptor conform to Equatable and use the equality operator to find the associated EventView.

Why the 1st way is preferred? Because the EventDescriptor is meant to have a direct relationship to the EventView. i.e. a single descriptor is attached to a single view. I think, it's even possible to add a view property onto a descriptor, to be set by the library when a view has been attached.

So, the descriptor is not a value type but actually a direct reference used & edited by the library.

@qubyedev
Copy link
Author

I just tried to modify the code like in below and it always return nil, did I get it wrong?

func eventViewFor(eventDescriptor: EventDescriptor) -> EventView?{
//        for eventView in eventViews{
//            if eventView.descriptor?.startDate == eventDescriptor.startDate &&
//                eventView.descriptor?.endDate == eventDescriptor.endDate &&
//                eventView.descriptor?.titleText === eventDescriptor.titleText &&
//                eventView.descriptor?.timeText == eventDescriptor.timeText {
//                    return eventView
//            }
//        }
        
        for eventView in eventViews{
            if eventView.descriptor === eventDescriptor{
                return eventView
            }
        }
        return nil
    }

@richardtop
Copy link
Owner

No, the code is OK. but are you returning the same descriptor as you've used in the eventsForDate method? It not only has to be the same model, but actually the same instance you've passed in that method.

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

No branches or pull requests

2 participants