From 654d551377cdd74f427505ea17a06eaea2a613c8 Mon Sep 17 00:00:00 2001 From: Julian Winkler Date: Wed, 27 Mar 2024 23:01:46 +0100 Subject: [PATCH] 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. --- src/api-impl-jni/generated_headers/android_view_View.h | 8 ++++++++ src/api-impl-jni/views/android_view_View.c | 5 +++++ src/api-impl/android/view/View.java | 7 ++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/api-impl-jni/generated_headers/android_view_View.h b/src/api-impl-jni/generated_headers/android_view_View.h index 98c21f34..cc396a79 100644 --- a/src/api-impl-jni/generated_headers/android_view_View.h +++ b/src/api-impl-jni/generated_headers/android_view_View.h @@ -287,6 +287,14 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1requestLayout JNIEXPORT void JNICALL Java_android_view_View_native_1setBackgroundDrawable (JNIEnv *, jobject, jlong, jlong); +/* + * Class: android_view_View + * Method: native_queueAllocate + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_android_view_View_native_1queueAllocate + (JNIEnv *, jobject, jlong); + /* * Class: android_view_View * Method: nativeInvalidate diff --git a/src/api-impl-jni/views/android_view_View.c b/src/api-impl-jni/views/android_view_View.c index ddb5851b..7c718302 100644 --- a/src/api-impl-jni/views/android_view_View.c +++ b/src/api-impl-jni/views/android_view_View.c @@ -536,3 +536,8 @@ JNIEXPORT jboolean JNICALL Java_android_view_View_native_1getMatrix(JNIEnv *env, GtkWidget *widget = gtk_widget_get_parent(GTK_WIDGET(_PTR(widget_ptr))); return gtk_widget_compute_transform(gtk_widget_get_parent(widget), widget, _PTR(matrix_ptr)); } + +JNIEXPORT void JNICALL Java_android_view_View_native_1queueAllocate(JNIEnv *env, jobject this, jlong widget_ptr) +{ + gtk_widget_queue_allocate(GTK_WIDGET(_PTR(widget_ptr))); +} diff --git a/src/api-impl/android/view/View.java b/src/api-impl/android/view/View.java index 7ac7d3a5..e3fdee64 100644 --- a/src/api-impl/android/view/View.java +++ b/src/api-impl/android/view/View.java @@ -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);