Android EditText height not grow automatically when used inside YogaLayout #1210

Closed
opened 2023-01-11 23:42:33 -08:00 by TChengZ · 2 comments
TChengZ commented 2023-01-11 23:42:33 -08:00 (Migrated from github.com)

Report

Android EditText height not grow automatically when used inside YogaLayout, but height grow automatically when used inside a constraintLayout or LinearLayout

Issues and Steps to Reproduce

Replaces this with steps to repro your issue.
create xml like below
`

<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yoga="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fl_scroll_root"
>

<com.facebook.yoga.android.YogaLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
yoga:yg_flexDirection="column"
yoga:yg_width="100%"
android:id="@+id/fl_sv_scroll"
app:layout_constraintTop_toBottomOf="@+id/set_input1"
app:layout_constraintStart_toStartOf="@+id/fl_scroll_root"
app:layout_constraintEnd_toEndOf="@+id/fl_scroll_root"
>

</com.facebook.yoga.android.YogaLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
`

Expected Behavior

Describe what you expected would happen.
the second edittext grow automatically as the first edittext

Actual Behavior

Describe what actually happened.
the second edittext act like single line
image

Link to Code

If you have some code that maintainers can clone/test for themselves, bugs can be resolved much faster. Please paste a link here.

When applicable, use this fiddle to post a web repro.

# Report Android EditText height not grow automatically when used inside YogaLayout, but height grow automatically when used inside a constraintLayout or LinearLayout - [ ] I have searched [existing issues](https://github.com/facebook/yoga/issues) and this is not a duplicate # Issues and Steps to Reproduce ***Replaces this with steps to repro your issue.*** create xml like below ` <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:yoga="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/fl_scroll_root" > <EditText android:layout_width="0dp" android:layout_height="wrap_content" android:paddingTop="5dp" android:paddingBottom="5dp" android:paddingLeft="3dp" android:paddingRight="2dp" android:layout_marginTop="15dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" app:layout_constraintTop_toTopOf="@+id/fl_scroll_root" app:layout_constraintStart_toStartOf="@+id/fl_scroll_root" app:layout_constraintEnd_toEndOf="@+id/fl_scroll_root" android:id="@+id/set_input1" android:text="@string/null_text" android:textSize="26sp" android:textColor="@color/yellow" android:gravity="center_vertical" android:hint="@string/edit_hint" android:textColorHint="@color/gray" android:background="@drawable/edit_text_bg" android:textCursorDrawable="@drawable/text_cursor" android:inputType="textMultiLine" /> <com.facebook.yoga.android.YogaLayout android:layout_width="match_parent" android:layout_height="wrap_content" yoga:yg_flexDirection="column" yoga:yg_width="100%" android:id="@+id/fl_sv_scroll" app:layout_constraintTop_toBottomOf="@+id/set_input1" app:layout_constraintStart_toStartOf="@+id/fl_scroll_root" app:layout_constraintEnd_toEndOf="@+id/fl_scroll_root" > <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" yoga:yg_height="auto" yoga:yg_paddingTop="5dp" yoga:yg_paddingBottom="5dp" yoga:yg_paddingLeft="3dp" yoga:yg_paddingRight="2dp" yoga:yg_marginTop="15dp" yoga:yg_marginLeft="10dp" yoga:yg_marginRight="10dp" android:id="@+id/set_input" android:text="@string/null_text" style="@style/style_font_auto_font_body_sample1" android:textColor="@color/yellow" android:gravity="center_vertical" android:hint="@string/edit_hint" android:textColorHint="@color/gray" android:background="@drawable/edit_text_bg" android:textCursorDrawable="@drawable/text_cursor" android:inputType="textMultiLine" /> </com.facebook.yoga.android.YogaLayout> </androidx.constraintlayout.widget.ConstraintLayout> ` # Expected Behavior ***Describe what you expected would happen.*** the second edittext grow automatically as the first edittext # Actual Behavior ***Describe what actually happened.*** the second edittext act like single line ![image](https://user-images.githubusercontent.com/2180654/212007044-add85153-5485-4abb-86b0-2e2b9e916ff7.png) # Link to Code ***If you have some code that maintainers can clone/test for themselves, bugs can be resolved much faster. Please paste a link here.*** ***When applicable, use this [fiddle](https://jsfiddle.net/emilsjolander/jckmwztt/) to post a web repro.***
NickGerleman commented 2023-01-12 04:36:18 -08:00 (Migrated from github.com)

Afaict (not a lot of specific familiarity with YogaLayout), invalidation of native views does not propagate to dirtying Yoga nodes. So if a leaf-node view changes, you need to do something like:

yogaLayout.invalidate(editText);

yogaLayout.requestLayout();
yogaLayout.invalidate();

From https://github.com/facebook/yoga/issues/956, I'm not 100% sure that will work as expected though.

There may very well be a reason for this, but it does seem strange YogaLayout doesn't participate in native layout invalidation. My understanding from quick googling is that on invalidation, EditText would call requestLayout() on its parent. So if the YogaLayout is the parent of a view with self measure function, it should be able to do the Yoga node dirtying itself.

Afaict (not a lot of specific familiarity with YogaLayout), invalidation of native views does not propagate to dirtying Yoga nodes. So if a leaf-node view changes, you need to do something like: ```java yogaLayout.invalidate(editText); yogaLayout.requestLayout(); yogaLayout.invalidate(); ``` From https://github.com/facebook/yoga/issues/956, I'm not 100% sure that will work as expected though. There may very well be a reason for this, but it does seem strange YogaLayout doesn't participate in native layout invalidation. My understanding from quick googling is that on invalidation, EditText would call `requestLayout()` on its parent. So if the YogaLayout is the parent of a view with self measure function, it should be able to do the Yoga node dirtying itself.
TChengZ commented 2023-01-15 21:44:35 -08:00 (Migrated from github.com)

Afaict (not a lot of specific familiarity with YogaLayout), invalidation of native views does not propagate to dirtying Yoga nodes. So if a leaf-node view changes, you need to do something like:

yogaLayout.invalidate(editText);

yogaLayout.requestLayout();
yogaLayout.invalidate();

From #956, I'm not 100% sure that will work as expected though.

There may very well be a reason for this, but it does seem strange YogaLayout doesn't participate in native layout invalidation. My understanding from quick googling is that on invalidation, EditText would call requestLayout() on its parent. So if the YogaLayout is the parent of a view with self measure function, it should be able to do the Yoga node dirtying itself.

Afaict (not a lot of specific familiarity with YogaLayout), invalidation of native views does not propagate to dirtying Yoga nodes. So if a leaf-node view changes, you need to do something like:

yogaLayout.invalidate(editText);

yogaLayout.requestLayout();
yogaLayout.invalidate();

From #956, I'm not 100% sure that will work as expected though.

There may very well be a reason for this, but it does seem strange YogaLayout doesn't participate in native layout invalidation. My understanding from quick googling is that on invalidation, EditText would call requestLayout() on its parent. So if the YogaLayout is the parent of a view with self measure function, it should be able to do the Yoga node dirtying itself.

yogaLayout.invalidate(editText);

this works

> Afaict (not a lot of specific familiarity with YogaLayout), invalidation of native views does not propagate to dirtying Yoga nodes. So if a leaf-node view changes, you need to do something like: > > ```java > yogaLayout.invalidate(editText); > > yogaLayout.requestLayout(); > yogaLayout.invalidate(); > ``` > > From #956, I'm not 100% sure that will work as expected though. > > There may very well be a reason for this, but it does seem strange YogaLayout doesn't participate in native layout invalidation. My understanding from quick googling is that on invalidation, EditText would call `requestLayout()` on its parent. So if the YogaLayout is the parent of a view with self measure function, it should be able to do the Yoga node dirtying itself. > Afaict (not a lot of specific familiarity with YogaLayout), invalidation of native views does not propagate to dirtying Yoga nodes. So if a leaf-node view changes, you need to do something like: > > ```java > yogaLayout.invalidate(editText); > > yogaLayout.requestLayout(); > yogaLayout.invalidate(); > ``` > > From #956, I'm not 100% sure that will work as expected though. > > There may very well be a reason for this, but it does seem strange YogaLayout doesn't participate in native layout invalidation. My understanding from quick googling is that on invalidation, EditText would call `requestLayout()` on its parent. So if the YogaLayout is the parent of a view with self measure function, it should be able to do the Yoga node dirtying itself. `yogaLayout.invalidate(editText);` this works
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DaddyFrosty/yoga#1210
No description provided.