From 15a6432d01fe69a50a68f37b8a60efa5fbc19b37 Mon Sep 17 00:00:00 2001 From: Julian Winkler Date: Tue, 25 Mar 2025 19:59:25 +0100 Subject: [PATCH] Revert "View: call onLayout() only on size change or on request" This reverts commit b33a470c7bbcb9aa928a656e44bec471ba57d855. This commit was added as fix for layout recreation loops, but this is no longer a problem, since ViewGroup.detachViewFromParent() has been improved. The first fix is no longer needed and it seems to cause some minor regressions, so we revert it. --- src/api-impl-jni/util.c | 2 +- src/api-impl-jni/views/AndroidLayout.c | 11 +---------- src/api-impl/android/view/View.java | 20 +++++--------------- 3 files changed, 7 insertions(+), 26 deletions(-) diff --git a/src/api-impl-jni/util.c b/src/api-impl-jni/util.c index 66028336..8fa829df 100644 --- a/src/api-impl-jni/util.c +++ b/src/api-impl-jni/util.c @@ -134,7 +134,7 @@ void set_up_handle_cache(JNIEnv *env) handle_cache.view.onTouchEvent = _METHOD(handle_cache.view.class, "onTouchEvent", "(Landroid/view/MotionEvent;)Z"); handle_cache.view.dispatchTouchEvent = _METHOD(handle_cache.view.class, "dispatchTouchEvent", "(Landroid/view/MotionEvent;)Z"); handle_cache.view.onInterceptTouchEvent = _METHOD(handle_cache.view.class, "onInterceptTouchEvent", "(Landroid/view/MotionEvent;)Z"); - handle_cache.view.layoutInternal = _METHOD(handle_cache.view.class, "layoutInternal", "(II)Z"); + handle_cache.view.layoutInternal = _METHOD(handle_cache.view.class, "layoutInternal", "(II)V"); handle_cache.view.measure = _METHOD(handle_cache.view.class, "measure", "(II)V"); handle_cache.view.performLongClick = _METHOD(handle_cache.view.class, "performLongClick", "(FF)Z"); handle_cache.view.getId = _METHOD(handle_cache.view.class, "getId", "()I"); diff --git a/src/api-impl-jni/views/AndroidLayout.c b/src/api-impl-jni/views/AndroidLayout.c index 8ae56687..fea5bdf7 100644 --- a/src/api-impl-jni/views/AndroidLayout.c +++ b/src/api-impl-jni/views/AndroidLayout.c @@ -70,18 +70,9 @@ static void android_layout_allocate(GtkLayoutManager *layout_manager, GtkWidget height = layout->real_height; } - jboolean layoutChanged = (*env)->CallBooleanMethod(env, layout->view, handle_cache.view.layoutInternal, width, height); + (*env)->CallVoidMethod(env, layout->view, handle_cache.view.layoutInternal, width, height); if((*env)->ExceptionCheck(env)) (*env)->ExceptionDescribe(env); - if (!layoutChanged) { // No change in layout. Reapply the current allocations - for (GtkWidget *child = gtk_widget_get_first_child(widget); child; child = gtk_widget_get_next_sibling(child)) { - graphene_matrix_t transform_matrix; - if (gtk_widget_compute_transform(child, widget, &transform_matrix)) { - GskTransform *transform = gsk_transform_matrix(NULL, &transform_matrix); - gtk_widget_allocate(child, gtk_widget_get_width(child), gtk_widget_get_height(child), gtk_widget_get_baseline(child), transform); - } - } - } } static GtkSizeRequestMode android_layout_get_request_mode(GtkLayoutManager *layout_manager, GtkWidget *widget) diff --git a/src/api-impl/android/view/View.java b/src/api-impl/android/view/View.java index c844b478..6033818a 100644 --- a/src/api-impl/android/view/View.java +++ b/src/api-impl/android/view/View.java @@ -848,7 +848,6 @@ public class View implements Drawable.Callback { private int oldWidthMeasureSpec = -1; private int oldHeightMeasureSpec = -1; private boolean layoutRequested = true; - private boolean layoutPending = true; private int oldWidth; private int oldHeight; protected boolean haveCustomMeasure = true; @@ -1372,7 +1371,6 @@ public class View implements Drawable.Callback { oldHeightMeasureSpec = heightMeasureSpec; onMeasure(widthMeasureSpec, heightMeasureSpec); layoutRequested = false; - layoutPending = true; } } @@ -1448,10 +1446,8 @@ public class View implements Drawable.Callback { native_layout(widget, l, t, r, b); } - /** Helper function to be called from GTK's LayoutManager via JNI - * @return true if the layout changed - */ - private boolean layoutInternal(int width, int height) { + /** Helper function to be called from GTKs LayoutManager via JNI */ + private void layoutInternal(int width, int height) { // if the layout is triggered from a native widget, we might not have measured yet if (width != getMeasuredWidth() || height != getMeasuredHeight()) { measure(width | MeasureSpec.EXACTLY, height | MeasureSpec.EXACTLY); @@ -1461,15 +1457,9 @@ public class View implements Drawable.Callback { onSizeChanged(width, height, oldWidth, oldHeight); bottom = top + height; right = left + width; - if (changed || layoutPending) { - layoutPending = false; - onLayout(changed, 0, 0, width, height); - oldWidth = width; - oldHeight = height; - return true; - } else { - return false; - } + onLayout(changed, 0, 0, width, height); + oldWidth = width; + oldHeight = height; } public int getLeft() {