Last active
December 28, 2018 02:19
-
-
Save MestreKarin/34a96a8db7705f437a0fd652183e53b8 to your computer and use it in GitHub Desktop.
Directive for NativeScript-Vue.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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