You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>At this point you can add a grocery item and it will appear immediately in your list—and, all of this is completely driven by a backend service. Pretty cool, huh?</p>
1446
1446
<p>Let's look at how you can polish this page with a NativeScript module for showing activity indicators.</p>
1447
1447
<h3id="activityindicator">ActivityIndicator</h3>
1448
-
<p>Introduce the activity indicator.</p>
1448
+
<p>Currently there's a bit of a delay when you first visit the list page before groceries appear. This delay could confuse a new user, who might think the app is stuck rather than retrieving data from a backend.</p>
1449
+
<p>In NativeScript apps you can use the <ahref="http://docs.nativescript.org/ApiReference/ui/activity-indicator/README">ActivityIndicator</a> module to show a spinner icon in your UI while your app is busy performing actions. The ActivityIndicator is a relatively simple UI element as it primarily uses one attribute—<code>busy</code>. When an ActivityIndicator's <code>busy</code> attribute is set to <code>true</code> the ActivityIndicator shows, and when its <code>busy</code> attribute is set to <code>false</code> it doesn't. Let's see how the module works by adding an ActivityIndicator to the list page.</p>
1449
1450
<h4class="exercise-start">
1450
-
<b>Exercise</b>: ???
1451
+
<b>Exercise</b>: Add an ActivityIndicator
1451
1452
</h4>
1452
1453
1453
1454
<p>Open up <code>app/pages/list/list.html</code> and paste the following line immediately before the final <code></GridLayout></code>:</p>
<p>Next, open <code>app/pages/list/list.component.ts</code> and add the following property to the <code>ListPage</code> class (immediately under <code>grocery: string</code>):</p>
1457
+
<p>This binds the ActivityIndicator’s <code>busy</code> attribute to an <code>isLoading</code> property in the <code>ListPage</code> component. To define that property, open <code>app/pages/list/list.component.ts</code> and add the following line of codeimmediately under <code>grocery: string = ""</code>:</p>
<p>Then, change the existing <code>ngOnInit()</code> function to use the code below:</p>
1460
+
<p>Now that the property exists, your final step is to set this flag to to <code>true</code> when the grocery data is loading. To do that, change the existing <code>ngOnInit()</code> function to use the code below:</p>
<p>Talk about how that works, then introduce how an animation can add a little polish.</p>
1474
+
<p>When you first visit the list page, you should now see the following loading indicators:</p>
1475
+
<p><imgsrc="images/chapter4/android/7.png" alt="ActivityIndicator on Android">
1476
+
<imgsrc="images/chapter4/ios/7.png" alt="ActivityIndicator on iOS"></p>
1477
+
<blockquote>
1478
+
<p><strong>TIP</strong>: You can apply the same <code>row</code> or <code>column</code> attribute to multiple UI controls to have them take up the same space on the screen. The UI control that is defined last will appear on top, which is why the <code><ActivityIndicator></code> appears on top of the <code><ListView></code> in the previous example.</p>
<p>To finish off this chapter, let’s look at how you can use the animation module to add a final bit of polish to how the list page loads.</p>
1474
1484
<h4class="exercise-start">
1475
-
<b>Exercise</b>: ???
1485
+
<b>Exercise</b>: Add a fade-in animation
1476
1486
</h4>
1477
1487
1478
-
<p>Open <code>app/pages/list/list-common.css</code> and paste the following CSS at the top of the file:</p>
1488
+
<p>In this exercise, you’ll use the animation module to animate the <code>opacity</code> of the list page’s <code><ListView></code> to add a fade-in effect. Start by opening <code>app/pages/list/list-common.css</code> and pasting in the following CSS at the top of the file:</p>
<p>Talk about what happened. Include a gif. Transition to talking about npm modules and {N} plugins.</p>
1512
+
<p>A few things are happening in the code above.</p>
1513
+
<p>First, in CSS, you assign an <code>opacity</code> of <code>0</code> to the list page’s <code><ListView></code>. This hides the grocery list completely when the page loads. Next, in TypeScript, after the <code>GroceryListService</code>’s <code>load()</code> call completes, you call the list view’s <code>animate()</code> function. This changes the element's <code>opacity</code> from <code>0</code> (completely hidden) to <code>1</code> (completely visible) over one full second.</p>
1514
+
<p>The result of this code is a nice fade-in animation:</p>
1515
+
<p><imgsrc="images/chapter4/android/8.gif" alt="Loading animation on Android">
1516
+
<imgsrc="images/chapter4/ios/8.gif" alt="Loading animation on iOS"></p>
1517
+
<p>Now that you have functional login and list pages, let’s enhance the app’s functionality as a grocery list management tool. In the next chapters you'll add functionality such as email validation, social sharing, and more. And you’ll use one of NativeScript's most useful features to do so: npm modules.</p>
1518
+
<blockquote>
1519
+
<p><strong>TIP</strong>: There are several modules that come out of the box with your NativeScript installation that we did not have time to cover in this guide—including a <ahref="{{site.baseurl}}/ApiReference/location/HOW-TO">location service</a>, a <ahref="{{site.baseurl}}/ApiReference/file-system/HOW-TO">file-system helper</a>, a <ahref="{{site.baseurl}}/ApiReference/timer/HOW-TO">timer module</a>, a <ahref="{{site.baseurl}}/ApiReference/camera/HOW-TO">camera module</a>, and a whole lot more. Make sure to peruse the “Modules API” of the docs, or just look around <code>node_modules/tns-core-modules</code> to see all of what’s available.</p>
Copy file name to clipboardExpand all lines: src/chapters/chapter4.md
+32-8Lines changed: 32 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -563,10 +563,12 @@ Let's look at how you can polish this page with a NativeScript module for showin
563
563
564
564
### ActivityIndicator
565
565
566
-
Introduce the activity indicator.
566
+
Currently there's a bit of a delay when you first visit the list page before groceries appear. This delay could confuse a new user, who might think the app is stuck rather than retrieving data from a backend.
567
+
568
+
In NativeScript apps you can use the [ActivityIndicator](http://docs.nativescript.org/ApiReference/ui/activity-indicator/README) module to show a spinner icon in your UI while your app is busy performing actions. The ActivityIndicator is a relatively simple UI element as it primarily uses one attribute—`busy`. When an ActivityIndicator's `busy` attribute is set to `true` the ActivityIndicator shows, and when its `busy` attribute is set to `false` it doesn't. Let's see how the module works by adding an ActivityIndicator to the list page.
567
569
568
570
<h4 class="exercise-start">
569
-
<b>Exercise</b>: ???
571
+
<b>Exercise</b>: Add an ActivityIndicator
570
572
</h4>
571
573
572
574
Open up `app/pages/list/list.html` and paste the following line immediately before the final `</GridLayout>`:
@@ -575,13 +577,13 @@ Open up `app/pages/list/list.html` and paste the following line immediately befo
Next, open `app/pages/list/list.component.ts` and add the following property to the `ListPage` class (immediately under `grocery:string`):
580
+
This binds the ActivityIndicator’s `busy` attribute to an `isLoading` property in the `ListPage` component. To define that property, open `app/pages/list/list.component.ts` and add the following line of code immediately under `grocery:string=""`:
579
581
580
582
```TypeScript
581
583
isLoading =false;
582
584
```
583
585
584
-
Then, change the existing `ngOnInit()` function to use the code below:
586
+
Now that the property exists, your final step is to set this flag to to `true` when the grocery data is loading. To do that, change the existing `ngOnInit()` function to use the code below:
Talk about what happened. Include a gif. Transition to talking about npm modules and {N} plugins.
650
+
A few things are happening in the code above.
651
+
652
+
First, in CSS, you assign an `opacity` of `0` to the list page’s `<ListView>`. This hides the grocery list completely when the page loads. Next, in TypeScript, after the `GroceryListService`’s `load()` call completes, youcallthelistview’s`animate()`function. This changes the element's `opacity` from `0` (completelyhidden) to `1` (completelyvisible) over one full second.
653
+
654
+
The result of this code is a nice fade-in animation:
655
+
656
+

657
+

658
+
659
+
Now that you have functional login and list pages, let’s enhance the app’s functionality as a grocery list management tool. In the next chapters you'll add functionality such as email validation, social sharing, and more. And you’ll use one of NativeScript's most useful features to do so: npm modules.
660
+
661
+
> **TIP**: There are several modules that come out of the box with your NativeScript installation that we did not have time to cover in this guide—including a [location service]({{site.baseurl}}/ApiReference/location/HOW-TO), a [file-system helper]({{site.baseurl}}/ApiReference/file-system/HOW-TO), a [timer module]({{site.baseurl}}/ApiReference/timer/HOW-TO), a [camera module]({{site.baseurl}}/ApiReference/camera/HOW-TO), and a whole lot more. Make sure to peruse the “Modules API” of the docs, or just look around `node_modules/tns-core-modules` to see all of what’s available.
0 commit comments