Skip to content

Commit 2f3d248

Browse files
committed
docs: cleanup and organize core reference
1 parent d79cae3 commit 2f3d248

21 files changed

+812
-472
lines changed

.vitepress/config.mts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineConfig } from 'vitepress'
22
import apiSidebar from '../content/api/sidebar.json'
3+
import coreSidebar from '../content/core/sidebar'
34
import mainSidebar from '../content/sidebar'
45
import uiSidebar from '../content/ui/sidebar'
56
import nav from './nav'
@@ -37,6 +38,7 @@ export default defineConfig({
3738
nav,
3839
sidebar: {
3940
'/api': apiSidebar,
41+
'/core': coreSidebar,
4042
'/ui': uiSidebar,
4143
'/': mainSidebar,
4244
},

.vitepress/nav.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default [
1212
{
1313
text: 'Docs',
1414
link: '/',
15-
activeMatch: '^/(?!plugins|best-practices|api|dev-reference|tutorials|ui)',
15+
activeMatch: '^/(?!plugins|best-practices|api|dev-reference|tutorials|ui|core)',
1616
icon: 'BookOpenIcon',
1717
},
1818

@@ -50,6 +50,12 @@ export default [
5050
activeMatch: '^/ui',
5151
icon: 'CubeTransparentIcon',
5252
},
53+
{
54+
text: 'Core Reference',
55+
link: '/core/',
56+
activeMatch: '^/core',
57+
icon: 'CodeBracketIcon',
58+
},
5359
{
5460
text: 'API Reference',
5561
link: '/api/',

content/guide/core/application-settings.md renamed to content/core/application-settings.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ description: Persist data locally on the device storage
1414
To store a string value, use the [setString](#setstring) method:
1515

1616
```ts
17-
ApplicationSettings.setString("username", "Wolfgang");
17+
ApplicationSettings.setString('username', 'Wolfgang')
1818
```
19+
1920
:::tip :green_circle: Tip
2021
You can use this method with the `JSON.stringify()` (as shown in the `saveObjectAsString` method in the StackBlitz demo app at the link above) to store an object or an array as a string. Then, use `JSON.parse()` to convert the result of [getString()](#getstring) back to the object or array.
2122
:::
@@ -25,15 +26,15 @@ You can use this method with the `JSON.stringify()` (as shown in the `saveObject
2526
To store a boolean value, call the [setBoolean](#setboolean) method passing the key as the first argument and the value as second argument.
2627

2728
```ts
28-
ApplicationSettings.setBoolean("isTurnedOn", true);
29+
ApplicationSettings.setBoolean('isTurnedOn', true)
2930
```
3031

3132
### Store a numeric value
3233

3334
To store a number, use the [setNumber()](#setnumber) method:
3435

3536
```ts
36-
ApplicationSettings.setNumber("locationX", 54.321);
37+
ApplicationSettings.setNumber('locationX', 54.321)
3738
```
3839

3940
## ApplicationSettings API
@@ -94,7 +95,7 @@ Sets a `boolean` for a key.
9495
ApplicationSettings.getBoolean(key: string, deafaultValue?: boolean)
9596
```
9697

97-
Gets a value (if existing) for a key as a `boolean`. A default value can be provided in case the value does not exist.value.
98+
Gets a value (if existing) for a key as a `boolean`. A default value can be provided in case the value does not exist.value.
9899

99100
---
100101

@@ -123,14 +124,16 @@ Removes all values from the device storage.
123124
```ts
124125
ApplicationSettings.getAllKeys(): Array<string>
125126
```
127+
126128
Returns an array of all stored keys or an empty array if no keys exist in the device storage.
127129

128130
---
129131

130-
131132
## API Reference(s)
133+
132134
- [ApplicationSettings](https://docs.nativescript.org/api-reference/modules#applicationsettings) module
133135

134136
## Native Component
137+
135138
- `Android`: [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences)
136139
- `iOS`: [NSUserDefaults](https://developer.apple.com/documentation/foundation/nsuserdefaults)

content/guide/core/application.md renamed to content/core/application.md

Lines changed: 72 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,75 @@ The Application class provides the wrapper around [android.app.Application](http
1010
### Register a broadcast receiver
1111

1212
To register a broadcast receiver, you follow these 3 steps:
13+
1314
1. Import the `Application` class from `@nativescript/core`.
14-
```ts
15-
import { Application, isAndroid } from '@nativescript/core';
16-
```
15+
16+
```ts
17+
import { Application, isAndroid } from '@nativescript/core'
18+
```
19+
1720
2. Get the wrapper object for [android.app.Application](https://developer.android.com/reference/android/app/Application) instance.
18-
Use the `android` property to get the wrapper around [android.app.Application](https://developer.android.com/reference/android/app/Application).
21+
Use the `android` property to get the wrapper around [android.app.Application](https://developer.android.com/reference/android/app/Application).
1922

20-
```ts
21-
const androidApp: AndroidApplication = Application.android
22-
```
23+
```ts
24+
const androidApp: AndroidApplication = Application.android
25+
```
2326

2427
3. Call the [registerBroadcastReceiver](#registerbroadcastreceiver) method.
25-
Call the `registerBroadcastReceiver` method on `androidApp`.
26-
```ts
27-
androidApp.registerBroadcastReceiver()
28-
```
28+
Call the `registerBroadcastReceiver` method on `androidApp`.
29+
30+
```ts
31+
androidApp.registerBroadcastReceiver()
32+
```
2933

30-
For a complete example that shows how to register a broadcast receiver with a custom intent filter, visit the following link:
34+
For a complete example that shows how to register a broadcast receiver with a custom intent filter, visit the following link:
3135

3236
<!-- Preview: https://stackblitz.com/edit/nativescript-stackblitz-templates-khnhes?file=app/app.ts -->
37+
3338
For system intent filters, see [Standard Broadcast Actions](https://developer.android.com/reference/android/content/Intent#standard-broadcast-actions).
3439

3540
### Unregister a broadcast receiver
3641

3742
To unregister a broadcast receiver, call the [unregisterBroadcastReceiver](#unregisterbroadcastreceiver) on the wrapper around an [android.app.Application](https://developer.android.com/reference/android/app/Application) passing it the intent filter for which to unregister the broacast receiver. The example below unregisters a broadcast receiver for the `android.content.Intent.ACTION_BATTERY_CHANGED` intent filter.
3843

3944
```ts
40-
import { Application, isAndroid } from '@nativescript/core';
41-
if(isAndroid){
42-
const androidApp: AndroidApplication = Application.android
45+
import { Application, isAndroid } from '@nativescript/core'
46+
if (isAndroid) {
47+
const androidApp: AndroidApplication = Application.android
4348

44-
androidApp.unregisterBroadcastReceiver(android.content.Intent.ACTION_BATTERY_CHANGED);
49+
androidApp.unregisterBroadcastReceiver(
50+
android.content.Intent.ACTION_BATTERY_CHANGED
51+
)
4552
}
46-
4753
```
4854

4955
### Add a notification observer
5056

51-
To add an iOS notification observer, follow the steps below:
57+
To add an iOS notification observer, follow the steps below:
5258

5359
1. Import the `Application` class from `@nativescript/core`.
5460

55-
```ts
56-
import { Application, isIOS } from '@nativescript/core';
57-
```
61+
```ts
62+
import { Application, isIOS } from '@nativescript/core'
63+
```
5864

5965
2. Get the wrapper object for [UIApplication](https://developer.apple.com/documentation/uikit/uiapplication?language=objc) instance.
60-
```ts
61-
const iOSApp: iOSApplication = Application.ios
62-
```
66+
67+
```ts
68+
const iOSApp: iOSApplication = Application.ios
69+
```
6370

6471
3. Call the `addNotificationObserver` method.
65-
Call the `addNotificationObserver` passing it the name of the notification([NSNotificationName](https://developer.apple.com/documentation/foundation/nsnotificationname)) you would like to observe as the first parameter and as a second parameter, a callback function to be called when that notification occurs.
72+
Call the `addNotificationObserver` passing it the name of the notification([NSNotificationName](https://developer.apple.com/documentation/foundation/nsnotificationname)) you would like to observe as the first parameter and as a second parameter, a callback function to be called when that notification occurs.
6673

67-
```ts
68-
const observer: any = iOSApp.addNotificationObserver(
69-
UIDeviceOrientationDidChangeNotification,
70-
(notification: NSNotification) => {
71-
//Handle the notification
72-
}
73-
)
74-
```
74+
```ts
75+
const observer: any = iOSApp.addNotificationObserver(
76+
UIDeviceOrientationDidChangeNotification,
77+
(notification: NSNotification) => {
78+
//Handle the notification
79+
}
80+
)
81+
```
7582

7683
Find the complete example [here](https://stackblitz.com/edit/nativescript-stackblitz-templates-khnhes?file=app%2Fapp.ts%3AL14)
7784

@@ -80,11 +87,14 @@ Find the complete example [here](https://stackblitz.com/edit/nativescript-stackb
8087
To remove a notification observer, use the `removeNotificationObserver` method on a `Application.ios` reference the observer id, returned by the `addNotificationObserver` as the first argument and the name of the notification to stop observing.
8188

8289
```ts
83-
iOSApp.removeNotificationObserver(observer, UIDeviceBatteryStateDidChangeNotification)
90+
iOSApp.removeNotificationObserver(
91+
observer,
92+
UIDeviceBatteryStateDidChangeNotification
93+
)
8494
```
8595

86-
8796
## Cross platform application events
97+
8898
This class allows you to listen to the following lifecycle events on both platforms.
8999

90100
```ts
@@ -110,49 +120,68 @@ Application.on('orientationChanged', (args: ApplicationEventData) => {
110120
- `fontScaleChanged`
111121

112122
:::
123+
113124
## getResources()
125+
114126
```ts
115127
resources: any = Application.getResources()
116128
```
129+
117130
Gets application-level static resources.
118131

119132
---
133+
120134
## setResources()
135+
121136
```ts
122137
Application.setResources(resources)
123138
```
139+
124140
Sets application-level static resources.
125141

126142
---
143+
127144
## setCssFileName()
145+
128146
```ts
129147
Application.setCssFileName(filePath)
130148
```
149+
131150
Sets css file name for the application.
132151

133152
---
153+
134154
## getCssFileName()
155+
135156
```ts
136157
cssFileName: string = Application.getCssFileName()
137158
```
159+
138160
Gets css file name for the application.
139161

140162
---
163+
141164
## loadAppCss()
165+
142166
```ts
143167
loadedCss: any = Applicatioin.loadAppCss()
144168
```
169+
145170
Loads immediately the app.css. By default the app.css file is loaded shortly after "loaded". For the Android snapshot the CSS can be parsed during the snapshot generation, as the CSS does not depend on runtime APIs, and loadAppCss will be called explicitly.
146171

147172
---
173+
148174
## addCss()
175+
149176
```ts
150177
Application.addCss(cssText, attributeScoped)
151178
```
179+
152180
Adds new values to the application styles.
181+
153182
- `cssText` - A valid CSS styles to be add to the current application styles.
154183
- _Optional_: `attributeScoped` - sets whether the styles are attribute scoped. Adding attribute scoped styles does not perform a full application styling refresh.
155-
184+
156185
---
157186

158187
## Android Reference
@@ -171,15 +200,14 @@ The property gives you the `AndroidApplication` object, a Nativescript wrapper,
171200

172201
```ts
173202
nativeApp: android.app.Application = androidApp.nativeApp
174-
// or
203+
// or
175204
nativeApp: UIApplication = iOSApp.nativeApp
176205
```
177206

178-
This is a native application reference.
207+
This is a native application reference.
179208

180209
For Android, it is the [android.app.Application](http://developer.android.com/reference/android/app/Application.html) instance keeping track of the global application state. From this object you can get methods such as getFilesDir(), onLowMemory(),etc.
181210

182-
183211
For iOS, it returns the reference to a [UIApplication](https://developer.apple.com/documentation/uikit/uiapplication?language=objc) instance for the application.
184212

185213
---
@@ -258,10 +286,10 @@ Unregisters a previously registered BroadcastReceiver for the specified intent f
258286

259287
### Android Activity lifecycles events
260288

261-
To handle the application lifecycle events for Android, use `on` method of the
289+
To handle the application lifecycle events for Android, use `on` method of the
262290

263291
```ts
264-
androidApp.on('activityResumed', args => {
292+
androidApp.on('activityResumed', (args) => {
265293
//handle the event here
266294
})
267295
```
@@ -282,7 +310,9 @@ androidApp.on('activityResumed', args => {
282310
:::
283311

284312
---
313+
285314
## iOS Reference
315+
286316
### ios
287317

288318
```ts
@@ -385,8 +415,6 @@ Returns whether the system appearance is `dark`, `light` or `null`(for iOS <= 11
385415

386416
---
387417

388-
389-
390418
:::details References
391419

392420
## API References
@@ -401,4 +429,4 @@ Returns whether the system appearance is `dark`, `light` or `null`(for iOS <= 11
401429
| :----------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------- |
402430
| [android.app.Application](https://developer.android.com/reference/android/app/Application) | [UIApplication](https://developer.apple.com/documentation/uikit/uiapplication?language=objc) |
403431

404-
:::
432+
:::
File renamed without changes.

0 commit comments

Comments
 (0)