Questions tagged [uiviewrepresentable]
122 questions
15
votes
1 answer
SwiftUI - State change in UITextField causes the frameWidth to grow uncontrolled and ignore bounds/frame
I am using SwiftUI and bridge to UITextField (I need to assign firstResponder). I use the code from here: SwiftUI: How to make TextField become first responder?
The following code updates my @Binding var. This of course is intended behavior. The…
![](../../users/profiles/12396087.webp)
denninho
- 233
- 1
- 6
15
votes
3 answers
SKView warning logs
When running my SwiftUI & SpriteKit app, I get the following messages in the logs:
2019-11-18 21:58:57.631912+0000 PixelBattles[2812:1215803]
SKView: ignoreRenderSyncInLayoutSubviews is NO. Call _renderSynchronouslyForTime without handler
What am…
![](../../users/profiles/9607863.webp)
George_E
- 8,913
- 3
- 35
- 76
8
votes
4 answers
Implementing Apple Pay with SwiftUI
This is my first time working with PassKit and with SwiftUI on a big project. I'm trying to implement Apple Pay SwiftUI and since there isn't a native way to do so yet, I tried wrapped the PKPaymentAuthorizationViewController in…
![](../../users/profiles/2805119.webp)
user2805119
- 153
- 1
- 5
8
votes
1 answer
SwiftUI View not updating its state when embedded in UIView (using UIHostingController)
I'm wanting to use a SwiftUI View as content for a child UIView (which in my app would be inside UIViewController) by passing SwiftUI. However the SwiftUI View doesn't respond to state changes once embedded inside UIView.
I created the simplified…
![](../../users/profiles/8190951.webp)
Damo
- 81
- 2
7
votes
6 answers
SwiftUI - iOS 13 UIViewRepresentable of WKWebView gets Thread 1: EXC_BREAKPOINT crash
I'm trying to port WKWebView over to SwiftUI. Here's my code:
import SwiftUI
import WebKit
struct ContentView: View {
var body: some View {
WebViewWrapper()
}
}
/**
WKWebView ported over to SwiftUI with `UIViewRepresentable`.
…
![](../../users/profiles/14351818.webp)
aheze
- 6,076
- 3
- 6
- 40
7
votes
3 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…
![](../../users/profiles/49951.webp)
Jaanus
- 17,268
- 14
- 62
- 102
7
votes
4 answers
Changes to ObservedObject don't update a UIViewRepresentable
Simplest example below. Works fine in preview (UITextView text updates to "ouch"). But, run it in an app (ie add as rootView by the sceneDelegate), and the UITextView doesn't update.
import SwiftUI
class ModelObject : ObservableObject{
…
![](../../users/profiles/11671301.webp)
Rumbles
- 554
- 1
- 5
- 14
6
votes
1 answer
SwiftUI not refresh my custom UIView with UIViewRepresentable & ObservableObject
create a simple ARClass: ObservableObject with @Published var
name: String
create custom ARView: UIView received ARClass as
parameter and draw Text from ARClass.name at center
create UIViewRepresentable
and then use in SwuftUI View by using…
![](../../users/profiles/7486240.webp)
Anan R
- 231
- 1
- 8
5
votes
0 answers
SwiftUI UITextView wrapper how to size it content to match parent
I have such UITextView wrapper and it works but when I place it inside List row. I would like it to autosize, i.e. have width that match parent in this case List Row VStack { }, and height that is autosize based on text length. Text should wrap.…
![](../../users/profiles/4415642.webp)
Michał Ziobro
- 7,390
- 6
- 50
- 99
4
votes
0 answers
Interacting with a SwiftUI view below a UIKit PKCanvasView
I have a view Structure as follows:
ZStack {
UIKitView //PKCanvasView
.zIndex(1)
SwiftUIView //SwiftUI view which has a gesture recogniser
.zIndex(0)
}
I wanted to know what the best way was to allow simultaneous…
![](../../users/profiles/13296730.webp)
santi.gs
- 278
- 1
- 8
4
votes
1 answer
Set custom UIView frame in UIViewRepresentable SwiftUI
I'm trying to use my custom UIView in SwiftUI using UIViewRepresentable and I want my UIView to have the same size as I set in .frame() so that I can use it like this:
MyViewRepresentable()
.frame(width: 400, height: 250, alignment: .center)
For…
![](../../users/profiles/12517479.webp)
IrelDev
- 158
- 2
- 9
3
votes
0 answers
How to programmatically trigger UIMenu from UIViewRepresentable
I tried to create a custom SwiftUI menu (based on UIMenu).
However, I'm unable to trigger the primary action.
It works when I tap on the CustomMenu but the programmatic action is not triggered. What am I doing wrong?
struct CustomMenu:…
![](../../users/profiles/8697793.webp)
pawello2222
- 23,992
- 12
- 59
- 94
3
votes
2 answers
Size a UILabel in SwiftUI via UIViewRepresentable like Text to wrap multiple lines
The goal is to get a UILabel integrated via UIViewRepresentable to size the same way Text does - use the available width and wrap to multiple lines to fit all the text thus increasing the height of the HStack it's in, instead of expanding in width…
![](../../users/profiles/1795356.webp)
Jordan H
- 45,794
- 29
- 162
- 306
3
votes
0 answers
Finger and Pencil width on PKCanvasView Different
I am trying to build out an application with the ability to use both apple pencil and finger input to draw. However, when I set the width of the tool to a sufficiently small number (1) the pencil input displays correctly, but when I use my finger it…
![](../../users/profiles/10214652.webp)
balt2
- 75
- 5
3
votes
1 answer
How to make UIViewRepresentable focusable on tvOS in SwiftUI?
The title says it all - I can't get focus on UIViewRepresentable in SwiftUI on tvOS. Any view that conforms to View protocol can be focused without problems but neither UIViewRepresentable nor UIViewControllerRepresentable can.
Any ideas?
This code…
![](../../users/profiles/1732868.webp)
gutaker
- 181
- 2
- 9