Skip to content

Commit

Permalink
style: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rigor789 committed Oct 4, 2023
1 parent 86ab86b commit a9ed9f8
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 326 deletions.
35 changes: 23 additions & 12 deletions content/core/color.md
Expand Up @@ -4,25 +4,27 @@ description: Create a color object with any color representation and use it in y
---

The `Color` class enables the creation of a color object:
- using color components (alpha, red, green, blue) ranging from 0 to 255,
- using various color representations like ARGB, color names, hex values, and more.


- using color components (alpha, red, green, blue) ranging from 0 to 255,
- using various color representations like ARGB, color names, hex values, and more.

The `ios` and `android` properties of the `Color` class instance return the native platform instance of [UIColor](https://developer.apple.com/documentation/uikit/uicolor) on iOS and [Color](https://developer.android.com/reference/android/graphics/Color) on Android.

## How to use the Color class

<!-- Preview: https://stackblitz.com/edit/nativescript-stackblitz-templates-x2y7k6?file=app/main-view-model.ts -->

### Create a color object from a hex value

```ts
const color = new Color('#FF00CC');
const colorShortHex = new Color('#F0C');
const color = new Color('#FF00CC')
const colorShortHex = new Color('#F0C')
```

### Create a color object from an alpha value

```ts
const colorARGB = new Color(100, 255, 100, 100);
const colorARGB = new Color(100, 255, 100, 100)
```

## Color API
Expand All @@ -36,25 +38,31 @@ Creates a color object. The Color class offers the following constructor overloa
```ts
const color = new Color(knownColor)
```

Creates a Color instance from a known color name.

- `knownColor` : A color name string such as `'red'`, `'purple'`, `'orange'`.

```ts
const color = new Color(hex)
```

Creates a Color instance from a color hexidecimal code.

- `hex`: A string of a hexidecimal color value such as `'#fff'` or `'#FF00CC'`.

```ts
const color = new Color(argb)
```

Creates a Color instance from a number representing a color with an alpha.
- `argb`: A number such as `4293377432` as, representing color.

- `argb`: A number such as `4293377432` as, representing color.

```ts
const color = new Color(alpha: number, red: number, green:number, blue: number, type?: 'rgb' | 'hsl' | 'hsv')
```

---

### a
Expand Down Expand Up @@ -100,7 +108,7 @@ Gets the Blue component of the color. This is a `read-only` property.
### argb

```ts
colorARGB : number = color.argb
colorARGB: number = color.argb
```

Gets the Argb Number representation of this color where each 8 bits represent a single color component. This is a `read-only` property.
Expand All @@ -120,7 +128,7 @@ Gets the Hexadecimal string representation of the color.
### name

```ts
colorName: string =color.name
colorName: string = color.name
```

Gets the known name of this instance. Defined only if it has been constructed from a known color name - e.g. "red".
Expand Down Expand Up @@ -157,7 +165,7 @@ A static Color class method that compares two `Color` instances and returns `tru

---

### Color.isValid()
### Color.isValid()

```ts
isValidColorValue: boolean = Color.isValid(value)
Expand Down Expand Up @@ -213,7 +221,7 @@ A static method that returns a new Color from HSV.
color.equals(value)
```

A Color instance method that checks whether the color instance on which the method is called equals the Color instance passed to the method.
A Color instance method that checks whether the color instance on which the method is called equals the Color instance passed to the method.

---

Expand Down Expand Up @@ -262,9 +270,10 @@ Returns the color's [luminance](http://www.w3.org/TR/2008/REC-WCAG20-20081211/#r
```ts
colorWithAlpha: Color = color.setAlpha(a)
```

Adds the specified alpha to the color instance on which the method is called and returns the result as a new Color instance.

`a` is a value between `0` and `255`.
`a` is a value between `0` and `255`.

---

Expand Down Expand Up @@ -377,6 +386,7 @@ colorSpinned: Color = color.spin(amount)
Spins the hue by the given amount, from -`360` to `360`. Calling with `0`, `360`, or -`360` does nothing since it sets the hue back to what it was before.

---

### complement()

```ts
Expand All @@ -388,5 +398,6 @@ Returns a Color instance that is the complement of the current color.
---

## Native Component

- `Android`: [android.graphics.Color](https://developer.android.com/reference/android/graphics/Color)
- `iOS`: [UIColor](https://developer.apple.com/documentation/uikit/uicolor?language=objc)
2 changes: 1 addition & 1 deletion content/core/index.md
Expand Up @@ -22,4 +22,4 @@ next: false
</li>
</ul>

See also [API Reference](/api/).
See also [API Reference](/api/).
6 changes: 2 additions & 4 deletions content/guide/adding-native-code.md
Expand Up @@ -2,14 +2,12 @@
title: Adding custom native code to a project
---


NativeScript allows you to access any native APIs anytime in your app. If the native API you need is not exposed through [@nativescript/core](https://docs.nativescript.org/understanding-packages#nativescript-core) or [third party plugins](https://market.nativescript.org/) or [@nativescript/* plugins](https://docs.nativescript.org/plugins/index.html)), you can add it to your project and access it right away in TypeScript.

NativeScript allows you to access any native APIs anytime in your app. If the native API you need is not exposed through [@nativescript/core](https://docs.nativescript.org/understanding-packages#nativescript-core) or [third party plugins](https://market.nativescript.org/) or [@nativescript/\* plugins](https://docs.nativescript.org/plugins/index.html)), you can add it to your project and access it right away in TypeScript.

1. Add native code to [App_Resources](/project-structure/app-resources). For example, see [Adding Java/Kotlin code to an application](/project-structure/app-resources#adding-java-kotlin-code-to-an-application) and [Adding ObjectiveC/Swift Code to an application](/project-structure/app-resources#adding-objectivec-swift-code-to-an-application)

2. Generate types for the added APIs
For iOS types run:
For iOS types run:

```cli
ns typings ios
Expand Down
40 changes: 19 additions & 21 deletions content/guide/error-handling.md
Expand Up @@ -12,21 +12,19 @@ NativeScript allows error handling to be set dependent on whether the app is in

```ts
const errorHandler: TraceErrorHandler = {

handlerError(err) {
throw err
}
},
}
```

**Prevent app crash**: Write the error message to the console and continue the execution of the app.
**Prevent app crash**: Write the error message to the console and continue the execution of the app.

```ts
const errorHandler: TraceErrorHandler = {

handlerError(err) {
Trace.write(err, 'unhandled-error', type.error)
}
},
}
```

Expand All @@ -36,10 +34,9 @@ const errorHandler: TraceErrorHandler = {

```ts
const errorHandler: TraceErrorHandler = {

handlerError(err) {
reportToAnalytics(err)
}
},
}
```

Expand All @@ -55,12 +52,12 @@ Nativescript also allows the prevention of an app crash by disabling rethrowing
ios: {
...
"discardUncaughtJsExceptions": true,

},
android: {
...
"discardUncaughtJsExceptions": true,

},
```

Expand All @@ -71,18 +68,19 @@ To handle discarded exceptions, two options are available:
```ts
import { Application, DiscardedErrorEventData } from '@nativescript/core'

Application.on(Application.discardedErrorEvent, function (args: DiscardedErrorEventData) {
const error = args.error

console.log('Received discarded exception: ')
console.log(error.message)
console.log(error.name)
console.log(error.stack)
console.log(error.nativeError)
// for example, report the exception to an analytics solution here
})
Application.on(
Application.discardedErrorEvent,
function (args: DiscardedErrorEventData) {
const error = args.error

console.log('Received discarded exception: ')
console.log(error.message)
console.log(error.name)
console.log(error.stack)
console.log(error.nativeError)
// for example, report the exception to an analytics solution here
}
)
```

- Assigning a one-argument function to `global.__onDiscardedError` which will receive the exception as a `NativeScriptError` instance.


0 comments on commit a9ed9f8

Please sign in to comment.