Parchment icon indicating copy to clipboard operation
Parchment copied to clipboard

Select paging item + scroll to item

Open Myste1 opened this issue 6 years ago • 5 comments

Hey!

Two questions/feedbacks :)

In the readme, about the "Selecting items" section, you mention :

override func viewDidLoad() { super.viewDidLoad() if let first = pagingViewController.items.first { pagingViewController.select(pagingItem: first) } }

But it seems there isn't a property "items". The property seems to be accessible only from the dataSource property. Or do I'm missing something ?

My second point is about another problem. I'm using Parchment with a side menu. When I change from "option A" to "option B" in my menu, the parchment collection focus is not resetted to the default item selected in the B parchment collection. The collection is still on the previous position selected in "menu A". Not easy to explain :) (If in "option B", I choose the last item in the menu which is at position 15 for exemple, when I'm going to "option A" having the first item selected, I don't see it. The collectview A is still at the same position it was with "option B")

I don't find a way to be able to "scroll" directly to the current item selected. I saw there is the option "select", but it doesn't work if the item is already selected. Is there another solution ? Or maybe I'm missing something again ? :D

Thanks for your help !

Myste1 avatar Apr 27 '20 11:04 Myste1

Btw, the only way seems to do :

self.pagingViewController.collectionView.scrollToItem(at: IndexPath(index: 0), at: .left, animated: true)

To be able to scroll the menu to an item already selected.

Myste1 avatar Apr 27 '20 11:04 Myste1

Hi @Myste1. Looks like the documentation is wrong. The items are available under the visibleItems property. E.g:

if let first = pagingViewController.visibleItems.items.first {
    pagingViewController.select(pagingItem: first)
}

Regarding the other issue you are having, I'm not sure I understand exactly. Is the problem that the collection view doesn't scroll to the selected item when using the select(pagingItem:) method? Do you have some code examples you could share?

rechsteiner avatar Jun 01 '20 11:06 rechsteiner

Hi,

Yep it should be nice to change the doc about that :)

Regarding the other issuee, the code will not help I think. I should record the problem but I can't do it bc it's a private app :/

Maybe I can describe the issue in another way:

  • If my first item is selected, but I scroll to the last item on the paging and so I don't see anymore the first item selected. Is there any method to be able to focus again on the first item ?

I just find this "trick" to do it : "self.pagingViewController.collectionView.scrollToItem(at: IndexPath(index: 0), at: .left, animated: true)"

Myste1 avatar Jun 02 '20 07:06 Myste1

Do you have a lot of items in the menu? The visibleItems property will only contain the items that are currently on the screen, so that might be the problem you're having. Have you tried using the select(index:) method? If you're using the infiniteDataSource you can't use that method, but you can select the first paging item by creating the actual PagingItem struct you're using and selecting that. E.g. select(pagingItem: PagingTitleItem(title: "View 0", index: 0). Does that work for you?

rechsteiner avatar Jun 06 '20 12:06 rechsteiner

Ok, I didn't know the method "select(index:)" was not available for infiniteDataSource. Maybe it should be specificied in the method description ?

Otherwise, I'm using PagingViewControllerDataSource and it doesn't work :/ But I checked quickly in the func select(pagingItem: PagingItem, animated: Bool) method and it seems you're are trying to use "visibleItems" in the method. So, if this property contains only the items on the screen, maybe it should be the problem and explain why I can't scroll on my first item which is not visible anymore ?

Btw, thank you for the lib, it's really helpful.

Myste1 avatar Jun 08 '20 07:06 Myste1

Hey @Myste1! I'm not sure when this was fixed, but it seems like it's now possible to select items that are not visible on the screen, so I will just close this one. I've updated the calendar example to illustrate your use-case

rechsteiner avatar Apr 07 '23 09:04 rechsteiner