Skip to content

Commit

Permalink
Merge pull request #7908 from m1ga/android_padding
Browse files Browse the repository at this point in the history
[TIMOB-16512] Android: added padding to TextField
  • Loading branch information
ashcoding committed Jun 27, 2016
2 parents 65b25f7 + f6b589d commit 5da41d7
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
TiC.PROPERTY_TEXT_ALIGN,
TiC.PROPERTY_VALUE,
TiC.PROPERTY_VERTICAL_ALIGN,
TiC.PROPERTY_PADDING,
TiC.PROPERTY_RETURN_KEY_TYPE
})
public class TextAreaProxy extends TiViewProxy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
TiC.PROPERTY_TEXT_ALIGN,
TiC.PROPERTY_VALUE,
TiC.PROPERTY_VERTICAL_ALIGN,
TiC.PROPERTY_RETURN_KEY_TYPE
TiC.PROPERTY_RETURN_KEY_TYPE,
TiC.PROPERTY_PADDING
})
public class TextFieldProxy extends TiViewProxy
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,34 @@ public void processProperties(KrollDict d)
if (d.containsKey(TiC.PROPERTY_AUTO_LINK)) {
TiUIHelper.linkifyIfEnabled(tv, d.get(TiC.PROPERTY_AUTO_LINK));
}

if (d.containsKey(TiC.PROPERTY_PADDING)) {
setTextPadding((HashMap)d.get(TiC.PROPERTY_PADDING));
}

}

private void setTextPadding(HashMap<String, Object> d)
{
int paddingLeft = 0;
int paddingRight = 0;

if (d.containsKey(TiC.PROPERTY_LEFT)) {
paddingLeft = TiConvert.toInt(d.get(TiC.PROPERTY_LEFT), 0);
} else {
paddingLeft = tv.getPaddingLeft();
}
if (d.containsKey(TiC.PROPERTY_RIGHT)) {
paddingRight = TiConvert.toInt(d.get(TiC.PROPERTY_RIGHT), 0);
} else {
paddingRight = tv.getPaddingRight();
}

tv.setPadding(paddingLeft, tv.getPaddingTop(), paddingRight, tv.getPaddingBottom());
if (field) {
tv.setGravity(Gravity.CENTER_VERTICAL);
}
}

@Override
public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy)
Expand Down Expand Up @@ -281,6 +307,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
setAttributedStringHint((AttributedStringProxy)newValue);
} else if (key.equals(TiC.PROPERTY_ATTRIBUTED_STRING) && newValue instanceof AttributedStringProxy) {
setAttributedStringText((AttributedStringProxy)newValue);
} else if (key.equals(TiC.PROPERTY_PADDING)) {
setTextPadding((HashMap)newValue);
} else {
super.propertyChanged(key, oldValue, newValue, proxy);
}
Expand Down
35 changes: 35 additions & 0 deletions apidoc/Titanium/UI/TextArea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ methods:
See also: [add](Titanium.UI.TextArea.add), <Titanium.UI.View.add>.
platforms: [iphone, ipad]

- name: padding
summary: Sets the left and right padding of this TextArea. The text will always be vertically centered.
type: Padding
platforms: [android, ios, ipad]
since: 6.0.0

- name: paddingLeft
summary: Left padding of this text field.
type: Number
platforms: [iphone, ipad]
deprecated:
since: "6.0.0"
notes: Use padding instead

- name: paddingRight
summary: Right padding of this text field.
type: Number
platforms: [iphone, ipad]
deprecated:
since: "6.0.0"
notes: Use padding instead

- name: setSelection
summary: Selects the text in range (start, end).
platforms: [android, iphone, ipad]
Expand Down Expand Up @@ -519,3 +541,16 @@ properties:
- name: length
summary: Number of characters selected.
type: Number
---
name: Padding
summary: Dictionary object of parameters for the <Titanium.UI.TextArea.padding> that describes the padding
since: "6.0.0"
platforms: [android, iphone, ipad]
properties:
- name: left
type: Number
summary: Left padding

- name: right
type: Number
summary: Right padding
27 changes: 26 additions & 1 deletion apidoc/Titanium/UI/TextField.yml
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,28 @@ properties:
type: Number
platforms: [iphone, ipad]

- name: padding
summary: Sets the padding of this text field.
type: Padding
platforms: [android, ios, ipad]
since: 6.0.0

- name: paddingLeft
summary: Left padding of this text field.
type: Number
platforms: [iphone, ipad]
deprecated:
since: "6.0.0"
notes: Use padding instead

- name: paddingRight
summary: Right padding of this text field.
type: Number
platforms: [iphone, ipad]

deprecated:
since: "6.0.0"
notes: Use padding instead

- name: passwordMask
summary: Obscure the input text from the user.
description: |
Expand Down Expand Up @@ -700,3 +712,16 @@ properties:
- name: length
summary: Number of characters selected.
type: Number
---
name: Padding
summary: Dictionary object of parameters for the <Titanium.UI.TextField.padding> that describes the padding
since: "6.0.0"
platforms: [android, iphone, ipad]
properties:
- name: left
type: Number
summary: Left padding

- name: right
type: Number
summary: Right padding

0 comments on commit 5da41d7

Please sign in to comment.