Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24086] iOS: Label doesn't fire link event correctly

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-11-07T14:59:46.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.1.0
ComponentsiOS
Labelsclickevent, communication, fireevent, ios, label, notable
ReporterFlavio De Stefano
AssigneeHans Knöchel
Created2016-10-31T10:58:31.000+0000
Updated2016-11-17T17:12:37.000+0000

Description

Sometimes, don't know why, the Labels doesn't fire the link event. I indagated in the code, and I found that the method to get the link is by finding the index from the clicked point in the Label. The problem is that the index, is, sometimes, wrong. I just re-implemented a more elegant version of the "find index", taken from here: https://github.com/AliSoftware/OHAttributedStringAdditions/blob/master/Source/UILabel%2BOHAdditions.m This is the demo of example that doesn't works and the one that works. ZIP + MOV. [tibugt.mov.zip](https://github.com/appcelerator/titanium_mobile/files/561573/tibugt.mov.zip) PR: https://github.com/appcelerator/titanium_mobile/pull/8568

Comments

  1. Hans Knöchel 2016-11-05

    Test-Case:
       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 attr = Titanium.UI.createAttributedString({
           text: text,
           attributes: [
               {
                   type: Ti.UI.ATTRIBUTE_LINK,
                   value: "https:/appcelerator.com",
                   range: [text.indexOf('Titanium'), ('Titanium').length]
               },
               // Underlines text
               {
                   type: Titanium.UI.ATTRIBUTE_UNDERLINES_STYLE,
                   value: Ti.UI.ATTRIBUTE_UNDERLINE_STYLE_SINGLE,
                   range: [text.indexOf('Titanium'), ('Titanium').length]
               }
           ]
       });
       
       var label = Titanium.UI.createLabel({
           left: 20,
           right: 20,
           height: Titanium.UI.SIZE,
           attributedString: attr
       });
       
       label.addEventListener("link", function(e) {
           alert(e);
       })
       
       win.add(label);
       
  2. Eric Wieber 2016-11-17

    Verified fixed, using: MacOS 10.12 (16A323) Studio 4.8.0.201611121409 Ti SDK 6.1.0.v20161117072812 Appc NPM 4.2.9-1 Appc CLI 6.1.0-13 Alloy 1.9.4 Xcode 8.1 (8B62) Link events are correctly fired for labels. Tested by using the provided sample code as well as adding many different attributes to the attributed string for the label and ensuring all link events were fired.

JSON Source