Skip to content

Commit

Permalink
Merge pull request #4645 from bijupmb/TIMOB-14753-AddingBorderRadiust…
Browse files Browse the repository at this point in the history
…oViewInVLayoutScrewsUPLayout

TIMOB-14753 check the deleted child index and add the child in that index position
  • Loading branch information
hieupham007 committed Oct 10, 2013
2 parents 6958700 + a197a53 commit e1262e8
Showing 1 changed file with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,23 @@ public TiUIView(TiViewProxy proxy)
* @param child the view to be added.
*/
public void add(TiUIView child)
{
add(child, -1);
}

private void add(TiUIView child, int childIndex)
{
if (child != null) {
View cv = child.getOuterView();
if (cv != null) {
View nv = getNativeView();
if (nv instanceof ViewGroup) {
if (cv.getParent() == null) {
((ViewGroup) nv).addView(cv, child.getLayoutParams());
if (childIndex != -1) {
((ViewGroup) nv).addView(cv, childIndex, child.getLayoutParams());
} else {
((ViewGroup) nv).addView(cv, child.getLayoutParams());
}
}
children.add(child);
child.parent = proxy;
Expand All @@ -166,6 +175,22 @@ public void add(TiUIView child)
}
}

private int findChildIndex(TiUIView child)
{
int idxChild = -1;
if (child != null) {
View cv = child.getOuterView();
if (cv != null) {
View nv = getNativeView();
if (nv instanceof ViewGroup) {
idxChild = ((ViewGroup) nv).indexOfChild(cv);

}
}
}
return idxChild;
}

/**
* Removes the child view from the ViewGroup, if child exists.
* @param child the view to be removed.
Expand Down Expand Up @@ -655,12 +680,18 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP

if (hasBorder) {
if (borderView == null && parent != null) {
// Since we have to create a new border wrapper view, we need to remove this view, and re-add it.
// Since we have to create a new border wrapper view, we need to remove this view, and re-add
// it.
// This will ensure the border wrapper view is added correctly.
TiUIView parentView = parent.getOrCreateView();
int removedChildIndex = parentView.findChildIndex(this);
parentView.remove(this);
initializeBorder(d, bgColor);
parentView.add(this);
if (removedChildIndex == -1) {
parentView.add(this);
} else {
parentView.add(this, removedChildIndex);
}
} else if (key.startsWith(TiC.PROPERTY_BORDER_PREFIX)) {
handleBorderProperty(key, newValue);
}
Expand Down

0 comments on commit e1262e8

Please sign in to comment.