Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 43ea157

Browse files
chore(update-plugins): Mon May 27 08:06:12 UTC 2024
1 parent 5acc3b9 commit 43ea157

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

‎plugins/swift-ui.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Use SwiftUI with NativeScript.
2929
- [Open Multiple Scenes](#open-multiple-scenes)
3030
- [Passing contextual data to scenes](#passing-contextual-data-to-scenes)
3131
- [Closing windows](#closing-windows)
32+
- [Use NativeScriptView inside SwiftUI](#use-nativescriptview-inside-swiftui)
3233
- [Credits](#credits)
3334
- [License](#license)
3435

@@ -49,6 +50,12 @@ For example, you can add this line to your `App_Resources/iOS/build.xcconfig`:
4950
IPHONEOS_DEPLOYMENT_TARGET = 13.0
5051
```
5152

53+
:::tip Note
54+
55+
If you would like to use `NativeScriptView` inside SwiftUI, you should target 14.0 minimum.
56+
57+
:::
58+
5259
## Usage
5360

5461
![SwiftUI Source Files Example](https://raw.githubusercontent.com/NativeScript/ui-kit/main/packages/swift-ui/swift-ui-source-files-example.png)
@@ -357,6 +364,40 @@ struct NeatView: View {
357364

358365
`XR.endSession()` for an Immersive Space which is already open will close it.
359366

367+
## Use NativeScriptView inside SwiftUI
368+
369+
You can also use NativeScript view layouts and components inside SwiftUI when targeting iOS 14.0 minimum.
370+
371+
Add this line to your `App_Resources/iOS/build.xcconfig`:
372+
373+
```
374+
IPHONEOS_DEPLOYMENT_TARGET = 14.0
375+
```
376+
377+
You can now register as many NativeScript views by an id for usage:
378+
379+
```ts
380+
import { SwiftUIManager } from '@nativescript/swift-ui'
381+
382+
SwiftUIManager.registerNativeScriptViews({
383+
Video: SceneVideoComponent
384+
})
385+
```
386+
387+
This will allow `SceneVideoComponent`, a NativeScript view component, to be used inside any SwiftUI component:
388+
389+
```swift
390+
struct ContentView: View {
391+
392+
var body: some View {
393+
394+
ZStack {
395+
NativeScriptView(id: "Video")
396+
}
397+
}
398+
}
399+
```
400+
360401
## Credits
361402

362403
- WindowManager and XR APIs were established with the Callstack team. Shoutout to: [Oskar Kwaśniewski](https://github.com/okwasniewski).

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /