5 Replies Latest reply on Oct 25, 2010 12:32 PM by tehxike1

    Am I using custom layouts wrong?

    tehxike1 Level 1

      I have a component that uses a custom layout to organize the items in a list both horizontally and vertically.  Because the layout pass is after the measure pass, my component has no clue what size it should be until it's too late.  Is there a way to force my component to measure itself after the items are laid out, or should I simply not be using a custom layout in this instance and instead put that logic into my component?

        • 1. Re: Am I using custom layouts wrong?
          Flex harUI Adobe Employee

          We are looking at changes in 4.5 to make this a bit easier, but the basic

          problem is that you generally want to constrain one dimension to determine

          the other.

           

          Some of our components pick a square measurement, then on updateDisplayList,

          remember the size they were given and if it is different than square, call

          invalidateSize again to force another measurement and use the remembered

          size in the measurement.  This works in simple scenarios but can cause

          invalidation loops if the measurements never stabilize.

           

          Normally there is some constraint, but it isn't explicit.  Making it

          explicit might help.  For example, you might set width="100%" on the

          component, but if the container is set to width="500", then you might as

          well just set width="500" on the component and then use the explicitWidth in

          measure().  That's how variableRowHeight renderers work.

          1 person found this helpful
          • 2. Re: Am I using custom layouts wrong?
            tehxike1 Level 1

            So is there a non-hack way to force a call to measure() after layout occurs in the Layout?  My layout is applied to a list inside my component, so I know I could do target.parent.invalidateDisplayList() to force a remeasure, but that feels horribly hackish.

             

            I really feel like I just need to move the layout code up to my component, but would prefer not doing that if it wasn't too ugly.

             

            Thanks.

            • 3. Re: Am I using custom layouts wrong?
              Flex harUI Adobe Employee

              You would call invalidateSize() in updateDisplayList to request another call

              to measure().  Our flow-based components already do that.   We're currently

              looking at changes to reduce how often that happens, but sometimes you don't

              have enough information the first time through.

               

              Moving the layout code to the component probably wouldn't help.  The

              lifecycle methods current just delegate to the layout anyway.

              1 person found this helpful
              • 4. Re: Am I using custom layouts wrong?
                tehxike1 Level 1

                Ok, invalidating size in my updateDisplayList did successfully make my component resize to exactly what it needs to be, but all of my renderers are cropped...it appears like it laid them out, clipped ones that weren't visible, then resized.

                 

                I've made a sample project, but it's far from simple- I really don't know how to simplify it any further- http://flexninja.com/examples/TimelineTest/ (view source enabled)  The checkbox toggles between two states: implicitly setting the height of the List, and allowing it to size itself.

                 

                Any help would be greatly appreciated- I feel like I'm really close to getting past this.

                • 5. Re: Am I using custom layouts wrong?
                  tehxike1 Level 1

                  I got it working by simply using the calculated size from measure() as the size for the list.  When I was assigning it to myself, the List wasn't being resized, so the cropping occurred.  Feels hackish, but works.