Skip to content

Instantly share code, notes, and snippets.

@MestreKarin
Last active December 28, 2018 02:19
Show Gist options
  • Save MestreKarin/34a96a8db7705f437a0fd652183e53b8 to your computer and use it in GitHub Desktop.
Save MestreKarin/34a96a8db7705f437a0fd652183e53b8 to your computer and use it in GitHub Desktop.
Directive for NativeScript-Vue.
/*
Saw Eddy directive for NativeScript-Angular, so I created for NativeScript-Vue.
Eddy's directive: https://gist.github.com/EddyVerbruggen/8232252e3a4667e7e20916279f98d3fc
*/
import { Label } from 'tns-core-modules/ui/label';
export default {
bind: function (el, binding) {
try {
if (!el.nativeView instanceof Label) {
console.error('Only label allowed!');
return;
}
if (isNaN(parseInt(binding.expression))) {
console.error('Invalid number.');
return;
}
el.nativeView.on(Label.loadedEvent, () => {
if (el.nativeView.ios) {
el.nativeView.ios.numberOfLines = binding.expression;
el.nativeView.ios.lineBreakMode = NSLineBreakMode.ByTruncatingTail;
el.nativeView.ios.adjustsFontSizeToFitWidth = false;
} else if (el.nativeView.android) {
el.nativeView.android.setMaxLines(maxLines);
el.nativeView.android.setEllipsize(android.text.TextUtils.TruncateAt.END);
}
});
} catch (e) {
console.error(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment