-
Notifications
You must be signed in to change notification settings - Fork 97
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
Problem with UILabel text wrapping the view's intrinsic width in an expression. #150
Comments
@Dragonspell99 it looks like a bug - I'll investigate. In the meantime, it works if you use <UIView
left="24"
top="24"
width="320"
height="auto">
<UILabel
backgroundColor="#CCC"
width="min(auto, 100%)"
numberOfLines="0"
text="This text is to verify line wrapping when using an expression that contains the auto keyword."
/>
</UIView> |
@nicklockwood Thanks for the prompt reply! I've tested your suggestion and it works great. Unfortunately, I'm having trouble applying it to my desired layout. I simplified the code example above to focus on the problem but in my real layout, I already have the UILabel wrapped by a UIView whose width depends on its children. Therefore, I can't set it to a fixed width and trying to reference it otherwise in the child's width expression will result in a circular reference. What I'm trying to achieve is a layout where I'm showing a chat bubble next to a user's profile picture. The bubble would be a rounded rectangle (wrapping view) with a grey background that contains the user's name (top label) followed by the message text. The bubble has to grow to wrap both the user name and message. I'm including a larger piece of the layout code below to see if an easy fix jumps out at you. Otherwise, I can try to fix it by measuring the string in code and passing the measured width as a parameter to the layout to be used in the expression.
P.S.> Great job on the library! I've been looking for something like Layout for a long time and stumbled upon it by chance the other day. |
@Dragonspell99 as far as I can see, there's no way to do this with the current release. I've pushed a fix to the develop branch that should make it work as you've written it above. Can you try it out and see if it solves your use-case? |
I've tested the changes that you pushed to the develop branch and it works perfectly for my use case. Thanks! |
@Dragonspell99 great. I'll do some more testing and assuming everything's OK with the other test projects I'll push a release with those changes asap. |
Hi @nicklockwood , Although the above problem was resolved with the commit that you pushed to address the issue, I have found another interesting case that is related to the same layout so I've included it in this same issue. Context: As described previously, this layout is for a "chat bubble". I'm trying to add the time at which the message was posted in the upper right corner of the bubble along with an icon of a clock adjacent and to the left of the time. Aligning the UILabel that contains the time to the top right of the parent view (bubble) works fine. However, when I add the clock icon in the UIImageView, the pair of subviews shift outside and to the left of the parent UIView. I've tested several things and I've isolated the problem which can be reproduced using the following layout which simply attempts to place an UIImageView in the top-right corner of the parent UIView.
The above layout produces a red rectangle outside and to the left of the parent UIView (gray chat bubble). Note that the same behaviour applies if an actual image is used instead of just a background colour. If the width expression of the parent UIView is changed from What's even more interesting is that if a UILabel is used instead of the UIImageView, it is correctly aligned to the top-right corner despite the above provided that the width expression is completely omitted from the node. Otherwise, the same behaviour occurs. I also tried with a UIView instead of the UIImageView and the same thing happens. |
@Dragonspell99 I've not worked out why this is happening yet, but replacing To be clear, these should be equivalent, so this is definitely a Layout bug, but the workaround should allow you to proceed for now. |
Ok. This works fine for my scenario. Thanks! |
I'm trying to create a UILabel that will size itself automatically according to the following rules:
In order to accomplish this, I have defined my view as follows:
As can be seen in the width expression, I would like the width to be the smaller of the auto width or 320. When I reduce the text to just a few words, this works as expected. However, when the text is too long, as in the supplied example, the label doesn't grow beyond 320 as desired but it doesn't wrap the text. It truncates it instead and remains at 1 line.
Conversely, if I change my width expression to something like:
width="min(1000, 320)"
Leaving everything else the same, the label wraps properly with a width at 320.
Therefore, there seems to be a problem with causing the label to wrap text when using the
auto
keyword in the width expression.The text was updated successfully, but these errors were encountered: