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-14753 check the deleted child index and add the child in that index position #4645

Merged
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 @@ -150,14 +150,23 @@ public TiUIView(TiViewProxy proxy)
* @param child the view to be added.
*/
public void add(TiUIView child)
{
add(child, -1);
}

public void add(TiUIView child, int childIndex)
Copy link
Contributor

Choose a reason for hiding this comment

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

this method should probably be private since its not called outside this file

{
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 @@ -651,12 +676,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);
Copy link
Contributor

Choose a reason for hiding this comment

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

findChildIndex() is a private function, so you don't need to pass 'this' into that function. You can just call methods directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to find index of a component is it so I passed 'this' into function . I removed 'this ' into this method and call directly . But not work properly .This method just work like 'remove' method only difference is in findChildIndex function find the position instead of remove

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