View.setTranslationY(): queue allocate when called on CoordinatorLayout

androidx adjusts the translation a little bit and immediately
reverts it to trigger a layout pass on the CoordinatorLayout.

Calling gtk_widget_queue_allocate here makes CoordinatorLayout behave
correctly, but it causes strange issues with other Views. Therefore, it is
done only for CoordinatorLayouts for now.
This commit is contained in:
Julian Winkler
2024-03-27 23:01:46 +01:00
parent 66e5d77959
commit 654d551377
3 changed files with 19 additions and 1 deletions

View File

@@ -948,6 +948,7 @@ public class View extends Object {
protected native void native_layout(long widget, int l, int t, int r, int b);
protected native void native_requestLayout(long widget);
protected native void native_setBackgroundDrawable(long widget, long paintable);
protected native void native_queueAllocate(long widget);
// --- stubs
@@ -1379,7 +1380,11 @@ public class View extends Object {
public float getTranslationX() {return 0.f;}
public float getTranslationY() {return 0.f;}
public void setTranslationX(float translationX) {}
public void setTranslationY(float translationY) {}
public void setTranslationY(float translationY) {
// CoordinatorLayout abuses this method to trigger a layout pass
if (getClass().getName().equals("androidx.coordinatorlayout.widget.CoordinatorLayout"))
native_queueAllocate(widget);
}
public void setAlpha(float alpha) {
native_setVisibility(widget, visibility, alpha);