Skip to content

Commit a97790a

Browse files
authored
feat: core 8.8 features (#148)
1 parent c5abb6a commit a97790a

File tree

4 files changed

+265
-3
lines changed

4 files changed

+265
-3
lines changed

content/configuration/nativescript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Specifies the [webpack config](./webpack) location. The default is `webpack.conf
107107
projectName: string = 'projectName'
108108
```
109109

110-
Specifies the name of the project. The default is the basename of the project directory.
110+
Specifies the name of the project. The default is the basename of the project directory.
111111

112112
### profiling
113113

content/guide/styling.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,141 @@ To allow for flexible styling and theming, NativeScript provides the following C
573573
In native modals in Angular, the classes are applied to the first layout view in your modal component's HTML. If you are targeting a class that is applied to the root layout in your modal, you would target it with `.ns-dark.your-class`.
574574
:::
575575

576+
### Media Queries (8.8+)
577+
578+
Media queries will allow you to apply CSS styles conditionally depending on a device's features or characteristics such as screen orientation, theme, or viewport width and height.
579+
580+
NativeScript supports [Media Queries Level 3](https://www.w3.org/TR/mediaqueries-3) specification including the following features:
581+
582+
- orientation
583+
- prefers-color-scheme (Even though this one is part of Media Queries Level 5, it was added along with current implementation to make theme styling possible)
584+
- width
585+
- height
586+
- device-width (same as width)
587+
- device-height (same as height)
588+
589+
Viewport features like width and height support ranged values by using the `min-` or `max-` prefix.
590+
591+
Here are few examples of how to declare media queries in NativeScript:
592+
593+
```css
594+
@media only screen and (orientation: landscape) {
595+
Label {
596+
color: yellow;
597+
font-size: 24;
598+
}
599+
}
600+
601+
@media only screen and (prefers-color-scheme: dark) {
602+
Label {
603+
background-color: #fff;
604+
color: #000;
605+
}
606+
}
607+
608+
@media only screen and (max-width: 400) {
609+
Label {
610+
font-size: 10;
611+
}
612+
}
613+
614+
@media only screen and (min-height: 800) {
615+
Page {
616+
background-color: red;
617+
}
618+
}
619+
```
620+
621+
Just like style properties, length feature values (e.g. width) can also accept DIP or device pixel (px) units.
622+
623+
#### The not operator
624+
625+
The `not` operator is used to negate a media query, returning true if the query would otherwise return false.
626+
627+
```css
628+
@media screen and not (orientation: portrait) {
629+
Label {
630+
color: yellow;
631+
font-size: 24;
632+
}
633+
}
634+
```
635+
636+
#### Nested Media Queries
637+
638+
```css
639+
@media only screen and (orientation: landscape) {
640+
Label {
641+
color: yellow;
642+
font-size: 24;
643+
}
644+
645+
@media only screen and (max-width: 400) {
646+
Label {
647+
font-size: 10;
648+
}
649+
}
650+
}
651+
```
652+
653+
#### Nesting Keyframes inside Media Queries
654+
655+
Apart from CSS selectors, keyframes can also be conditional using Media Queries.
656+
657+
```css
658+
@keyframes slidein {
659+
from {
660+
background-color: yellow;
661+
}
662+
663+
to {
664+
background-color: pink;
665+
}
666+
}
667+
668+
/** This one will apply if condition is truthy **/
669+
@media only screen and (orientation: landscape) {
670+
@keyframes slidein {
671+
from {
672+
background-color: red;
673+
}
674+
675+
to {
676+
background-color: green;
677+
}
678+
}
679+
}
680+
```
681+
682+
#### matchMedia and conditional Navigation with Media Queries
683+
684+
Sometimes, there's the need for an application to navigate to a completely different `Page` based on device screen size or orientation.
685+
Right now, that's possible using NativeScript's [Screen Size Qualifiers](https://old.docs.nativescript.org/ui/supporting-multiple-screens) API however it's limited to plain JS/TS apps and not available to the rest of JavaScript flavors.
686+
687+
For various flavors, you can instead use [matchMedia()](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia) providing many possibilities.
688+
689+
The example below demonstrates how to navigate to an alternate `Page` if screen width is larger than 600 DIP:
690+
691+
```ts
692+
const mql = matchMedia('only screen and (max-width: 600)')
693+
694+
Frame.topmost().navigate({
695+
// Navigate to another page if screen is too big
696+
moduleName: mql.matches ? './pages/phone' : './pages/tablet',
697+
})
698+
```
699+
700+
#### Using listeners to track Media Query changes
701+
702+
The [matchMedia()](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia) method returns a NativeScript [Observable](/core/observable#observable-api) instance, giving you the chance to track Media Query changes using event listeners.
703+
704+
```ts
705+
const mql = matchMedia('only screen and (orientation: portrait)')
706+
mql.addEventListener('change', (event) => {
707+
console.log('Is screen orientation still portrait? ' + event.matches)
708+
})
709+
```
710+
576711
## Supported Measurement Units
577712

578713
NativeScript supports `DIPs` (Device Independent Pixels), `pixels` (via postfix px) and `percentages` (partial support for width, height and margin) as measurement units.

content/guide/visionos.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ You can follow along in these "Vision Pro 🥽 Hello World" tutorials:
315315
- [Develop Vision Pro 🥽 apps with Svelte](https://blog.nativescript.org/develop-visionos-apps-with-svelte)
316316
- [Develop Vision Pro 🥽 apps with Vue](https://blog.nativescript.org/develop-visionos-apps-with-vue)
317317
318-
### Vision Pro for Angular Developers
318+
### Vision Pro for Angular Developers
319319
320320
This tutorial was hosted by [This Dot Media](https://www.youtube.com/@ThisDotMedia)
321321
@@ -329,4 +329,4 @@ https://blog.nativescript.org/particles-and-multiple-scenes-vision-pro-developme
329329
330330
### How to add visionOS to an existing app?
331331
332-
https://blog.nativescript.org/add-visionos-to-existing-nativescript-app/
332+
https://blog.nativescript.org/add-visionos-to-existing-nativescript-app/

content/ui/image.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,81 @@ Font symbols can be rendered as an image by prefixing the source with `font://`
8181
}
8282
```
8383

84+
### Using SF Symbols on iOS (8.8+)
85+
86+
Images can also be used to display [SF Symbols](https://developer.apple.com/sf-symbols/) on iOS by using the `sys://` prefix along with the symbol name. These also support `iosSymbolEffect` for animated effects as well as `iosSymbolScale` with a possible value of `small|medium|large`;
87+
88+
```html
89+
<GridLayout rows="auto,auto" columns="*,*">
90+
<image
91+
src="sys://photo.on.rectangle.angled"
92+
tintColor="green"
93+
[iosSymbolEffect]="symbolBounceEffect"
94+
/>
95+
96+
<image
97+
col="1"
98+
src="sys://photo.on.rectangle.angled"
99+
tintColor="green"
100+
[iosSymbolEffect]="symbolBounceEffect"
101+
iosSymbolScale="small"
102+
/>
103+
104+
<image
105+
row="1"
106+
src="sys://photo.on.rectangle.angled"
107+
tintColor="green"
108+
[iosSymbolEffect]="symbolBounceEffect"
109+
iosSymbolScale="medium"
110+
/>
111+
112+
<image
113+
row="1"
114+
col="1"
115+
src="sys://photo.on.rectangle.angled"
116+
tintColor="green"
117+
[iosSymbolEffect]="symbolBounceEffect"
118+
iosSymbolScale="large"
119+
/>
120+
</GridLayout>
121+
```
122+
123+
```ts
124+
import { ImageSymbolEffects } from '@nativescript/core'
125+
126+
const symbolBounceEffect = ImageSymbolEffects.Bounce
127+
```
128+
129+
<iframe style="width: 100%; min-height: 200px; aspect-ratio: 16 / 9;" src="https://www.youtube.com/embed/y_ULvYe5mTA" title="SF Symbol usage with NativeScript" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
130+
131+
This demonstrates using various built-in presets for effects and also using the `iosSymbolScale` property which is useful when you apply affects so the animation doesn't exceed the bounds of it's Image container (_as can be seen in the top left usage in the video_).
132+
133+
#### Custom Symbol Effects
134+
135+
You can also create custom effects using the full expansive iOS symbol API, for example:
136+
137+
```ts
138+
import { ImageSymbolEffect } from '@nativescript/core'
139+
140+
const effect = new ImageSymbolEffect(NSSymbolBounceEffect.effect())
141+
effect.options =
142+
NSSymbolEffectOptions.optionsWithSpeed(2).optionsWithRepeatCount(6)
143+
effect.completion = (context) => {
144+
console.log('effect completed!', context)
145+
}
146+
const customSymbolEffect = effect
147+
```
148+
149+
```html
150+
<image
151+
src="sys://heart.fill"
152+
tintColor="red"
153+
[iosSymbolEffect]="customSymbolEffect"
154+
/>
155+
```
156+
157+
<iframe style="width: 100%; min-height: 200px; aspect-ratio: 16 / 9;" src="https://www.youtube.com/embed/IuyGBoqJNKo" title="SF Symbol custom effects with NativeScript" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
158+
84159
## Props
85160

86161
### src
@@ -125,6 +200,58 @@ Gets or sets the way the image is resized to fill its allocated space.
125200

126201
See [`ImageStretchType`](/api/namespace/CoreTypes#imagestretchtype)
127202

203+
### iosSymbolEffect (8.8+)
204+
205+
```ts
206+
iosSymbolEffect: ImageSymbolEffect | ImageSymbolEffects
207+
```
208+
209+
Gets or sets the effect of the SF Symbol. You can create your own custom `ImageSymbolEffect` or use presets defined from `ImageSymbolEffects`, for example:
210+
211+
```ts
212+
export enum ImageSymbolEffects {
213+
Appear = 'appear',
214+
AppearUp = 'appearUp',
215+
AppearDown = 'appearDown',
216+
Bounce = 'bounce',
217+
BounceUp = 'bounceUp',
218+
BounceDown = 'bounceDown',
219+
Disappear = 'disappear',
220+
DisappearDown = 'disappearDown',
221+
DisappearUp = 'disappearUp',
222+
Pulse = 'pulse',
223+
Scale = 'scale',
224+
ScaleDown = 'scaleDown',
225+
ScaleUp = 'scaleUp',
226+
VariableColor = 'variableColor',
227+
Breathe = 'breathe',
228+
BreathePlain = 'breathePlain',
229+
BreathePulse = 'breathePulse',
230+
Rotate = 'rotate',
231+
RotateClockwise = 'rotateClockwise',
232+
RotateCounterClockwise = 'rotateCounterClockwise',
233+
Wiggle = 'wiggle',
234+
WiggleBackward = 'wiggleBackward',
235+
WiggleClockwise = 'wiggleClockwise',
236+
WiggleCounterClockwise = 'wiggleCounterClockwise',
237+
WiggleDown = 'wiggleDown',
238+
WiggleForward = 'wiggleForward',
239+
WiggleUp = 'wiggleUp',
240+
WiggleLeft = 'wiggleLeft',
241+
WiggleRight = 'wiggleRight',
242+
}
243+
```
244+
245+
Keep in mind that some are only iOS 17 or 18 and above.
246+
247+
### iosSymbolScale (8.8+)
248+
249+
```ts
250+
iosSymbolScale: number
251+
```
252+
253+
Gets or sets the scale of the SF Symbol.
254+
128255
### loadMode
129256

130257
```ts

0 commit comments

Comments
 (0)