You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
implement ViewGroup.detachViewFromParent() properly
Temporarily detaching a View from its parent should not call any callbacks, which was the case with the old implementation. This was causing infinite recreation loops in some cases.
This commit is contained in:
@@ -136,14 +136,27 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void detachViewFromParent(int index) {
|
public void detachViewFromParent(int index) {
|
||||||
removeViewInternal(children.get(index));
|
children.remove(index).parent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void attachViewToParent(View view, int index, LayoutParams params) {
|
public void attachViewToParent(View view, int index, LayoutParams params) {
|
||||||
addViewInternal(view, index, params);
|
if (!checkLayoutParams(params))
|
||||||
|
params = generateLayoutParams(params);
|
||||||
|
|
||||||
|
view.parent = this;
|
||||||
|
view.setLayoutParams(params);
|
||||||
|
if (index < 0)
|
||||||
|
index = children.size();
|
||||||
|
children.add(index, view);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void removeDetachedView(View child, boolean animate) {
|
protected void removeDetachedView(View child, boolean animate) {
|
||||||
|
native_removeView(widget, child.widget);
|
||||||
|
if (isAttachedToWindow())
|
||||||
|
child.detachFromWindowInternal();
|
||||||
|
if (onHierarchyChangeListener != null) {
|
||||||
|
onHierarchyChangeListener.onChildViewRemoved(this, child);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected native void native_addView(long widget, long child, int index, LayoutParams params);
|
protected native void native_addView(long widget, long child, int index, LayoutParams params);
|
||||||
@@ -373,7 +386,8 @@ public class ViewGroup extends View implements ViewParent, ViewManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void detachViewFromParent(View view) {
|
public void detachViewFromParent(View view) {
|
||||||
removeView(view);
|
children.remove(view);
|
||||||
|
view.parent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTouchscreenBlocksFocus(boolean touchscreenBlocksFocus) {}
|
public void setTouchscreenBlocksFocus(boolean touchscreenBlocksFocus) {}
|
||||||
|
|||||||
Reference in New Issue
Block a user