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

'updateTag' Method not reacting as like before #137

Open
Karahan00 opened this issue Apr 2, 2023 · 2 comments
Open

'updateTag' Method not reacting as like before #137

Karahan00 opened this issue Apr 2, 2023 · 2 comments

Comments

@Karahan00
Copy link

Karahan00 commented Apr 2, 2023

Hey,

our App includes the TTGTagCollectionView. We are fetching user data from our backend. For this example "extras" which are selected for an object. And after that we are "searching" and "selecting" the tags which belongs the "id" from that one element which returned from our backend. This worked every time fine and we don't changed anything in this function.

What we have checked:

  1. Does our backend retrive the correct data? --> YES
  2. Does the update tag Method from the TTGTextTagCollection reacting to the call and change the color for that one tag? --> NO
  3. Does the Pod have any new updates in recent time? - YES
  4. Updated ? currently on Version 2.4.1--> YES

Here you can see some code instructions from us how we are iterate for each data and update the tag on that specific tag index position. But the tags still stay on our default "Gray" Color:

  1. This function builds all available tags in our collection view. So that means we are building a TAG for each available data entry which is selectable:

`
func buildTagsForProductExtras() {

    self.productExtraSelectorCollectionView.removeAllTags()
    
    for productExtra in fetchedCardExtras {
        let itemPrice = String(format: "%.2f", productExtra.price).replacingOccurrences(of: ".", with: ",") + " €"
        let textForTag = productExtra.name + " " + itemPrice
        let content = TTGTextTagStringContent.init(text: textForTag)
        content.textColor = .white
        content.textFont = UIFont(name: "Poppins-Regular", size: 15)!
        
        let normalStyle = TTGTextTagStyle.init()
        normalStyle.backgroundColor = CustomColor.lightGray
        normalStyle.cornerRadius = 25
        normalStyle.borderColor = .clear
        normalStyle.extraSpace = CGSize.init(width: 20, height: 20)
        
        let selectedStyle = TTGTextTagStyle.init()
        selectedStyle.backgroundColor = CustomColor.orange
        selectedStyle.cornerRadius = 25
        selectedStyle.borderColor = .clear
        selectedStyle.extraSpace = CGSize.init(width: 20, height: 20)
        
        let tag = TTGTextTag.init()
        tag.content = content
        tag.style = normalStyle
        tag.selectedStyle = selectedStyle
        
        productExtraSelectorCollectionView.addTag(tag)
    }
    
    productExtraSelectorCollectionView.reload()
    
}`
  1. This function is called after we are retrive the "already" selected options from the user. That function is gonna used to iterate for every selected data:

`
func searchAndSelectProductExtraTags() {

    self.selectedCardExtras.forEach { selectedCardExtra in
        
        // Define and get the correct index for our area which we are sarching
        let indexForKey = getIndexForSelectedCardExtra(forKey: selectedCardExtra.key)
            // We detected an element which is selected
            let itemPrice = String(format: "%.2f", selectedCardExtra.price).replacingOccurrences(of: ".", with: ",") + " €"
            let textForTag = selectedCardExtra.name + " - " + itemPrice
            let content = TTGTextTagStringContent.init(text: textForTag)
            content.textColor = UIColor.white
            content.textFont = UIFont(name: "Poppins-Regular", size: 15)!
            
            let normalStyle = TTGTextTagStyle.init()
            normalStyle.backgroundColor = CustomColor.lightGray
            normalStyle.cornerRadius = 25
            normalStyle.borderColor = .clear
            normalStyle.extraSpace = CGSize.init(width: 20, height: 20)
            
            let selectedStyle = TTGTextTagStyle.init()
            selectedStyle.backgroundColor = CustomColor.orange
            selectedStyle.cornerRadius = 25
            selectedStyle.borderColor = .clear
            selectedStyle.extraSpace = CGSize.init(width: 20, height: 20)
            
            let newTag = TTGTextTag.init()
            newTag.selected = true
            newTag.content = content
            newTag.style = normalStyle
            newTag.selectedStyle = selectedStyle
            
            // Update the area tag on that position which returned from the fetched area array
            productExtraSelectorCollectionView.updateTag(at: UInt(indexForKey), withNewTag: newTag)
           
    }
    
}`

So something is happening here because as I said above this method worked really fine. We also have compared our versions and the currently stable version works fine. The new version which we are currently developing are not working fine anymore. We don't have any changes at this point.

Please provide us an Instruction what we are doing wrong and could do better.

Best regards

@Karahan00
Copy link
Author

Update of Informations

So after debugging for like 2 Hours I got an Idea to "getAllSelectedTags" from the Collection. And whoala the tags which are updated before with the "selectedContent" are there. So the implementation above works fine as like before. The only problem is that the state doesn't change.

So I have tried some more things until I found out that the "updateTag" Method does not change the state instantly anymore. So the solution at this point was only to call "tagCollectionView.reload()" at the and of the loops 😄. So easy.

I think the Issue could be closed at this point. But maybe the creator of this beautiful library want to give a look at the "updateTag" - Method if there are some more changes made which could effect some other points.

Best regards !

@zekunyan
Copy link
Owner

zekunyan commented Apr 3, 2023

Thanks for the suggestion, I will double check the code logic.

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

2 participants