官术网_书友最值得收藏!

Our first view via component building

If we look at our sketch from Chapter 1, Get into Shape with @NgModule, we can see a header at the top of the app, which will contain our app title with the record button to the right. We also see a listing of tracks with some player controls at the bottom. We can break these key elements of our UI design into essentially three primary components. One component is already provided by the NativeScript framework, the ActionBar, which we will use to represent the top header. 

NativeScript provides many rich view components to build our UI. The markup is not HTML but rather XML with an .html extension, which may seem unusual. The reason the .html extension is used for XML view templates with NativeScript for Angular is that the custom renderer (https://github.com/NativeScript/nativescript-angular) uses a DOM adapter to parse the view template. Each NativeScript XML component represents true native view widgets on each respective platform.

For the other two primary components, we will use Angular's Component decorator. It's important at this phase of the app development cycle to think about encapsulated pieces of UI functionality. We will encapsulate our track listing as a component and the player controls as another component. In this exercise, we will use an outside-in approach to building our UI from an abstract viewpoint down to the implementation details of each component. 

To begin, let's focus on the root component in our Angular app because it will define the basic layout of our first view. Open app/app.component.html, clear its contents, and replace with the following to rough out the initial UI concept from our sketch:

<ActionBar title="TNSStudio">
</ActionBar>
<GridLayout rows="*, 100" columns="*">
<track-list row="0" col="0"></track-list>
<player-controls row="1" col="0"></player-controls>
</GridLayout>

We are expressing our view with ActionBar and the primary layout container for the main view, GridLayout. With NativeScript, it's important that each view starts with a layout container as the root node (outside of any ActionBar or ScrollView), much like div tags that are used with HTML markup. At the time of this writing, there are six layout containers provided by NativeScript: StackLayout, GridLayout, FlexboxLayout, AbsoluteLayout, DockLayout, and WrapLayout. For our layout here, GridLayout will work well.

主站蜘蛛池模板: 盐源县| 壶关县| 和平县| 鹿泉市| 巴林右旗| 河南省| 浠水县| 高淳县| 嫩江县| 甘肃省| 罗田县| 彰武县| 吉隆县| 电白县| 孟州市| 博乐市| 武平县| 酒泉市| 松溪县| 大悟县| 甘孜县| 宿迁市| 章丘市| 蒙自县| 黄大仙区| 文成县| 象州县| 腾冲县| 哈尔滨市| 玉山县| 驻马店市| 宁远县| 邵武市| 平江县| 石嘴山市| 湟中县| 屯门区| 醴陵市| 抚远县| 霍林郭勒市| 龙江县|