Skip to content

Commit abc5f8d

Browse files
committed
chore: rootlayout, code sharing and touchups
1 parent 5c9037b commit abc5f8d

File tree

7 files changed

+190
-34
lines changed

7 files changed

+190
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.DS_Store
12
.vitepress/dist
23
node_modules
34
package-lock.json

.vitepress/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ function getSidebar() {
117117
text: 'Performance',
118118
children: [{ text: 'Performance', link: '/performance' }],
119119
},
120+
{
121+
text: 'Scalability',
122+
children: [{ text: 'Code Sharing', link: '/code-sharing/index' }],
123+
},
120124
{
121125
text: 'Advanced Concepts',
122126
children: [

best-practices/index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ title: Best Practices
44

55
## NativeScript Best Practices
66

7+
### The story of 😢 or 😊
8+
79
Over the years several distinct best practices have emerged when working with NativeScript and we'd like to outline a few here for you in hopes that you can enjoy NativeScripting as much as we do. More importantly though, that your end product gives you all the right _feels_ you expect.
810

9-
We are providing a sample "vanilla" NativeScript app which shows some of the good vs. bad practices for you to run and see for yourself.
10-
Using vanilla NativeScript is a great way to see the raw examples of why these are good and bad practices and are applicable to any frontend framework integration. Each framework integration effectively utilitizes these same practices for it's own various cases.
11+
We are providing a sample "vanilla" NativeScript app which shows some of the bad vs. good practices for you to run and see for yourself.
12+
Using vanilla NativeScript is a great way to see the raw examples of why these are bad and good practices which are applicable to any frontend framework integration. Each framework integration effectively utilitizes these same practices for it's own various cases.
1113

1214
Clone and see for yourself: https://github.com/NativeScript/examples-best-practices
1315

code-sharing/index.md

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
title: Code Sharing
33
---
44

5+
JavaScript provides opportunities of immense scalability if architectured properly.
6+
7+
One key word that often comes up in this department is **"code sharing"**.
8+
9+
Over the years, several lessons have emerged around scalability with JavaScript in lieu of NativeScript in particular.
10+
511
**The NativeScript TSC's 5 fundamental lessons about good code sharing**
612

713
1. If you can share your code easily with other paradigms, other disciplines, other runtimes even, then you have a good code sharing approach that will continue to provide you and your team joy. No developer or team willingly gets into code sharing hoping to find themselves in a corner later. You always want to share now to more easily maintain and scale the code later.
@@ -22,46 +28,60 @@ If a "code sharing solution" is maintained by a framework that can often mean th
2228

2329
## Recommendations and Solutions
2430

25-
- [Nx with xplat](https://nstudio.io/xplat)
31+
### [Nrwl Nx DevTools with @nativescript/nx](https://github.com/NativeScript/nx)
32+
33+
**Pros:**
34+
35+
- It's centered around JavaScript/TypeScript (lesson 1 and 5 above)
36+
- Uses standard build tooling like typescript or webpack to build code (lesson 2 above)
37+
- No custom file extensions to deal with (lesson 3 above)
38+
- Nx splits up "apps" and "libs" clearly identifying deployment/distribution targets "apps" that consume shared code "libs" (lesson 4 above)
39+
40+
**Cons:**
41+
42+
- Learning curve if not used to Nx practices in general
43+
44+
### [Nrwl Nx DevTools with @nstudio/xplat](https://nstudio.io/xplat)
2645

27-
**Pros:**
46+
**Pros:**
2847

29-
- It's centered around JavaScript/TypeScript (lesson 1 and 5 above)
30-
- Uses standard build tooling like typescript or webpack to build code (lesson 2 above)
31-
- No custom file extensions to deal with (lesson 3 above)
32-
- Nx splits up "apps" and "libs" clearly identifying deployment/distribution targets "apps" that consume shared code "libs" (lesson 4 above)
33-
- Opinionated architecture is provided via xplat which helps to avoid common pitfalls from hard lessons learned in real world developments with cross platform mixtures
48+
- It's centered around JavaScript/TypeScript (lesson 1 and 5 above)
49+
- Uses standard build tooling like typescript or webpack to build code (lesson 2 above)
50+
- No custom file extensions to deal with (lesson 3 above)
51+
- Nx splits up "apps" and "libs" clearly identifying deployment/distribution targets "apps" that consume shared code "libs" (lesson 4 above)
52+
- It builds upon @nativescript/nx to further scale it across more paradigms so it's a natural extension when needed if already working in Nx with @nativescript/nx
53+
- Opinionated architecture is provided via xplat which helps to avoid common pitfalls from hard lessons learned in real world developments with cross platform mixtures
3454

35-
**Cons:**
55+
**Cons:**
3656

37-
- Learning curve if not used to Nx practices in general
38-
- Learning curve if you have not developed applications in large codebases before
39-
- Understanding the [basic fundamentals](https://nstudio.io/xplat/fundamentals/architecture) of the provided architecture
57+
- Learning curve if not used to Nx practices in general
58+
- Learning curve if you have not developed applications in large codebases before
59+
- Understanding the [basic fundamentals](https://nstudio.io/xplat/fundamentals/architecture) of the provided architecture
4060

41-
- [Yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/)
61+
### [Yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/)
4262

43-
**Pros:**
63+
**Pros:**
4464

45-
- It's centered around JavaScript/TypeScript (lesson 1 and 5 above)
46-
- Uses standard build tooling like typescript or webpack to build code (lesson 2 above)
47-
- No custom file extensions to deal with (lesson 3 above)
48-
- Can link/share dependencies
65+
- It's centered around JavaScript/TypeScript (lesson 1 and 5 above)
66+
- Uses standard build tooling like typescript or webpack to build code (lesson 2 above)
67+
- No custom file extensions to deal with (lesson 3 above)
68+
- Can link/share dependencies
4969

50-
**Cons:**
70+
**Cons:**
5171

52-
- You are on your own with organizational structure which can lead to common pitfalls with cross platform mixtures
53-
- No out of the box deployment/distribution target setup to identify app targets vs. shared code
72+
- You are on your own with organizational structure which can lead to common pitfalls with cross platform mixtures
73+
- No out of the box deployment/distribution target setup to identify app targets vs. shared code
5474

55-
- [Lerna](https://github.com/lerna/lerna)
75+
### [Lerna](https://github.com/lerna/lerna)
5676

57-
**Pros:**
77+
**Pros:**
5878

59-
- It's centered around JavaScript/TypeScript (lesson 1 and 5 above)
60-
- Uses standard build tooling like typescript or webpack to build code (lesson 2 above)
61-
- No custom file extensions to deal with (lesson 3 above)
79+
- It's centered around JavaScript/TypeScript (lesson 1 and 5 above)
80+
- Uses standard build tooling like typescript or webpack to build code (lesson 2 above)
81+
- No custom file extensions to deal with (lesson 3 above)
6282

63-
**Cons:**
83+
**Cons:**
6484

65-
- You are on your own with organizational structure which can lead to common pitfalls with cross platform mixtures
66-
- No out of the box deployment/distribution target setup to identify app targets vs. shared code
67-
- It's generally geared towards open source library management so no extra helpful tooling for "workspace management" in general
85+
- You are on your own with organizational structure which can lead to common pitfalls with cross platform mixtures
86+
- No out of the box deployment/distribution target setup to identify app targets vs. shared code
87+
- It's generally geared towards open source library management so no extra helpful tooling for "workspace management" in general

index.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,21 @@ actionLink: /introduction
1919
# footer: Copyright © 2021
2020
---
2121

22-
<div style="text-align:center;margin: 0 auto;">
23-
<img src="/assets/images/mobile.gif">
22+
<div style="float:left; max-width:275px;">
23+
<img src="/assets/images/ns-docs.gif">
2424
</div>
2525

26-
<a href="/introduction">Read the docs</a>
26+
<div style="float:left">
27+
<h3 id="table-of-contents"><a class="header-anchor" href="#table-of-contents" aria-hidden="true">#</a> Table of Contents</h3>
28+
29+
<ul style="list-style-type:none">
30+
<li><a href="/introduction">Introduction</a></li>
31+
<li><a href="/ui-and-styling">UI &amp; Styling</a></li>
32+
<li><a href="/networking">Networking</a></li>
33+
<li><a href="/performance">Performance</a></li>
34+
<li><a href="/code-sharing/index">Scalability</a></li>
35+
<li><a href="/advanced-concepts">Advanced Concepts</a></li>
36+
<li><a href="/releasing">Distribution</a></li>
37+
<li><a href="/troubleshooting">Troubleshooting</a></li>
38+
</ul>
39+
</div>

public/assets/images/ns-docs.gif

481 KB
Loading

ui-and-styling.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,122 @@ The following example creates a diagonal stack of items with responsive sizes. I
489489

490490
None.
491491

492+
### RootLayout
493+
494+
`<RootLayout>` is a layout container designed to be used as the primary root layout container for your app with a built in api to easily control dynamic view layers. It extends a GridLayout so has all the features of a grid but enhanced with additional apis.
495+
496+
It's api can be observed here:
497+
498+
```ts
499+
export class RootLayout extends GridLayout {
500+
open(view: View, options?: RootLayoutOptions): Promise<void>
501+
close(view: View, exitTo?: TransitionAnimation): Promise<void>
502+
bringToFront(view: View, animated?: boolean): Promise<void>
503+
closeAll(): Promise<void>
504+
getShadeCover(): View
505+
}
506+
507+
export function getRootLayout(): RootLayout
508+
509+
export interface RootLayoutOptions {
510+
shadeCover?: ShadeCoverOptions
511+
animation?: {
512+
enterFrom?: TransitionAnimation
513+
exitTo?: TransitionAnimation
514+
}
515+
}
516+
517+
export interface ShadeCoverOptions {
518+
opacity?: number
519+
color?: string
520+
tapToClose?: boolean
521+
animation?: {
522+
enterFrom?: TransitionAnimation // only applied if first one to be opened
523+
exitTo?: TransitionAnimation // only applied if last one to be closed
524+
}
525+
ignoreShadeRestore?: boolean
526+
}
527+
528+
export interface TransitionAnimation {
529+
translateX?: number
530+
translateY?: number
531+
scaleX?: number
532+
scaleY?: number
533+
rotate?: number // in degrees
534+
opacity?: number
535+
duration?: number // in milliseconds
536+
curve?: any // CoreTypes.AnimationCurve (string, cubicBezier, etc.)
537+
}
538+
```
539+
540+
You can use `getRootLayout()` to get a reference to the root layout in your app from anywhere.
541+
542+
#### Example: RootLayout setup
543+
544+
Sample layout:
545+
546+
```html
547+
<RootLayout height="100%" width="100%">
548+
<GridLayout height="100%">
549+
<label
550+
verticalAlignment="center"
551+
textAlignment="center"
552+
text="MAIN CONTENT AREA"
553+
></label>
554+
</GridLayout>
555+
</RootLayout>
556+
```
557+
558+
Sample api usage:
559+
560+
```ts
561+
// Open a dynamic popup
562+
const view = this.getPopup('#EA5936', 110, -30)
563+
getRootLayout()
564+
.open(view, {
565+
shadeCover: {
566+
color: '#000',
567+
opacity: 0.7,
568+
tapToClose: true
569+
},
570+
animation: {
571+
enterFrom: {
572+
opacity: 0,
573+
translateY: 500,
574+
duration: 500
575+
},
576+
exitTo: {
577+
opacity: 0,
578+
duration: 300
579+
}
580+
}
581+
})
582+
.catch(ex => console.error(ex))
583+
584+
// Close the dynamic popup
585+
getRootLayout()
586+
.close(view, {
587+
opacity: 0,
588+
translate: { x: 0, y: -500 }
589+
})
590+
.catch(ex => console.error(ex))
591+
592+
function getPopup(color: string, size: number, offset: number): View {
593+
const layout = new StackLayout()
594+
layout.height = size
595+
layout.width = size
596+
layout.marginTop = offset
597+
layout.marginLeft = offset
598+
layout.backgroundColor = color
599+
layout.borderRadius = 10
600+
return layout
601+
}
602+
```
603+
604+
You can play with [the toolbox app here](https://github.com/NativeScript/NativeScript/tree/master/apps/toolbox/src/pages/root-layout.ts)
605+
606+
You can also find a more [thorough example in this sample repo](https://github.com/williamjuan027/nativescript-rootlayout-demo)
607+
492608
### WrapLayout
493609

494610
`<WrapLayout>` is a layout container that lets you position items in rows or columns, based on the `orientation` property. When the space is filled, the container automatically wraps items onto a new row or column.

0 commit comments

Comments
 (0)