3

I am trying to add a image below a scrollview using the famous sequentialLayout and im having a problem with the scrollview's height.

This is how i create my scrollview.

var scrollview = new Scrollview({       
    direction: Utility.Direction.X,
    options: {
        size: [300, 300]
    },        
    paginated: true
});

When i add surfaces to the scrollview with 250 height, the scrollview's parent DOM container (famous-group) containing these surfaces has a width and height of 0.

When adding this scrollview within a sequentialLayout as the first item, the second item or surface with a height is displayed on top of this scrollview since it has no height.

Any ideas how to fix this using Famo.us?

nytrm
  • 509
  • 1
  • 5
  • 15

1 Answers1

9

You can't set size like that - use a modifier for this.

This will be the render tree

MainContext
   SequentialLayout
      Modifier(size)
          ScrollView
      Modifier(size)
          Image

Code snippet:

// Create components
var scrollview = new ScrollView();
var image = new ImageSurface({
    content: 'content/images/famous_symbol_transparent.png'
});

// Create Size Modifiers
var scrollModifier = new StateModifier({ size: [200,200]});
var imageModifier = new StateModifier({ size: [200,200]});

// Wrap the Modifier in a RenderNode, so we can add the surface
// (you can't add surfaces directly to a modifier)
var scrollNode = new RenderNode(scrollModifier)
scrollNode.add(scrollview);

var imageNode = new RenderNode(imageModifier);
imageNode.add(image);

// Create a SequentialLayout
var sequence = new SequentialLayout();
sequence.sequenceFrom([scrollNode,imageNode]);

And here is an example gist (copy-paste the main.js after running the yo famous generator)

markmarijnissen
  • 5,569
  • 2
  • 28
  • 34
  • You are correct, found this out myself aswel but your code is better written and documented :-) Thanks! – nytrm Apr 14 '14 at 13:06
  • 1
    Your welcome! It is even more fun is you use "scrollModifier.sizeFrom" to dynamically set size to 50% of your screenheight! – markmarijnissen Apr 14 '14 at 16:25