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

Automatic Scroll #2

Open
Ahmed-Masoud opened this issue Mar 19, 2020 · 5 comments
Open

Automatic Scroll #2

Ahmed-Masoud opened this issue Mar 19, 2020 · 5 comments

Comments

@Ahmed-Masoud
Copy link

I have my token field with fixed height is there a way to make it scroll automatically when new lines is added so the last thing inserted is the visible thing and thankns

@tadejr
Copy link
Owner

tadejr commented Apr 6, 2020

The token field does have an internal collection view, but currently expects to grow as needed. You should try adding it to a parent scroll view, and limiting the scroll view's height. You can then scroll the parent scroll view to bottom if needed after adding tokens, or when token field invokes the resizingTokenFieldWill/DidChangeIntrinsicHeight callback.

@Ahmed-Masoud
Copy link
Author

Ahmed-Masoud commented May 7, 2020

since the collection view is private so this is how i worked around it I hope you can implement it in the pod or expose the collection view
I loop on the subviews to hold a refrence on the collection view which is the only subview
tokenField.subviews.forEach { (view) in if let collectionView = view as? UICollectionView { tagsCollectionView = collectionView } }
then after adding any token i scroll to the last element
tokenField.append(tokens: tags, animated: true) let lastItemIndex = NSIndexPath(item: tokenField.tokens.count + 1, section: 0) tagsCollectionView?.scrollToItem(at: lastItemIndex as IndexPath, at: .bottom, animated: true)

@NallapatiMalleswari
Copy link

@Ahmed-Masoud , I have the same issue, while using your solution I am facing problem with "tagsCollectionView". can you help in this, where you did this and what is tagsCollectionView. I am rounding with this issue from past two day.
Thank you.

@Ahmed-Masoud
Copy link
Author

Ahmed-Masoud commented Nov 5, 2021

@NallapatiMalleswari
What I did in details is

  1. I initialized an optional UIVollectionView named tagsCollectionView
  2. In viewWillAppear I hold a reference to the internal collection view in the tokenField as so where token field is of type ResizingTokenField
tokenField.subviews.forEach { (view) in if let collectionView = view as? UICollectionView { tagsCollectionView = collectionView } }
  1. Whenever I want to add new item in the tokenField I add it like this
tokenField.append(tokens: tags, animated: true) 
let lastItemIndex = NSIndexPath(item: tokenField.tokens.count + 1, section: 0) 
tagsCollectionView?.scrollToItem(at: lastItemIndex as IndexPath, at: .bottom, animated: true)

@NallapatiMalleswari
Copy link

@Ahmed-Masoud, works for me.

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

No branches or pull requests

3 participants