Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8941] iOS: Children views inside scrollview aren't calculating size properly

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-06-13T14:01:56.000+0000
Affected Version/sRelease 2.0.1
Fix Version/sRelease 2.1.0, Sprint 2012-12 Core
ComponentsiOS
LabelsSupportTeam, core, module_scrollview, qe-testadded
ReporterMitchell Amihod
AssigneeMax Stepanov
Created2012-04-29T17:45:40.000+0000
Updated2012-07-09T10:07:23.000+0000

Description

Issue

ScrollView Children do not size properly. Label 6 doesn't calculate size properly (uses remaining visible space), but Label 7 and Label 1-5 all calculate size properly.

Tested on

iOS 5 simulator

Expected behavior

Children should calculate based on contentWidth. Example will run under 1.8.2. When run under 1.8.2 sizes are as expected.

Current behavior

Instead, children use visible width value to calculate their size. As seen in screenShot with Titanium SDK 2.0.1.GA2

Repro sequence

var view = Ti.UI.createScrollView({
    borderWidth: 1,
    borderColor: '#f00',
    layout:'horizontal',
    height: 35,
    contentHeight: 35,
    contentWidth: 'auto',
    left: 0,
    right: 0
});

var items = ['Label 1', 'Label 2', 'Label 3', 'Label 4', 'Label 5', 'Label 6', 'Label 7'];

items.forEach(function(item) {
    
    var width = (Ti.UI.SIZE == undefined) ? 'auto': Ti.UI.SIZE; //So example works under 1.8.2 or 2.0.1
    
    var tLabel = Ti.UI.createLabel({
        touchEnabled: false,
        text:'  ' + item + '  ', //To add inner padding
        backgroundColor: '#6CF',
        borderColor: '#000',
        borderWidth: 1,
        borderRadius: 5,
        color: '#FF0080',
        right: 5,
        top: 1,
        width:width,
        height:22,
        font: {
            fontSize: 13
        },
        textAlign: 'center'
    });
    view.add(tLabel);
});

var rootWin = Ti.UI.createWindow({
    backgroundColor: '#ccc'
});

// add table view to the window
rootWin.add(view);
rootWin.open();

API Docs

http://docs.appcelerator.com/titanium/2.0/index.html#!/api/Titanium.UI.ScrollView-property-contentWidth

Attachments

FileDateSize
app.js2012-04-29T17:46:11.000+00001263
right-1.8.2.png2012-04-29T17:48:43.000+0000120188
wrong-2.0.1.png2012-04-29T17:48:43.000+0000120555

Comments

  1. Max Stepanov 2012-05-29

    *Related issue:* For some reason NSString's - (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode method truncates the string having trailing spaces when given _size_ parameter width is equal to the expected return width. E.g. for size=(61,20) it returns (60, 16), but for size=(60,20) it returns (56, 16). if there is no space, the returned values are same.
  2. Max Stepanov 2012-05-29

    *Possible fix:*
       diff --git a/iphone/Classes/TiUIScrollViewProxy.m b/iphone/Classes/TiUIScrollViewProxy.m
       index d6fd66d..35d59ff 100644
       --- a/iphone/Classes/TiUIScrollViewProxy.m
       +++ b/iphone/Classes/TiUIScrollViewProxy.m
       @@ -188,7 +188,7 @@
                }
                else if (TiDimensionIsAutoSize(constraint))
                {
       -            bounds.size.width = [child autoWidthForSize:CGSizeMake(boundingValue,bounds.size.height - offset2)] + offset;
       +            bounds.size.width = [child autoWidthForSize:CGSizeMake(-1,bounds.size.height - offset2)] + offset;
                    horizontalLayoutBoundary += bounds.size.width;
                }
                else if (TiDimensionIsAuto(constraint) )
       
  3. Max Stepanov 2012-06-06

    PR pending https://github.com/appcelerator/titanium_mobile/pull/2338
  4. Michael Pettiford 2012-06-21

    Closing issue Tested with Ti Studio build 2.1.0.201206200844 Ti Mobile SDK 2.1.0.v20120619172256 hash rd3a84b13 OSX Lion 10.7.3 iPhone 4S OS 5.1 The expected behavior is shown

JSON Source