Skip to content

Commit ed3a1bc

Browse files
authored
Merge branch 'feat/8.9-core-additions' into feat/flavor-snippets
2 parents e7775b6 + f10c794 commit ed3a1bc

File tree

7 files changed

+272
-2
lines changed

7 files changed

+272
-2
lines changed

content/configuration/nativescript.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ ios.SPMPackages: Array<{
371371
libs: Array<string>;
372372
repositoryURL: string;
373373
version: string;
374+
/**
375+
* (8.9+) If you have more targets (like widgets for example),
376+
* you can list their names here to include the Swift Package with them.
377+
*/
378+
targets?: string[];
374379
}>
375380
```
376381

@@ -392,6 +397,63 @@ ios: {
392397
}
393398
```
394399

400+
### ios.NativeSource
401+
402+
::: tip
403+
404+
NativeSource config option is available in `[email protected]` or newer.
405+
406+
:::
407+
408+
```ts
409+
ios.NativeSource: Array<{
410+
name: string;
411+
path: string;
412+
}>
413+
```
414+
415+
Include any native source code from anywhere in the project (or workspace). Glob patterns are fully supported.
416+
417+
#### Example
418+
419+
- Include any `.swift` files anywhere within the project `src` directory:
420+
421+
```ts
422+
// ...
423+
ios: {
424+
NativeSource: [
425+
{
426+
name: 'ProjectPlatformSrc',
427+
path: './src/**/*.swift'
428+
}
429+
],
430+
}
431+
```
432+
433+
This will create a file reference folder named `ProjectPlatformSrc` within the generated Xcode project containing any .swift files found anywhere within the project `src` directory.
434+
435+
- Include any `.swift` files anywhere within the project `src` directory, including any (Swift, Obj-C impl/headers, as well as any module.modulemap files) within a workspace `packages` or `libs` dir:
436+
437+
```ts
438+
// ...
439+
ios: {
440+
NativeSource: [
441+
{
442+
name: 'ProjectPlatformSrc',
443+
path: './src/**/*.swift'
444+
},
445+
{
446+
name: 'Auth',
447+
path: '../../packages/**/*.{swift,m,h,modulemap}'
448+
},
449+
{
450+
name: 'Purchasing',
451+
path: '../../libs/**/*.{swift,m,h,modulemap}'
452+
}
453+
],
454+
}
455+
```
456+
395457
## Hooks Configuration Reference
396458

397459
```ts

content/guide/widgets-ios.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
---
2+
title: Developing Widgets for iOS
3+
---
4+
5+
[Widgets](https://developer.apple.com/design/human-interface-guidelines/widgets) display content and offer specific functionality without requiring people to open your app. People can use widgets to organize and personalize their devices, quickly accessing the information and features they need.
6+
7+
> A widget elevates and displays a small amount of timely, relevant information from your app or game so people can see it at a glance in additional contexts.
8+
9+
With NativeScript 8.9 CLI (`npm install -g nativescript`), you can create an iOS Widget with a single command:
10+
11+
```bash
12+
$ ns widget ios
13+
```
14+
15+
This will allow you to create a Home Screen Widget, a Live Activity on the lock screen or a combination of both.
16+
17+
## ns widget ios
18+
19+
The widget command generates all the necessary files for your NativeScript project to develop iOS widgets. The setup includes a fully functioning hypothetical pizza delivery widget which you can learn from and customize for your own needs.
20+
21+
The command will prompt to name the widget and choose a type. We will provide a custom name to outline exactly what is generated to explain each file.
22+
23+
```bash
24+
$ ns widget ios
25+
? What name would you like for this widget? (Default is 'widget') › pizza
26+
? What type of widget would you like? › - Use arrow-keys. Return to submit.
27+
Live Activity
28+
❯ Live Activity with Home Screen Widget - This will create a Live Activity that will display on the iOS Lock Screen with ability to also display a Home Screen Widget.
29+
Home Screen Widget
30+
```
31+
32+
Once the choice is made, the widget will be generated. Based on the above responses, you would see a few followup steps:
33+
34+
```bash
35+
Created Shared Resources: Shared_Resources/iOS/SharedWidget.
36+
37+
🚀 Your widget is now ready to develop: App_Resources/iOS/extensions/pizza.
38+
39+
Followup steps:
40+
41+
- Check App_Resources/iOS/build.xcconfig uses IPHONEOS_DEPLOYMENT_TARGET=17 or higher.
42+
- Update App_Resources/iOS/extensions/provisioning.json with your profile id.
43+
- Customize App_Resources/iOS/extensions/pizza/PizzaLiveActivity.swift for your display.
44+
- Customize Shared_Resources/iOS/SharedWidget/Sources/SharedWidget/PizzaModel.swift for your data.
45+
```
46+
47+
Let's discuss each note by outlining everything that was generated:
48+
49+
- `App_Resources/iOS/app.entitlements`: Includes the App Groups capability for shared data between your app and widget. _If one doesn't exist, it will be created for you._
50+
- `App_Resources/iOS/extensions/pizza/extension.json`: Xcode build configuration details. This is where additional frameworks, if desired, for your widget can also be included in the `frameworks` collection at the top.
51+
- `App_Resources/iOS/extensions/pizza/Info.plist`: The widget's info property list.
52+
- `App_Resources/iOS/extensions/pizza/pizza.entitlements`: Similar to the app.entitlements, this also includes the App Groups capability for shared data between your app and widget.
53+
- `App_Resources/iOS/extensions/pizza/PizzaBundle.swift`: This allows different widget features to be bundled together. For example, when choosing a Live Activity with a Home Screen Widget, both will be listed as part of the widget bundle here.
54+
- `App_Resources/iOS/extensions/pizza/PizzaHomeScreenWidget.swift`: The Home Screen Widget itself. This is where the view is defined as well as the [Timeline](https://developer.apple.com/documentation/widgetkit/timeline) which determines how data should be provided to the view. It comes already setup to use data from shared app/widget data which you can customize further.
55+
- `App_Resources/iOS/extensions/pizza/PizzaLiveActivity.swift`: The Live Activity to show on the lock screen. The view is defined via `LockScreenView` and also provides example customizations to the iPhone [Dynamic Island](https://support.apple.com/guide/iphone/use-the-dynamic-island-iph28f50d10d/ios).
56+
- `App_Resources/iOS/extensions/pizza/PrivacyInfo.xcprivacy`: The privacy policy for the widget. Refence documentation can be found [here](https://developer.apple.com/documentation/bundleresources/privacy-manifest-files).
57+
- `App_Resources/iOS/extensions/provisioning.json`: The provisioning profile configured to use with the widget id. On first generation, a placeholder is inserted however you can update this value to the provision profile needed.
58+
59+
::: tip Provisioning Profiles
60+
`open ~/Library/Developer/Xcode/UserData/Provisioning\ Profiles` and sort by modified date; this will allow you to find the profile id auto generated by xcode for your widget.
61+
:::
62+
63+
- `App_Resources/iOS/src/AppleWidgetUtils.swift`: This provides various static utilities for your NativeScript app to start, update and cancel live activities, as well as initiate widget updates and interact with shared data between your app and the widget.
64+
- `Shared_Resources/iOS/SharedWidget/Sources/SharedWidget/PizzaModel.swift`: This model is the contract of data between your app and your widget.
65+
66+
::: info Shared Model Data
67+
Because your app and widget are separate processes yet need to share the same model data to interact, `Shared_Resources/iOS/SharedWidget` is created as a local shared Swift package and auto configured via `nativescript.config` to share between your app and widget. This allows you to avoid unnecessary code duplication.
68+
:::
69+
70+
Your projects `references.d.ts` are also annotated to include strong types for `AppleWidgetUtils` usage from your TypeScript codebase:
71+
72+
```ts
73+
/**
74+
* Customize for your own Apple Widget Data
75+
*/
76+
declare interface AppleWidgetModelData {
77+
numberOfPizzas: number
78+
totalAmount: string
79+
message: string
80+
deliveryTime: number
81+
}
82+
declare class AppleWidgetUtils extends NSObject {
83+
static startActivity(data: AppleWidgetModelData): void
84+
static updateActivity(
85+
data: Pick<AppleWidgetModelData, 'message' | 'deliveryTime'>,
86+
): void
87+
static cancelActivity(data: Pick<AppleWidgetModelData, 'message'>): void
88+
static updateWidget(): void
89+
static updateDataWithKey(key: string, data: string): void
90+
static getDataWithKey(key: string): string
91+
static removeDataWithKey(key: string): void
92+
}
93+
```
94+
95+
Based on your own data needs, you can customize `AppleWidgetModelData` and the method signatures of `AppleWidgetUtils` to suit your case.
96+
97+
All shared group data between your app and widget are intended to be a string value so when using `AppleWidgetUtils.updateDataWithKey` with structured data, you can stringify it:
98+
99+
```ts
100+
AppleWidgetUtils.updateDataWithKey(
101+
'widgetData',
102+
JSON.stringify({
103+
pizzas: ['Pepperoni', 'Supreme', 'Hawaiian', 'Meat Lovers', 'Margherita'],
104+
orderTime: this.orderTime(),
105+
delivered: false,
106+
}),
107+
)
108+
```
109+
110+
This data is always decoded in the widget for it's own data purposes.
111+
112+
::: tip Widget Development
113+
All of the generated files are intended to be customized for your needs while at the same time giving you enough to follow to be successful at widget creation.
114+
:::
115+
116+
## Sample Project
117+
118+
A helpful sample project is available [here](https://github.com/NativeScript/widget-ios-example). It utilizes everything that `ns widget ios` provides for you to learn from.
119+
120+
## Resources
121+
122+
Additional features can be discussed anytime:
123+
124+
- https://github.com/orgs/NativeScript/discussions
125+
- https://github.com/NativeScript/NativeScript/issues/10703
126+
127+
Widget extensions have been supported with NativeScript for several years. Prior to 8.9, they required a number of manual steps. We'll include the following resources for additional context:
128+
129+
- https://blog.nativescript.org/add-home-screen-widget
130+
- https://www.bryanleetc.com/creating-a-share-extension-in-nativescript/
131+
- https://blog.nativescript.org/making-a-today-widget-in-ios-with-nativescript-and-ui-for-nativescript
132+
- https://old.docs.nativescript.org/tooling/ios-app-extensions.html
133+
134+
## Troubleshooting
135+
136+
Several common cases could occur while developing widgets.
137+
138+
### Minimum version targeting
139+
140+
The widget generator expects iOS 17 minimum.
141+
142+
If you encounter errors similar to the following:
143+
144+
```
145+
App_Resources/iOS/extensions/widget/WidgetBundle.swift:7:3: error: 'WidgetHomeScreen' is only available in application extensions for iOS 17.0 or newer
146+
```
147+
148+
Add the following line to your `App_Resources/iOS/build.xcconfig`:
149+
150+
```
151+
IPHONEOS_DEPLOYMENT_TARGET = 17;
152+
```

content/sidebar.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ export default [
299299
{
300300
text: 'Platform Version Handling',
301301
link: '/guide/platform-version-handling',
302+
},
303+
{
304+
text: 'Widgets for iOS',
305+
link: '/guide/widgets-ios',
302306
}
303307
],
304308
},

content/ui/action-bar.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ By default, a border is drawn at the bottom of the ActionBar. In addition to the
8888
<ActionBar title="MyApp" flat="true" />
8989
```
9090

91+
:::tip 8.9+
92+
You can alternatively use `iosShadow="false"` in the event you want to keep the translucency but remove the border.
93+
:::
94+
95+
```xml
96+
<ActionBar title="MyApp" iosShadow="false" />
97+
```
98+
9199
## Props
92100

93101
### title
@@ -98,6 +106,14 @@ title: string
98106

99107
Gets or sets the ActionBar title.
100108

109+
::: tip 8.9+
110+
On iOS, you can also enable prefersLargeTitles by setting `iosLargeTitle="true"`
111+
:::
112+
113+
```xml
114+
<ActionBar title="MyApp" iosLargeTitle="true" />
115+
```
116+
101117
### titleView
102118

103119
```ts

content/ui/activity-indicator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ busy: boolean
7171

7272
Gets or sets whether the indicator is busy.
7373

74-
### iosIndicatorViewStyle
74+
### iosIndicatorViewStyle 8.9+
7575

7676
```ts
7777
iosIndicatorViewStyle: IOSIndicatorViewStyle = 'medium' | 'large'

content/ui/text-view.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,42 @@ autocorrect: boolean
130130

131131
Enables or disables autocorrect.
132132

133+
### isWritingToolsActive 8.9+
134+
135+
(iOS Only) Are Apple Intelligence writing tools active.
136+
137+
```ts
138+
isWritingToolsActive: boolean
139+
```
140+
141+
### enableWritingToolsEvents 8.9+
142+
143+
(iOS Only) Allow Apple Intelligence writing tools to emit text changes on each alteration instead of after the final change (default).
144+
145+
```ts
146+
enableWritingToolsEvents: boolean
147+
```
148+
149+
### iosWritingToolsBehavior 8.9+
150+
151+
(iOS Only) Behavior for Apple Intelligence Writing Tools.
152+
153+
```ts
154+
iosWritingToolsBehavior: WritingToolsBehavior
155+
```
156+
157+
Can be `Default`, `Complete`, `Limited` or `None`.
158+
159+
### iosWritingToolsAllowedInput 8.9+
160+
161+
(iOS Only) Allowed input for Apple Intelligence Writing Tools.
162+
163+
```ts
164+
iosWritingToolsAllowedInput: Array<WritingToolsAllowedInput>
165+
```
166+
167+
Can be `Default`, `List`, `PlainText`, `RichText` or `Table`.
168+
133169
### ...Inherited
134170

135171
For additional inherited properties not shown, refer to the [API Reference](/api/class/TextView).

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@
4848
]
4949
},
5050
"packageManager": "[email protected]+sha256.732620bac8b1690d507274f025f3c6cfdc3627a84d9642e38a07452cc00e0f2e"
51-
}
51+
}

0 commit comments

Comments
 (0)