Skip to content

Commit 8e83717

Browse files
committed
Starting my second pass through 4.3
1 parent 19f85fc commit 8e83717

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

images/chapter4/android/5.png

31.2 KB
Loading

images/chapter4/ios/5.png

36.2 KB
Loading

index.html

+28-5
Original file line numberDiff line numberDiff line change
@@ -1316,12 +1316,12 @@ <h4 class="exercise-start">
13161316
<img src="images/chapter4/ios/4.png" alt="Grocery data on iOS"></p>
13171317
<p>At this point you have a list of data associated with each account that you display in a list view control, but a grocery list isn’t very useful if you can’t add to the list. Let’s look at how to do that next.</p>
13181318
<h3 id="gridlayout">GridLayout</h3>
1319-
<p>Introduce what a grid layout actually is. Should be able to copy from the existing guide liberally.</p>
1319+
<p>In order to allow users to add to their grocery lists you need to add a few additional UI controls to the list page. While you could layout these elements with a <code>&lt;StackLayout&gt;</code>, let’s look at how to create a slightly more complex layout using the <code>&lt;GridLayout&gt;</code> element.</p>
13201320
<h4 class="exercise-start">
1321-
<b>Exercise</b>: ???
1321+
<b>Exercise</b>: Add a GridLayout
13221322
</h4>
13231323

1324-
<p>Open <code>app/pages/list/list.html</code> and paste in the following code:</p>
1324+
<p>Open <code>app/pages/list/list.html</code> and replace the contents of the file with the following code:</p>
13251325
<pre><code class="lang-XML">&lt;GridLayout rows=&quot;auto, *&quot;&gt;
13261326

13271327
&lt;GridLayout row=&quot;0&quot; columns=&quot;*, auto&quot; class=&quot;add-bar&quot;&gt;
@@ -1339,8 +1339,31 @@ <h4 class="exercise-start">
13391339
</code></pre>
13401340
<div class="exercise-end"></div>
13411341

1342-
<p>Show an image of what this looks like first and then break down the syntax in detail.</p>
1343-
<p>Now let’s make the add button actually work.</p>
1342+
<p>When your app runs with these changes your UI should now look like this:</p>
1343+
<p><img src="images/chapter4/android/5.png" alt="Updated view on Android">
1344+
<img src="images/chapter4/ios/5.png" alt="Updated view on iOS"></p>
1345+
<p>To break down how this layout works, let’s start with the outer structure of the markup:</p>
1346+
<pre><code class="lang-XML">&lt;GridLayout rows=&quot;auto, *&quot;&gt;
1347+
&lt;GridLayout row=&quot;0&quot; class=&quot;add-bar&quot;&gt;...&lt;/GridLayout&gt;
1348+
&lt;ListView row=&quot;1&quot;&gt;...&lt;/ListView&gt;
1349+
&lt;/GridLayout&gt;
1350+
</code></pre>
1351+
<p>The outer grid layout’s <code>rows</code> attribute divides the screen into two rows, the first auto-sized according to its childrens&#39; height, and the other to contain *, or the remaining height of the screen. You place UI elements into these rows using the zero-based <code>row</code> attribute. You place inner grid layout in the top row with the <code>row=&quot;0&quot;</code> attribute, and the list view in the bottom row with the <code>row=&quot;1&quot;</code> attribute.</p>
1352+
<p>Grid layouts can also divide the screen into columns, which is what the inner grid layout does:</p>
1353+
<pre><code class="lang-XML">&lt;GridLayout columns=&quot;*, auto&quot; class=&quot;add-bar&quot;&gt;
1354+
&lt;TextField col=&quot;0&quot;&gt;&lt;/TextField&gt;
1355+
&lt;Image col=&quot;1&quot;&gt;&lt;/Image&gt;
1356+
&lt;/GridLayout&gt;
1357+
</code></pre>
1358+
<p>Here the <code>columns</code> attribute divides the top of the screen into two columns. The <code>col=&quot;0&quot;</code> attribute puts the text field in the first column, and the <code>col=&quot;1&quot;</code> attribute puts the plus image in the last column. Grid layouts are the most commonly used NativeScript layout, so you may wish to take a minute to play around with the <code>columns</code> and <code>rows</code> attributes to figure out how they work.</p>
1359+
<blockquote>
1360+
<p><strong>TIP</strong>:</p>
1361+
<ul>
1362+
<li>You can nest any of the <a href="http://docs.nativescript.org/ui/layout-containers.html">NativeScript layouts</a>—not just grid layouts.</li>
1363+
<li>You can pass numbers, percentages, and a variety of other values to create more complex grid layouts. Refer to the <a href="http://docs.nativescript.org/ui/layout-containers.html#gridlayout">grid layout docs</a> for more information.</li>
1364+
</ul>
1365+
</blockquote>
1366+
<p>Now that we have the UI ready, let’s make the add button work.</p>
13441367
<h4 class="exercise-start">
13451368
<b>Exercise</b>: ???
13461369
</h4>

src/chapters/chapter4.md

+34-5
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,13 @@ At this point you have a list of data associated with each account that you disp
395395
396396
### GridLayout
397397
398-
Introduce what a grid layout actually is. Should be able to copy from the existing guide liberally.
398+
In order to allow users to add to their grocery lists you need to add a few additional UI controls to the list page. While you could layout these elements with a `<StackLayout>`, let’s look at how to create a slightly more complex layout using the `<GridLayout>` element.
399399
400400
<h4 class="exercise-start">
401-
<b>Exercise</b>: ???
401+
<b>Exercise</b>: Add a GridLayout
402402
</h4>
403403
404-
Open `app/pages/list/list.html` and paste in the following code:
404+
Open `app/pages/list/list.html` and replace the contents of the file with the following code:
405405
406406
``` XML
407407
<GridLayout rows="auto, *">
@@ -422,9 +422,38 @@ Open `app/pages/list/list.html` and paste in the following code:
422422
423423
<div class="exercise-end"></div>
424424
425-
Show an image of what this looks like first and then break down the syntax in detail.
425+
When your app runs with these changes your UI should now look like this:
426+
427+
![Updated view on Android](images/chapter4/android/5.png)
428+
![Updated view on iOS](images/chapter4/ios/5.png)
429+
430+
To break down how this layout works, let’s start with the outer structure of the markup:
431+
432+
``` XML
433+
<GridLayout rows="auto, *">
434+
<GridLayout row="0" class="add-bar">...</GridLayout>
435+
<ListView row="1">...</ListView>
436+
</GridLayout>
437+
```
438+
439+
The outer grid layout’s `rows` attribute divides the screen into two rows, the first auto-sized according to its childrens' height, and the other to contain *, or the remaining height of the screen. You place UI elements into these rows using the zero-based `row` attribute. You place inner grid layout in the top row with the `row="0"` attribute, and the list view in the bottom row with the `row="1"` attribute.
440+
441+
Grid layouts can also divide the screen into columns, which is what the inner grid layout does:
442+
443+
``` XML
444+
<GridLayout columns="*, auto" class="add-bar">
445+
<TextField col="0"></TextField>
446+
<Image col="1"></Image>
447+
</GridLayout>
448+
```
449+
450+
Here the `columns` attribute divides the top of the screen into two columns. The `col="0"` attribute puts the text field in the first column, and the `col="1"` attribute puts the plus image in the last column. Grid layouts are the most commonly used NativeScript layout, so you may wish to take a minute to play around with the `columns` and `rows` attributes to figure out how they work.
451+
452+
> **TIP**:
453+
> * You can nest any of the [NativeScript layouts](http://docs.nativescript.org/ui/layout-containers.html)—not just grid layouts.
454+
> * You can pass numbers, percentages, and a variety of other values to create more complex grid layouts. Refer to the [grid layout docs](http://docs.nativescript.org/ui/layout-containers.html#gridlayout) for more information.
426455
427-
Now let’s make the add button actually work.
456+
Now that we have the UI ready, let’s make the add button work.
428457
429458
<h4 class="exercise-start">
430459
<b>Exercise</b>: ???

0 commit comments

Comments
 (0)