Questions tagged [nsviewrepresentable]
24 questions
9
votes
1 answer
WKWebView in SwiftUI not loading HTML string on macOS
first question on StackOverflow (and relatively new to native app dev targeting macOS).
I'm currently trying to build a simple SwiftUI view, that leverages WKWebView's loadHTMLString function, to display hardcoded HTML string on the screen.
AFAIK…

MQumairi
- 115
- 2
- 5
8
votes
2 answers
How to render multiline text in SwiftUI List with correct height?
I would like to have a SwiftUI view that shows many lines of text, with the following requirements:
Works on both macOS and iOS.
Shows a large number of strings (each string is backed by a separate model object).
I can do arbitrary styling to the…

Jaanus
- 17,688
- 15
- 65
- 110
5
votes
0 answers
SwiftUI 2.0 can't remove .titled from styleMask on NSWindow using NSViewRepresentable
I'm reworking my app for SwiftUI 2.0 but have come across a problem when replicating what I could do with AppDelegate.
I'm using NSViewRepresentable to get access to NSWindow so I can remove the titlebar of the window (I know it's not in the…

mousebat
- 474
- 7
- 25
4
votes
2 answers
How to auto-expand height of NSTextView in SwiftUI?
How do I properly implement NSView constraints on the NSTextView below so it interacts with SwiftUI .frame()?
Goal
An NSTextView that, upon new lines, expands its frame vertically to force a SwiftUI parent view to render again (i.e., expand a…

Beginner
- 455
- 7
- 14
3
votes
1 answer
Can I Stop NSViewRepresentable layout lag for NSTextView?
I am using an NSTextView inside NSViewRepresentable in a SwiftUI app.
The NSViewRepresentable correctly resizes to the height of the NSTextView, so the text flows to multiple lines, but on the first render after creation it only shows a single…

Giles
- 1,428
- 11
- 21
3
votes
1 answer
Swift UI not redrawing NSViewRepresentable wrapped textfield
I created a list-detail view like this. In the detail view, there is some input field that accepts text. The input field is a NSTextField wrapped using NSViewRepresentable. The issue happens in the below scenario.
First, click a row and select…

Sooraj P
- 73
- 7
3
votes
1 answer
How to use CAEmitterLayer on macOS in a SwiftUI app using NSViewRepresentable
I want to use a CAEmitterLayer within a macOS app that is based on SwiftUI.
Problem: The layer itself is perfectly visible, but it doesn’t emit any particles.
→ Here’s my demo project on GitHub
I basically built a NSViewRepresentable for a custom…

ixany
- 5,433
- 9
- 41
- 65
2
votes
0 answers
How to customize a table item content on selection and on emphasis change for a NSTableView?
I'm currently trying to create a 3-pane layout in SwiftUI. Since SwiftUI's List doesn't provide greater customisation, I decided to create my own NSViewRepresentableView based on NSTableView. The NSTableView has a single column and each row is…

technusm1
- 503
- 5
- 14
1
vote
0 answers
How can I animate NSPopover size change?
I have a SwiftUI view with fields that changes according to an object type that is about to be created. Each type has a different amount of fields, what makes the popover size change. I would like to make that change in size animated. How can I do…

Rafael Bitencourt
- 378
- 2
- 10
1
vote
1 answer
Real-time NSTextField formatter in SwiftUI context
After lots of trial and error, I ended up with the following implementation to do real-time formatting for numeric entry in a text field. Various attempts to use a SwiftUI TextField() resulted in many anomalies. The approach below seems to be solid…

CodeBuddy
- 427
- 4
- 14
1
vote
1 answer
NSViewRepresentable overlaps scrollbar making it impossible to click
When a NSViewRepresentable is embedded in a SwiftUI ScrollView AND the "show scroll bar" system setting is set to "When scrolling", it is impossible to drag or click the scrollbar.
I am trying to solve this for a while now, but I am running out of…

paxos
- 877
- 5
- 11
1
vote
0 answers
Autosized NSViewRepresentables in ScrollView overlap each other (SwiftUI)
I am trying to display items in a ScrollView which contains several autosized NSViewRepresentables. However, it seems the items overlap each other after scrolling or when the size of its parent ScrollView is changed:
If I understood correctly from…

Sebastian
- 115
- 1
- 8
1
vote
2 answers
Finding click location in SwiftUI on MacOS
I've tried to adapt a solution I've used on an iOS app to macOS using NSViewRepresentable instead of UIViewRepresentable.
Below is my 'Tappable View'. My problem is that when I try to use this view I get the error Cannot find "TappableView" in…

santi.gs
- 514
- 3
- 15
0
votes
0 answers
Using custom views from AppKit and UIKit in a SwiftUI app
I have a multiplatform SwiftUI app which uses a custom view that is platform-specific in that it derives from NSView on macOS and UIView on iOS. These are legacy classes written in Objective-C & I'd like to use them in my SwiftUI app.
The…

jkcl
- 2,141
- 3
- 16
- 19
0
votes
0 answers
Array Binding in NSViewRepresentable Updating Incorrectly After Sorting
I have a ForEach binding to an array of items. Each item has an index (which represents how it should be sorted), and some text. Each row in the ForEach has an NSTextView in an NSViewRepresentable (I can't use TextEditor for various reasons), which…

Michael Berk
- 365
- 2
- 16