Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23887] iOS: Attributed string link on a TextArea doesn't fire link event

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2017-05-09T18:06:06.000+0000
Affected Version/sRelease 5.4.0
Fix Version/sRelease 6.1.0
ComponentsiOS
Labelsmerge-6.1.0
Reporteryouri hanssens
AssigneeVijay Singh
Created2016-07-30T11:15:01.000+0000
Updated2017-05-10T16:14:41.000+0000

Description

I use non-editable textarea's for multi-line text sections in my app. For setting the value I use attributed strings because some parts are links. Visually the clickable parts look like they are processed correctly because they turn blue and underlined. But when I click on one of the links I expect the 'link' event to be triggered but all it does is select the word I just clicked, the listener get's nothing. When replacing textarea with label the link event works fine. Unfortunately labels are not an option for me because they do not handle Ti.UI.ATTRIBUTE_BASELINE_OFFSET, which I use to create a better looking line sacing, very well. Using that attribute on a label makes the it clip the text or unwanted ellipsis.

Comments

  1. Sharif AbuDarda 2016-08-05

    Hello, Can uou share a sample test code that regenerates the issue. Also please update your ticket with effected SDK version and your platform information. We will look into your testcode. Thanks.
  2. Issei Komatsu 2016-09-05

  3. Vijay Singh 2017-04-03

    This problem is due to TIMOB-19165 . In this NSLinkAttributeName attribute is removed in order to fulfill the requirement of ticket. The UITextView recognize URL on basis of NSLinkAttributeName and delegates get called , which is handled by UITextView itself. So link event is not getting fired.
  4. Vijay Singh 2017-04-04

    There are two solutions - 1. Revert changes of TIMOB-19165 then UITextView's native link recognizer will be called. 2. Made changes similar to UILabel's link recognizer which is custom. In this PR, I have followed solution 2. PR: https://github.com/appcelerator/titanium_mobile/pull/8923 Test Case :
       // With padding
       var win = Titanium.UI.createWindow({
         backgroundColor: '#ddd',
       });
       
       var string = Ti.UI.createAttributedString({
         text: 'Appcelerator always give blue and underlined',
         attributes: [{
           type: Ti.UI.ATTRIBUTE_LINK,
           value: 'http://www.appcelerator.com',
           range: [0, 12]
         }, {
           type: Ti.UI.ATTRIBUTE_FOREGROUND_COLOR,
           value: 'red',
           range: [0, 12]
         }, {
           type: Ti.UI.ATTRIBUTE_UNDERLINES_STYLE,
           value: Ti.UI.ATTRIBUTE_UNDERLINE_STYLE_NONE,
           range: [0, 12]
         }, {
           type: Ti.UI.ATTRIBUTE_LINK,
           value: 'https://www.youtube.com',
           range: [25, 4]
         }]
       });
       
       var textarea = Ti.UI.createTextArea({
         top: 100,
         attributedString: string,
         padding: {
           left: 20,
           right: 10
         }
       });
       
       win.add(textarea);
       win.open();
       
       textarea.addEventListener("link", function(e) {
         Ti.API.info('link clicked');
         win.add(Titanium.UI.createWebView({
           url: e.url,
           height: 300,
           width: 300
         }));
       });
       
  5. Hans Knöchel 2017-05-03

    Backport for 6.1.0 please
  6. Vijay Singh 2017-05-04

    Backport PR (6_1_X):https://github.com/appcelerator/titanium_mobile/pull/9013
  7. Eric Wieber 2017-05-09

    FR Passed, using: MacOS 10.12 (16A323) Studio 4.9.0.201704061825 Ti SDK 6.1.0.v20170503211832 Appc NPM 4.2.9 Appc CLI 6.2.0 Alloy 1.9.11 Xcode 8.3.2 (8E2002) Attributed strings, inside non-editable text areas, with links now correctly fire the link event when clicked. Tested using the sample code and modified it to fully apply to the test case.
  8. Eric Wieber 2017-05-10

    Fixes verified in builds: 6.1.0.v20170509170935 6.2.0.v20170510084833

JSON Source