Skip to content

Commit 8c69654

Browse files
OmbuwebNathanWalkerSeanKelly369
authored
docs: The Layout Process (#29)
Co-authored-by: Nathan Walker <[email protected]> Co-authored-by: Sean Kelly <[email protected]>
1 parent fddbbd3 commit 8c69654

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

content/guide/the-layout-process.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: The Layout Process
3+
---
4+
5+
The ability for all your views to render with the right dimensions and positions requires a run of "the layout process". When rendering, a recursive process runs through every view in the **view hierarchy** in two passes &mdash; a measure pass and a layout pass.
6+
7+
During **the measure pass** every view is measured to obtain its desired size. The following properties are considered during the measuring:
8+
9+
- `width`, `height`
10+
- `minWidth`, `minHeight`
11+
- `visibility`
12+
- `marginTop`, `marginRight`, `marginBottom`, `marginLeft`
13+
14+
During **the layout pass** every view is placed in a specific layout slot. The slot is determined by the result of the measure pass and the following properties:
15+
16+
- `marginTop`, `marginRight`, `marginBottom`, `marginLeft`
17+
- `horizontalAlignment`, `verticalAlignment`
18+
19+
The layout process is by nature an resource-intensive process and it's performance highly depends on the number views (and complexity).
20+
<!-- TODO: fix links -->
21+
:::tip
22+
It's a good practice to minimize deep nesting of views. Instead, utilize different [Layout Containers](/ui/#layout-containers) to achieve a simpler and more organized view hierarchy. This approach improves readability, maintainability and performance.
23+
24+
**For example:** don't treat `<StackLayout>` as a `<div>` &mdash; instead try to use a `<GridLayout>` with specific `rows` and `columns` to achieve the same result:
25+
26+
- Bad Practice:
27+
28+
```html
29+
<StackLayout>
30+
<StackLayout orientation="horizontal">
31+
<SomeItem />
32+
<SomeItem />
33+
</StackLayout>
34+
<StackLayout orientation="horizontal">
35+
<!-- ... -->
36+
</StackLayout>
37+
</StackLayout>
38+
```
39+
40+
- Good Practice:
41+
<!-- -->
42+
43+
```html
44+
<GridLayout rows="auto, auto" columns="auto, auto">
45+
<SomeItem row="0" col="0" />
46+
<SomeItem row="0" col="1" />
47+
<!-- ... row="1" ... -->
48+
</GridLayout>
49+
```
50+
51+
One-offs are fine with the `<StackLayout>` approach, but building an entire app with the first approach will usually result in poor performance.
52+
53+
:::

content/sidebar.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ export default [
288288
text: 'Property System',
289289
link: '/guide/property-system',
290290
},
291+
{
292+
text: 'Layout',
293+
link: '/guide/the-layout-process'
294+
},
291295
{
292296
text: 'Error Handling',
293297
link: '/guide/error-handling',

0 commit comments

Comments
 (0)