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

Truncate the end of long token titles #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bmnick
Copy link

@bmnick bmnick commented Aug 8, 2014

By changing the autoresize rules on the token label, we can force the
label to appropriately size itself to the token title. Before, a
token’s label was sized to its content, meaning that if it was actually
longer than a line in the token field, it freely overflowed and was
clipped by the outer VENToken’s view. I also exposed the line break
mode for VENTokens as a whole, allowing a client application to change
the line break mode to one appropriate to their data (breaking in the
middle or beginning of the line, for example). Including this in a release
requires a minor version as it adds new API.

By changing the autoresize rules on the token label, we can force the
label to appropriately size itself to the token title. Before, a
token’s label was sized to its content, meaning that if it was actually
longer than a line in the token field, it freely overflowed and was
clipped by the outer VENToken’s view. I also exposed the line break
mode for VENTokens as a whole, allowing a client application to change
the line break mode to one appropriate to their data (breaking in the
middle or beginning of the line, for example.
@@ -28,8 +28,15 @@ @interface VENToken ()
@property (strong, nonatomic) IBOutlet UIView *backgroundView;
@end

static NSLineBreakMode _lineBreakMode = NSLineBreakByTruncatingTail;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal preference, but can we make this

@property (assign, nonatomic) NSLineBreakMode lineBreakMode;

instead of a static variable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I did it this way is so that it's consistent across VENToken instances. By scoping it statically, it avoids situations where some are breaking at the beginning and some at the end. Essentially, this is a class property rather than an instance property. If you would prefer it as an instance property though, I can convert it over and make sure it gets set on initialization.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer instance properties to avoid unintentional side-effects. At least in the Venmo app, we use VENTokenField in two separate places, and it could be the case that we want to use different line break styles for each (or at least have full control of its behavior in each context).

Let me know what you think, and thanks for the pull request! 😸

@ayanonagon ayanonagon force-pushed the master branch 2 times, most recently from 19b4b61 to a0495aa Compare September 17, 2014 04:32
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

Successfully merging this pull request may close these issues.

3 participants