Skip to content
This repository was archived by the owner on Nov 17, 2022. It is now read-only.

Commit 92b97d8

Browse files
authored
Merge pull request #1756 from NativeScript/docs_modules
chore: Docs modules
2 parents 4e1370f + 34e1ab5 commit 92b97d8

File tree

7 files changed

+442
-47
lines changed

7 files changed

+442
-47
lines changed

build/build-docs.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ cp -R $DOCS_ROOT"/docs/./" $CONTENT_ROOT
7676
$SDK_ROOT_NG"/dist/code-samples/ng-hardware-access" \
7777
$CONTENT_ROOT
7878

79-
[ ! -d $MODULES_ROOT ] || cp -R $MODULES_ROOT"/bin/dist/snippets" $CONTENT_ROOT
80-
[ ! -d $NG_ROOT ] || cp -R $NG_ROOT"/bin/dist/snippets" $CONTENT_ROOT
8179
[ ! -d $CLI_ROOT ] || cp -R $CLI_ROOT"/docs-cli" $CONTENT_ROOT"/tooling"
8280
[ ! -d $SDK_ROOT_JS ] || cp -R $SDK_ROOT_JS"/dist/cookbook/ns-ui-widgets" $SDK_ROOT_JS"/dist/cookbook/ns-ui/." $CONTENT_ROOT"/ui"
8381
[ ! -d $SDK_ROOT_NG ] || cp -R $SDK_ROOT_NG"/dist/code-samples/ng-ui-widgets" $SDK_ROOT_NG"/dist/code-samples/ng-ui/." $CONTENT_ROOT"/ui"

docs/core-concepts/angular-application-architecture.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,18 @@ The navigation inside a NativeScript application is done with the [Angular Route
108108

109109
To use the Router you will have to import `NativeScriptRouterModule` into `AppModule`:
110110

111-
{%snippet router-provider%}
111+
```TypeScript
112+
import { NativeScriptRouterModule } from "nativescript-angular/router";
113+
114+
@NgModule({
115+
bootstrap: [GroceriesApp],
116+
imports: [
117+
NativeScriptRouterModule,
118+
NativeScriptRouterModule.forRoot(routes)
119+
]
120+
})
121+
export class GroceriesAppModule { }
122+
```
112123

113124
Navigation is covered in detail in the [navigation article]({% slug angular-navigation %}).
114125

docs/core-concepts/angular-navigation.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,35 @@ You might want to perform some cleanup actions (e.g. unsubscribe from a service
100100
The router configuration usually consists of the following steps:
101101

102102
Create a `RouterConfig` object which maps paths to components and parameters:
103-
{%snippet router-config%}
103+
```TypeScript
104+
export const routes = [
105+
{ path: "login", component: LoginComponent },
106+
{ path: "groceries", component: GroceryListComponent },
107+
{ path: "grocery/:id", component: GroceryComponent }
108+
];
109+
```
104110

105111

106112
Use the `NativeScriptRouterModule` API to import your routes:
107-
{%snippet router-provider%}
113+
```TypeScript
114+
import { NativeScriptRouterModule } from "nativescript-angular/router";
115+
116+
@NgModule({
117+
bootstrap: [GroceriesApp],
118+
imports: [
119+
NativeScriptRouterModule,
120+
NativeScriptRouterModule.forRoot(routes)
121+
]
122+
})
123+
export class GroceriesAppModule { }
124+
```
108125

109126

110127
As usual, pass your module to the `bootstrapModule` function to start your app:
111-
{%snippet router-bootstrap%}
128+
```TypeScript
129+
import { platformNativeScriptDynamic } from "nativescript-angular/platform";
130+
platformNativeScriptDynamic().bootstrapModule(GroceriesAppModule);
131+
```
112132

113133
## Mobile Navigation Patterns
114134

docs/plugins/angular-third-party.md

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,31 @@ Most visual components have a simple markup interface: just a tag with zero or m
2323

2424
Now, suppose you have a NativeScript UI plugin named `SimpleTag`:
2525

26-
{%snippet third-party-simple-view%}
26+
```TypeScript
27+
export class SimpleTag extends ContentView {
28+
// ...
29+
}
30+
```
2731

2832
This is a fully-functional "vanilla" NativeScript component. To register it as a valid tag for Angular templates, you need to use the element registry API:
2933

30-
{%snippet third-party-simple-view-registration%}
34+
```TypeScript
35+
import {registerElement} from "nativescript-angular/element-registry";
36+
registerElement("third-party-view", () => require("./third-party-view").SimpleTag);
37+
```
3138

3239
That maps the `SimpleTag` class to the "third-party-view" tag name. You can now use it in templates:
3340

34-
{%snippet third-party-simple-view-container%}
41+
```TypeScript
42+
@Component({
43+
selector: "simple-view-container",
44+
template: `
45+
<third-party-view prop1="value1"></third-party-view>
46+
`
47+
})
48+
export class SimpleViewContainer {
49+
}
50+
```
3551

3652
## Views and Templates
3753

@@ -41,17 +57,67 @@ The problem with accepting `View` instances as a means of configuration is that
4157

4258
To illustrate this approach, we'll assume that we have a `<document-form>` component that displays a document with a form-like UI. It allows you to customize its title by setting a preconfigured title `View` instance.
4359

44-
{%snippet third-party-document-form-component%}
60+
```TypeScript
61+
@Component({
62+
selector: "document-form",
63+
template: ""
64+
})
65+
export class DocumentFormComponent {
66+
67+
constructor() {
68+
}
69+
70+
public setTitleView(view: View) {
71+
// pass view parameter to native element...
72+
}
73+
}
74+
```
4575

4676
To support that on the Angular side, we need an Angular template nested inside the `document-form` tag. To make template discovery and manipulation easier, we associate it with a directive named `DocumentTitleDirective`. Here is what the client code looks like:
4777

48-
{%snippet third-party-document-form-container%}
78+
```TypeScript
79+
@Component({
80+
selector: "document-form-container",
81+
template: `
82+
<document-form src="document1.pdf">
83+
<Label *documentTitle text="Document1"></Label>
84+
</document-form>
85+
`
86+
})
87+
export class DocumentFormContainer {
88+
}
89+
```
4990

5091
Note the standard Angular asterisk syntax, which is just shorthand for creating a template.
5192

5293
The actual integration code is hosted in the directive implementation. It works with the Angular `TemplateRef` instance and uses the `ViewContainer` API to create and attach a view:
5394

54-
{%snippet third-party-template-directive%}
95+
```TypeScript
96+
@Directive({
97+
selector: "[documentTitle]"
98+
})
99+
export class DocumentTitleDirective {
100+
public static titleLabel: Label;
101+
constructor(
102+
private ownerForm: DocumentFormComponent,
103+
private viewContainer: ViewContainerRef,
104+
private template: TemplateRef<any>
105+
) {
106+
}
107+
108+
ngOnInit() {
109+
const viewRef = this.viewContainer.createEmbeddedView(this.template);
110+
// filter out whitespace nodes
111+
const titleViews = viewRef.rootNodes.filter((node) =>
112+
node && node.nodeName !== "#text");
113+
114+
if (titleViews.length > 0) {
115+
const titleView = titleViews[0];
116+
this.ownerForm.setTitleView(titleView);
117+
}
118+
}
119+
}
120+
```
55121

56122
Two things in the code above need mentioning:
57123

docs/ui/gestures.md

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ label.on(GestureTypes.tap, function (args: GestureEventData) {
4646
```
4747
{% endnativescript %}
4848
{% angular %}
49-
{%snippet ng-tap-gesture%}
49+
```TypeScript
50+
onTap(args: GestureEventData) {
51+
console.log("Tap!");
52+
}
53+
```
54+
```HTML
55+
<Label text="Tap here" (tap)="onTap($event)"></Label>
56+
```
5057
{% endangular %}
5158

5259
## Double Tap
@@ -72,7 +79,15 @@ label.on(GestureTypes.doubleTap, function (args: GestureEventData) {
7279
```
7380
{% endnativescript %}
7481
{% angular %}
75-
{%snippet ng-double-tap-gesture%}
82+
```TypeScript
83+
onDoubleTap(args: GestureEventData) {
84+
console.log("DoubleTap!");
85+
86+
}
87+
```
88+
```HTML
89+
<Label text="Double tap here" (doubleTap)="onDoubleTap($event)"></Label>
90+
```
7691
{% endangular %}
7792
Possible implementation:
7893
* Scale up the object with a predefined percentage, centered around the double-tapped region. If a user keeps repeating the double tap gesture, continue to scale up until the maximum scale is reached.
@@ -102,7 +117,14 @@ label.on(GestureTypes.longPress, function (args: GestureEventData) {
102117
```
103118
{% endnativescript %}
104119
{% angular %}
105-
{%snippet ng-long-press-gesture%}
120+
```TypeScript
121+
onLongPress(args: GestureEventData) {
122+
console.log("LongPress!");
123+
}
124+
```
125+
```HTML
126+
<Label text="Long press here" (longPress)="onLongPress($event)"></Label>
127+
```
106128
{% endangular %}
107129
Possible implementation: Select one or more items in a view and act upon the data using a contextual action bar. Enter data selection mode. Avoid using long press for displaying contextual menus.
108130

@@ -129,7 +151,14 @@ label.on(GestureTypes.swipe, function (args: SwipeGestureEventData) {
129151
```
130152
{% endnativescript %}
131153
{% angular %}
132-
{%snippet ng-swipe-gesture%}
154+
```TypeScript
155+
onSwipe(args: SwipeGestureEventData) {
156+
console.log("Swipe Direction: " + args.direction);
157+
}
158+
```
159+
```HTML
160+
<Label text="Swipe here" (swipe)="onSwipe($event)"></Label>
161+
```
133162
{% endangular %}
134163
Possible implementation: Navigate between views in the same hierarchy.
135164

@@ -155,7 +184,14 @@ label.on(GestureTypes.pan, function (args: PanGestureEventData) {
155184
```
156185
{% endnativescript %}
157186
{% angular %}
158-
{%snippet ng-pan-gesture%}
187+
```TypeScript
188+
onPan(args: PanGestureEventData) {
189+
console.log("Pan delta: [" + args.deltaX + ", " + args.deltaY + "] state: " + args.state);
190+
}
191+
```
192+
```HTML
193+
<Label text="Pan here" (pan)="onPan($event)"></Label>
194+
```
159195
{% endangular %}
160196

161197
## Pinch
@@ -181,7 +217,14 @@ label.on(GestureTypes.pinch, function (args: PinchGestureEventData) {
181217
```
182218
{% endnativescript %}
183219
{% angular %}
184-
{%snippet ng-pinch-gesture%}
220+
```TypeScript
221+
onPinch(args: PinchGestureEventData) {
222+
console.log("Pinch scale: " + args.scale + " state: " + args.state);
223+
}
224+
```
225+
```HTML
226+
<Label text="Pinch here" (pinch)="onPinch($event)"></Label>
227+
```
185228
{% endangular %}
186229
Possible implementation: Zoom into content or out of content.
187230

@@ -208,7 +251,14 @@ label.on(GestureTypes.rotation, function (args: RotationGestureEventData) {
208251
```
209252
{% endnativescript %}
210253
{% angular %}
211-
{%snippet ng-rotate-gesture%}
254+
```TypeScript
255+
onRotate(args: RotationGestureEventData) {
256+
console.log("Rotate angle: " + args.rotation + " state: " + args.state);
257+
}
258+
```
259+
```HTML
260+
<Label text="Rotate here" (rotation)="onRotate($event)"></Label>
261+
```
212262
{% endangular %}
213263

214264
## Touch
@@ -236,7 +286,16 @@ label.on(GestureTypes.touch, function (args: TouchGestureEventData) {
236286
```
237287
{% endnativescript %}
238288
{% angular %}
239-
{% snippet ng-touch-gesture %}
289+
```TypeScript
290+
onTouch(args: TouchGestureEventData) {
291+
console.log(
292+
"Touch point: [" + args.getX() + ", " + args.getY() +
293+
"] activePointers: " + args.getActivePointers().length);
294+
}
295+
```
296+
```HTML
297+
<Label text="Touch here" (touch)="onTouch($event)"></Label>
298+
```
240299
{% endangular %}
241300

242301
{% nativescript %}

0 commit comments

Comments
 (0)