Skip to content

Commit

Permalink
chore(update-plugins): Mon May 27 08:04:43 UTC 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
nativescript-oss committed May 27, 2024
1 parent bc2d4ad commit 715e382
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions content/plugins/swift-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Use SwiftUI with NativeScript.
- [Open Multiple Scenes](#open-multiple-scenes)
- [Passing contextual data to scenes](#passing-contextual-data-to-scenes)
- [Closing windows](#closing-windows)
- [Use NativeScriptView inside SwiftUI](#use-nativescriptview-inside-swiftui)
- [Credits](#credits)
- [License](#license)

Expand All @@ -50,6 +51,12 @@ For example, you can add this line to your `App_Resources/iOS/build.xcconfig`:
IPHONEOS_DEPLOYMENT_TARGET = 13.0
```

:::tip Note

If you would like to use `NativeScriptView` inside SwiftUI, you should target 14.0 minimum.

:::

## Usage

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

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

## Use NativeScriptView inside SwiftUI

You can also use NativeScript view layouts and components inside SwiftUI when targeting iOS 14.0 minimum.

Add this line to your `App_Resources/iOS/build.xcconfig`:

```
IPHONEOS_DEPLOYMENT_TARGET = 14.0
```

You can now register as many NativeScript views by an id for usage:

```ts
import { SwiftUIManager } from '@nativescript/swift-ui'

SwiftUIManager.registerNativeScriptViews({
Video: SceneVideoComponent,
})
```

This will allow `SceneVideoComponent`, a NativeScript view component, to be used inside any SwiftUI component:

```swift
struct ContentView: View {

var body: some View {

ZStack {
NativeScriptView(id: "Video")
}
}
}
```

## Credits

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

0 comments on commit 715e382

Please sign in to comment.