Android YogaLayout set setVisibility to View.GONE problem #671

Closed
opened 2017-11-21 07:33:31 -08:00 by AndrewYangmq · 5 comments
AndrewYangmq commented 2017-11-21 07:33:31 -08:00 (Migrated from github.com)

Report

When I set a YoagLayout to View.GONE. It still takes the space and give it back to its parent. I already try invalidate(view), requestLayout on YoagLayout and its parent YoagLayout.

Issues and Steps to Reproduce

Please see the xml and code below. Just click the change button and it will show or hide the content of YogaLayout1. But when it hides it, the space is still reserved and not given back to its parent. This never happens when I used Android LinearLayout as the container.

The only way to make the YogaLayout give back its space is to remove it from its parent YogaLayout. But when I add it back when I want to show it, it is not displayed properly. Please see the screen shots below.

Expected Behavior

When we set yogalayout Visibility to View.GONE, it should not take its space any more.

Actual Behavior

The yogalayout still takes the space.
Following pictures are in order of:
1-initial screen
2-after setVisibility to View.GONE
3-use removeview approach
4- after removing the yogalayout and add it back in its parent yogalayout at index 0.
1
2
3
4

Link to Code

https://gist.github.com/AndrewYangmq/4be91e3031863a487448bb3ca02d620d

# Report When I set a YoagLayout to View.GONE. It still takes the space and give it back to its parent. I already try invalidate(view), requestLayout on YoagLayout and its parent YoagLayout. - [x ] I have searched [existing issues](https://github.com/facebook/yoga/issues) and this is not a duplicate # Issues and Steps to Reproduce Please see the xml and code below. Just click the change button and it will show or hide the content of YogaLayout1. But when it hides it, the space is still reserved and not given back to its parent. This never happens when I used Android LinearLayout as the container. The only way to make the YogaLayout give back its space is to remove it from its parent YogaLayout. But when I add it back when I want to show it, it is not displayed properly. Please see the screen shots below. # Expected Behavior When we set yogalayout Visibility to View.GONE, it should not take its space any more. # Actual Behavior The yogalayout still takes the space. Following pictures are in order of: 1-initial screen 2-after setVisibility to View.GONE 3-use removeview approach 4- after removing the yogalayout and add it back in its parent yogalayout at index 0. ![1](https://user-images.githubusercontent.com/33296921/33080681-af367456-cea6-11e7-94a8-dc0b44fb91bc.png) ![2](https://user-images.githubusercontent.com/33296921/33080682-af4ac6e0-cea6-11e7-8144-f31764bda14d.png) ![3](https://user-images.githubusercontent.com/33296921/33080679-af17b2b4-cea6-11e7-84ee-fa2119257a30.png) ![4](https://user-images.githubusercontent.com/33296921/33080680-af2957ee-cea6-11e7-87ea-e95db7f31505.png) # Link to Code https://gist.github.com/AndrewYangmq/4be91e3031863a487448bb3ca02d620d
uziasferreirazup commented 2020-09-22 07:01:36 -07:00 (Migrated from github.com)

hey @AndrewYangmq did you find some solution about this?

hey @AndrewYangmq did you find some solution about this?
290125120 commented 2021-04-07 00:43:41 -07:00 (Migrated from github.com)

I alse meet this problem, is anyone find some solution?

I alse meet this problem, is anyone find some solution?
hou3172568 commented 2021-04-13 22:51:32 -07:00 (Migrated from github.com)

in YogaLayout.ViewMeasureFunction#measure,change if (view == null || view instanceof YogaLayout) { return YogaMeasureOutput.make(0, 0); } to if (view == null || view instanceof YogaLayout || view.getVisibility() == GONE){.....}
but when a child View in YogaLayout,it's unuseful!!

in `YogaLayout.ViewMeasureFunction#measure`,change `if (view == null || view instanceof YogaLayout) { return YogaMeasureOutput.make(0, 0); }` to ` if (view == null || view instanceof YogaLayout || view.getVisibility() == GONE){.....}` but when a child View in YogaLayout,it's unuseful!!
hou3172568 commented 2021-04-25 07:12:56 -07:00 (Migrated from github.com)

hello,I'm back。
I found the way to fix this bug.
In

YogaLayout#addView(android.view.View, int, android.view.ViewGroup.LayoutParams)

,when add a child ,if it's GONE,we save the current index, the code like

if (child.getVisibility() == GONE) {
        //save the current index
           child.setTag(R.id.yoga_child_position, mYogaNode.getChildCount());
       } else {
           mYogaNode.addChildAt(childNode, mYogaNode.getChildCount());
       }

then we add a function to change the Child's visibility,and add it‘s YogaNode to correct index,and calculate it's parent YogaNode,the code like

public void setChildVisibility(View child, int value) {
        child.setVisibility(value);
        YogaNode childNode = mYogaNodes.get(child); 
        Object object = child.getTag(R.id.yoga_child_position); 
        if (value == VISIBLE) {
         
            if (object != null && mYogaNode.indexOf(childNode) == -1) {
                int index = (int) object;
                if (index < mYogaNode.getChildCount()) {
                    mYogaNode.addChildAt(mYogaNodes.get(child), index);
                } else {
                    mYogaNode.addChildAt(mYogaNodes.get(child), mYogaNode.getChildCount());
                }
                reCalculate(mYogaNode);
            }
        } else if (value == GONE) {
           
            int childIndex = mYogaNode.indexOf(childNode);
            if (childIndex != -1) {
              
                mYogaNode.removeChildAt(childIndex);
               
                child.setTag(R.id.yoga_child_position, childIndex);
                reCalculate(mYogaNode);
            }
        }

    }

   //reset the width and height,and calculate
    private void reCalculate(YogaNode node){
       
        node.setWidth(Float.NaN);
        node.setHeight(Float.NaN);
        if(node.getOwner()!=null){
//look up
            reCalculate(node.getOwner());
        }else{
          
            node.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
        }
    }
hello,I'm back。 I found the way to fix this bug. In ```java YogaLayout#addView(android.view.View, int, android.view.ViewGroup.LayoutParams) ``` ,when add a child ,if it's ``GONE``,we save the current index, the code like ```java if (child.getVisibility() == GONE) { //save the current index child.setTag(R.id.yoga_child_position, mYogaNode.getChildCount()); } else { mYogaNode.addChildAt(childNode, mYogaNode.getChildCount()); } ``` then we add a function to change the Child's visibility,and add it‘s YogaNode to correct index,and calculate it's parent ``YogaNode``,the code like ```java public void setChildVisibility(View child, int value) { child.setVisibility(value); YogaNode childNode = mYogaNodes.get(child); Object object = child.getTag(R.id.yoga_child_position); if (value == VISIBLE) { if (object != null && mYogaNode.indexOf(childNode) == -1) { int index = (int) object; if (index < mYogaNode.getChildCount()) { mYogaNode.addChildAt(mYogaNodes.get(child), index); } else { mYogaNode.addChildAt(mYogaNodes.get(child), mYogaNode.getChildCount()); } reCalculate(mYogaNode); } } else if (value == GONE) { int childIndex = mYogaNode.indexOf(childNode); if (childIndex != -1) { mYogaNode.removeChildAt(childIndex); child.setTag(R.id.yoga_child_position, childIndex); reCalculate(mYogaNode); } } } //reset the width and height,and calculate private void reCalculate(YogaNode node){ node.setWidth(Float.NaN); node.setHeight(Float.NaN); if(node.getOwner()!=null){ //look up reCalculate(node.getOwner()); }else{ node.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); } } ```
NickGerleman commented 2023-04-25 20:43:59 -07:00 (Migrated from github.com)

We're deprecating the com.facebook.yoga.android.YogaLayout ViewGroup in the next major release of Yoga. We intend to still push out a new version aligned to the core Yoga 2.0. I have bulk closed ViewGroup issues to reflect that we are not planning to invest time into functional changes of the ViewGroup. and eventually intend to remove it from the repo.

We're deprecating the `com.facebook.yoga.android.YogaLayout` ViewGroup in the next major release of Yoga. We intend to still push out a new version aligned to the core Yoga 2.0. I have bulk closed ViewGroup issues to reflect that we are not planning to invest time into functional changes of the ViewGroup. and eventually intend to remove it from the repo.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DaddyFrosty/yoga#671
No description provided.