Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-16512] Android: added left and right padding to TextField #5492

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
TiC.PROPERTY_TEXT_ALIGN,
TiC.PROPERTY_VALUE,
TiC.PROPERTY_VERTICAL_ALIGN,
TiC.PROPERTY_RETURN_KEY_TYPE
TiC.PROPERTY_RETURN_KEY_TYPE,
TiC.PROPERTY_PADDING_LEFT,
TiC.PROPERTY_PADDING_RIGHT
})
public class TextAreaProxy extends TiViewProxy
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
TiC.PROPERTY_TEXT_ALIGN,
TiC.PROPERTY_VALUE,
TiC.PROPERTY_VERTICAL_ALIGN,
TiC.PROPERTY_RETURN_KEY_TYPE
TiC.PROPERTY_RETURN_KEY_TYPE,
TiC.PROPERTY_PADDING_LEFT,
TiC.PROPERTY_PADDING_RIGHT
})
public class TextFieldProxy extends TiViewProxy
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public class TiUIText extends TiUIView
private int maxLength = -1;
private boolean isTruncatingText = false;
private boolean disableChangeEvent = false;

protected TiEditText tv;

public class TiEditText extends EditText
Expand Down Expand Up @@ -201,8 +200,37 @@ public void processProperties(KrollDict d)
if (d.containsKey(TiC.PROPERTY_AUTO_LINK)) {
TiUIHelper.linkifyIfEnabled(tv, d.get(TiC.PROPERTY_AUTO_LINK));
}

setTextPadding(d);
}

private boolean setTextPadding(KrollDict d)
{
boolean padding = false;
int paddingLeft = 0;
int paddingRight = 0;
int paddingTop = 0;
int paddingBottom = 0;
if (d.containsKey(TiC.PROPERTY_PADDING_LEFT)) {
paddingLeft = TiConvert.toInt(d, TiC.PROPERTY_PADDING_LEFT);
padding = true;
} else {
paddingLeft = tv.getPaddingLeft();
}
if (d.containsKey(TiC.PROPERTY_PADDING_RIGHT)) {
paddingRight = TiConvert.toInt(d, TiC.PROPERTY_PADDING_RIGHT);
padding = true;
} else {
paddingRight = tv.getPaddingRight();
}
if(padding)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (padding) {

{
paddingBottom = tv.getPaddingBottom();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

paddingTop = tv.getPaddingTop();
tv.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
}
return padding;
}

@Override
public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy)
Expand Down Expand Up @@ -262,7 +290,7 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
TiUIHelper.styleText(tv, (HashMap) newValue);
} else if (key.equals(TiC.PROPERTY_AUTO_LINK)) {
TiUIHelper.linkifyIfEnabled(tv, newValue);
} else {
} else if (!setTextPadding(proxy.getProperties())){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation is inefficient. You don't need to call it every time a property is changed.. You only need to call it when paddingRight and Left is called.

super.propertyChanged(key, oldValue, newValue, proxy);
}
}
Expand Down
10 changes: 10 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,16 @@ public class TiC
*/
public static final String PROPERTY_PACKAGE_NAME = "packageName";

/**
* @module.api
*/
public static final String PROPERTY_PADDING_LEFT = "paddingLeft";

/**
* @module.api
*/
public static final String PROPERTY_PADDING_RIGHT = "paddingRight";

/**
* @module.api
*/
Expand Down
10 changes: 10 additions & 0 deletions apidoc/Titanium/UI/TextArea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ methods:
See also: [add](Titanium.UI.TextArea.add), <Titanium.UI.View.add>.
platforms: [iphone, ipad]

- name: paddingLeft
summary: Left padding of this TextArea.
type: Number
platforms: [android]

- name: paddingRight
summary: Right padding of this TextArea.
type: Number
platforms: [android]

- name: setSelection
summary: Selects the text in range (start, end).
platforms: [android, iphone, ipad]
Expand Down
4 changes: 2 additions & 2 deletions apidoc/Titanium/UI/TextField.yml
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,12 @@ properties:
- name: paddingLeft
summary: Left padding of this text field.
type: Number
platforms: [iphone, ipad]
platforms: [iphone, ipad, android]

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

- name: passwordMask
summary: Obscure the input text from the user.
Expand Down