question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Layout issue when using custom components in a GridLayout

See original GitHub issue

When using this type of layout in conjunction with Angular components (one of which uses a ListView underneath) creates the following troublesome layout.

I would expect this layout to just work:

<GridLayout rows="*,100" columns="*">
    <test-list-cmp row="0" col="0"></test-list-cmp> <!-- This has ListView underneath -->
    <test-cmp row="1" col="0"></test-cmp>
</GridLayout>

Simple sample project which demonstrates this problem: https://github.com/NathanWalker/layout-bug-demo

Screenshot of problem… screen shot 2017-01-23 at 10 46 00 pm

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
m-abscommented, Feb 7, 2017

Hi @NathanWalker,

I don’t think it has anything to do with the ListView. If you wrap the custom components inside a StackLayout and set row/col on that, the problem goes away (at least on Android).

<ActionBar title="Test" icon="" class="action-bar">
</ActionBar>
<GridLayout rows="*,100" columns="*">
  <StackLayout row="0" col="0">
    <test-list-cmp></test-list-cmp>
  </StackLayout>
  <StackLayout row="1" col="0">
    <test-cmp></test-cmp>
  </StackLayout>
</GridLayout>

I can’t find the link with the explanation and the workaround I once had.

As I remember it, the problem is that layout properties are not inherited by the custom components. (It might have something to do with them being wrapped inside a ProxyViewContainer, but I can’t remember).

So you either have to wrap the custom component inside a StackLayout OR add the layout properties inside you custom component like this:

<GridLayout rows="100" columns="75,*" [row]="cRow" [col]="cCol">
    <Label text="Sample" row="0" col="0"></Label>
    <Label text="This layout issue is troublesome." row="0" col="1"></Label>
</GridLayout>
import { Component, Input } from '@angular/core';

@Component({
	moduleId: module.id,
	selector: 'test-cmp',
	templateUrl: 'test-cmp.component.html'
})
export class TestCmpComponent {
  @Input() cRow: number;
  @Input() cCol: number;
}
3reactions
m-abscommented, Jul 14, 2018

We’ve been using another workaround for a while.

If you change the selector to include an attribute selector, e.g. from test-cmp to test-cmp, [test-cmp] you can use the component like this:

<GridLayout rows="*,100" columns="*">
    <StackLayout test-list-cmp row="0" col="0"></StackLayout> <!-- This has ListView underneath -->
    <StackLayout test-cmp row="1" col="0"></StackLayout>
</GridLayout>

It is a lot prettier than the old workaround.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Component · Issue #1241 · react-grid-layout ... - GitHub
Hello, how do I use a custom component as grid item? I couldn't find anything on the guide and I'm quite new in...
Read more >
Solving Common Layout Problems (The Java™ Tutorials ...
If the component is not controlled by a layout manager, you can set its size by invoking the setSize or setBounds method on...
Read more >
Components in GridLayout don't show properly - Stack Overflow
It has to do with the way GridLayout behaves when both the rows and columns are set to non-zero values. The LayoutManager decides...
Read more >
Statuspage custom component grid layout by group (table)
I am wondering how I could create a grid layout for my components grouped by region where each group is a region and...
Read more >
Relationship of grid layout to other layout methods - CSS
This is where you want a two-dimensional layout method: You want to control the alignment by row and column, and this is where...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found