Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26805] Implement Margin property for all Views

GitHub Issuen/a
TypeNew Feature
PriorityNone
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsTiAPI
Labelsmargin, padding
ReporterBrenton House
AssigneeUnknown
Created2019-02-06T20:02:47.000+0000
Updated2019-03-05T04:05:57.000+0000

Description

Add Margin property to Ti.UI.View.

Comments

  1. Joshua Quick 2019-03-05

    Now that I think about it, we already do support margins. If you set a view's "width" property, then its "left" and "right" properties will act as margins. If you set a view's "height" property, then its "top" and "bottom" properties will act as margins. For example, the below will set up an auto-sized label with a margin of "5dp" around it. Note that it's important that you set the width and height to Ti.UI.SIZE or else the top/bottom/left/right properties will be used to size the view instead via our pinning feature.
       var label = Ti.UI.createLabel({
       	text: "My Margin Test",
       	width: Ti.UI.SIZE,
       	height: Ti.UI.SIZE,
       	top: "5dp",
       	bottom: "5dp",
       	left: "5dp",
       	right: "5dp",
       });
       
    [~bhouse], what do you think?
  2. Brenton House 2019-03-05

    The problem is that setting the size to Ti.UI.SIZE isn't always possible. For example, if you are trying to create a gridview w/ tiles . You might want each one to be a certain width/height. I've been able to work around it w/ embedded views but I usually have one embedded view for margin and and second embedded view for padding.
  3. Joshua Quick 2019-03-05

    It'll work for your case too. As long as you set the "width" and "height" properties to a value of some kind, then the top/bottom/left/right properties will act as margins. This works on all platforms (Android, iOS, and Windows).
  4. Brenton House 2019-03-05

    cool! let me try it out. Maybe we can add a helper property called margin that sets the top,bottom,left, and right.

JSON Source