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

Correct way of layouting subviews #39

Closed
danabeknar opened this issue Nov 9, 2022 · 2 comments
Closed

Correct way of layouting subviews #39

danabeknar opened this issue Nov 9, 2022 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@danabeknar
Copy link

danabeknar commented Nov 9, 2022

Hey @ekazaev!

I'm building a chat application on top of the Example project and trying to implement a view with following subviews (please see an attached image):

  1. Author label
  2. Image
  3. Reactions
  4. Date

These subviews are added as an arranged subview to a vertical UIStackView, which is added as a single subview to a let's call it MainView and used like TextMessageView or ImageView (in the example project). Another nuance is tapping on a reaction opens a reactions popup. Tapping a reaction on the popup leads to a new reaction on cell reactions, hence increasing the height and width of the cell in runtime.

Сonsidering things I said:

  1. Do you think using UIStackView the right way?
  2. What is the correct way of setting constraints where the cell has multiple views vertically and can increase dynamically?

As far as I understand I need to set the width (based on viewPortWidth) and height constraint of a subview in setupSize method, but in the example project all views (TextMessageView/ImageView/URLView) have only one subview. That's why I'm struggling with multiple vertical views.

Thank you! Let me know if you need any additional information.

example

@ekazaev
Copy link
Owner

ekazaev commented Nov 10, 2022

@danabeknar hi

Thank you for the question.

There is nothing wrong with using UIStackView if you feel that it is suitable for your case. I use them everywhere.

When it comes to reactions i would suggest to use another container view above ImageView or what ever where you allocate your reactions if you have some. And if youll call the reload of such cell - the new size will be calculated using autolayout and cell will expand. Set all the constraints like it is a normal view. You may need to use viewPortWidth to limit your internal views correctly. The reason behind is that the cell doesn’t know where it appears but it has to tell the collection layout its preferred size. For example for textview such constraint needs to be set so it breaks the line at the right place. There is no such requirement for vertical constraint.

Here is an example from one of the apps that is using ChatLayout. The reply and the reaction are actually placed in a container view above text view. So such container view can be reused with other type of cells like image view.

C491DD21-38D6-4A7E-B5CD-F8840D17B81E

FullSizeRender.MOV

@ekazaev ekazaev self-assigned this Nov 10, 2022
@ekazaev ekazaev added the question Further information is requested label Nov 10, 2022
@ekazaev
Copy link
Owner

ekazaev commented Nov 14, 2022

@danabeknar I close this issue. Feel free to reopen if you need more info about this case

@ekazaev ekazaev closed this as completed Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants