Code Monkey home page Code Monkey logo

Comments (5)

nuno-vieira avatar nuno-vieira commented on June 30, 2024

Hi @srgray,

Yes, that is normal, unfortunately. Since our Message List is an inverted UITableView and not a UICollectionView, embedding self-resizing collection views won't work very well. Although it might be possible to build that UI with some workarounds. You can try the following:

  1. If possible, use a UIStackView. If you are not expecting many tags per message, this could be enough, and the performance penalty of using a stack view won't be noticeable.
  2. The other option is to find a way to explicitly reload the cell whenever the tags grow to a specific size. One idea is to override the ChatMessageListView.reuseIdentifier() function which is the one responsible for calculating the cell identifier based on the ChatMessageLayoutOption and the message content. You could use the tags.countand post-fix the cell identifier to make sure that whenever the tags change, it reloads the cell 🤔

The pseudo code for 2:

class CustomMessageListView: ChatMessageListView {
    override func reuseIdentifier(
        contentViewClass: ChatMessageContentView.Type,
        attachmentViewInjectorType: AttachmentViewInjector.Type?,
        layoutOptions: ChatMessageLayoutOptions,
        message: ChatMessage?
    ) -> String {
        var identifier = super.reuseIdentifier(
            contentViewClass: contentViewClass,
            attachmentViewInjectorType: attachmentViewInjectorType,
            layoutOptions: layoutOptions,
            message: message
        )
        if message.tags.count > 0 {
            identifier += "_\(message.tags.count)"
        }
        return identifier
    }
}

Let us know if you were able to find a workaround for this.

Best,
Nuno

from stream-chat-swift.

nuno-vieira avatar nuno-vieira commented on June 30, 2024

@srgray We have a similar UI in our Slack Example App. We use a collection view there, but we have a height constraint that we change depending on the number of reactions.

The code:

This works best whenever the collection view has a predictable number of items per row since we can do this to calculate the height constraint:

let numberOfItemsPerRow = 3
let numberOfRows = Double(reactions.count).truncatingRemainder(dividingBy: numberOfItemsPerRow)
heightConstraint?.constant = ceil(numberOfRows) * reactionRowHeight

But yeah, these use cases are a bit tricky when working with a UITableView, unfortunatly it is a short-coming of our Message List at the moment, and solving it completely would require refactoring it to a UICollectionView, which we are not planning to do at the moment.

Best,
Nuno

from stream-chat-swift.

nuno-vieira avatar nuno-vieira commented on June 30, 2024

Hi @srgray,

Did one of the solutions provided work for you? If yes, which option did you choose?

Best,
Nuno

from stream-chat-swift.

nuno-vieira avatar nuno-vieira commented on June 30, 2024

Hey @srgray,

I'm closing this for now. Feel free to reply and re open it in case you are still having problems or want to share your solution.

Best,
Nuno

from stream-chat-swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.