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

feat(android): lineCount/visibleText for Ti.UI.Label #13583

Merged
merged 6 commits into from Jan 1, 2024

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Sep 29, 2022

Exposing two new parameters in a Ti.UI.Label:

  • lineCount: returns the lines of the label
  • visibleText: returns the visible text

Can be used in combination with ellipsize: true to determine if the text is fully visible or not.

Example

const win = Ti.UI.createWindow({});
var lbl = Ti.UI.createLabel({
	text: "asd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd 111111 fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdf",
	maxLines: 10,
	ellipsize: true
});
win.add(lbl);
setTimeout(function() {
	console.log(lbl.lineCount);
	console.log(lbl.text == lbl.visibleText ? "full text" : "ellipsize");
}, 2000)

win.open();

-> returns 4 and full text. So the label will use only 4 of the max 10 lines and it shows the full text

const win = Ti.UI.createWindow({});
var lbl = Ti.UI.createLabel({
	text: "asd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd 111111 fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdfasd fasd fasd fsdf",
	maxLines: 2,
	ellipsize: true
});
win.add(lbl);
setTimeout(function() {
	console.log(lbl.lineCount);
	console.log(lbl.text == lbl.visibleText ? "full text" : "ellipsize");
}, 2000)

win.open();

-> returns 2 and ellipsize. The visibleText only returns the actual text in the label.

TODO

  • and I'm not sure if there is something like this for iOS, so parity would be nice

@hansemannn
Copy link
Collaborator

hansemannn commented Oct 1, 2022

@m1ga
Copy link
Contributor Author

m1ga commented Jul 18, 2023

@hansemannn any help with parity here? Would be a great PR to have

apidoc/Titanium/UI/Label.yml Outdated Show resolved Hide resolved
@hansemannn
Copy link
Collaborator

hansemannn commented Dec 25, 2023

@m1ga Regarding parity:

Therefore I would decide if the effort is worth is based on community feedback. If only one person can benefit from it, it's hard to justify the effort.

@m1ga
Copy link
Contributor Author

m1ga commented Dec 25, 2023

If llineCount won't take long to implement then that would be already a great addition! Saw some apps that use the font size calculation + character count to get a rough line count (handling the font as a mono-spaced font).
And since Android has a property for it to get the exact line count I would prefer to have it inside of Ti so people won't need to calculate it.
We can skip the visibleText part. Didn't see a request for it, just added it because it was a native property too.

@hansemannn
Copy link
Collaborator

lineCount added ✅

@m1ga
Copy link
Contributor Author

m1ga commented Dec 31, 2023

iOS version works fine too.
Simulator Screenshot - iPhone 15 Pro Max - 2023-12-31 at 15 35 19

returned 5 for lineCount 👍

@hansemannn hansemannn merged commit 1eeb301 into master Jan 1, 2024
7 checks passed
@m1ga m1ga deleted the androidLinecount branch January 12, 2024 11:36
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.

None yet

2 participants