Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23367] Expose/support hyphenationFactor & hyphenationFrequency for Attributed Strings

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionDuplicate
Resolution Date2018-05-02T08:56:15.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTiAPI
Labelsattributedstring, hyphenation, label, text
ReporterGertjan Smits
AssigneeVijay Singh
Created2016-05-11T10:56:27.000+0000
Updated2018-08-06T17:41:08.000+0000

Description

iOS and Android both support hyphenation in native land. There is no option to use this in a Titanium app. (afaik) It would be very convenient to have this functionality in Ti.UI.Label. Especially in our case for German apps. Implementing this in Swift is extremely easy:
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.hyphenationFactor = 1.0
		
let attributedString = NSAttributedString(string: text, attributes: [NSParagraphStyleAttributeName:paragraphStyle])
		
label.attributedText = attributedString
*iOS*, hyphenationFactor: https://developer.apple.com/library/ios/documentation/Cocoa/Reference/ApplicationKit/Classes/NSMutableParagraphStyle_Class/#//apple_ref/occ/instp/NSMutableParagraphStyle/hyphenationFactor *Android*, hyphenationFrequency: http://developer.android.com/reference/android/widget/TextView.html#attr_android:hyphenationFrequency *Extra info:* https://en.wikipedia.org/wiki/Hyphen

Comments

  1. Gertjan Smits 2016-05-11

    For Android it probably needs to be implemented in combination with *android:breakStrategy*.
  2. Nazmus Salahin 2016-05-12

    Hello, Thanks for creating the ticket. Our engineering team will look into it. This need to be cleared by our selection committee. Please understand that the processes is time-consuming and lots of variables in play. We will let you know if and when we will be including this feature in our platform. Regards
  3. Malcolm Hollingsworth 2016-06-30

  4. Gertjan Smits 2016-11-02

    Any updates on this? Client now really wants it...
  5. Vijay Singh 2017-05-31

    PR: https://github.com/appcelerator/titanium_mobile/pull/9100
       var win = Titanium.UI.createWindow({
                       backgroundColor: '#ddd',
                   });
       
                   win.open();
       
                   var text =  'Bacon ipsum dolor Appcelerator Titanium rocks! sit amet fatback leberkas salami sausage tongue strip steak.';
                   var paragraphStyle = Titanium.UI.createParagraphStyle({
                       attributes:[
                       {
                           type:Titanium.UI.PARAGRAPH_ATTRIBUTE_HYPHENATION_FACTOTR,
                           value:0.5
                       },
                       {
                           type:Titanium.UI.PARAGRAPH_ATTRIBUTE_LINE_SPACING,
                           value:20
                       },
                       {
                           type:Titanium.UI.PARAGRAPH_ATTRIBUTE_FIRST_LINE_HEAD_INDENT,
                           value:20
                       }
                       ]
                       });
       
                   var attr = Titanium.UI.createAttributedString({
                       text: text,
                       attributes: [
                           // Paragraph Style 
                           {
                               type: Titanium.UI.ATTRIBUTE_PARAGRAPH_STYLE,
                               value: paragraphStyle,
                               range: [0, text.length]
                           },
                           // Sets a background color
                           {
                               type: Titanium.UI.ATTRIBUTE_BACKGROUND_COLOR,
                               value: "red",
                               range: [text.indexOf('Appcelerator'), ('Appcelerator').length]
                           },
                       ]
                   });
       
                   var label = Titanium.UI.createLabel({
                       left: 20,
                       right: 20,
                       height: Titanium.UI.SIZE,
                       attributedString: attr
                   });
                   win.add(label);
       
  6. Hans Knöchel 2018-05-02

    Solved as part of TIMOB-24080.
  7. Eric Merriman 2018-08-06

    Closing as a duplicate. If this is in error, please reopen.

JSON Source