Questions tagged [uiviewrepresentable]

229 questions
2
votes
1 answer

How do I stop SwiftUI from reloading WKWebView page that I am using via UIViewRepresentable?

My code sets the navigation bar title it gets from web page, but everytime this causes the whole WKWebView to reload... The page is quite heavy so consumes a lot of time. Same behaviour when using button to set title. struct TransitScreen: View,…
Sulphur
  • 71
  • 5
2
votes
1 answer

Resizable UITextView Has sizeThatFits That Gives Wrong Size in UIViewRepresentable

I am using a UITextView in a SwiftUI app in order to get a list of editable, multiline text fields based on this answer: How do I create a multiline TextField in SwiftUI? I use the component in SwiftUI like this: @State private var textHeight:…
Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128
2
votes
1 answer

SwiftUI: Create own TextField and change the content programmatically

I created my own TextField with the following tutorial:https://www.youtube.com/watch?v=9kfbJVqqTKc&t=17s. Every things works fine but I added a feature to refresh the content of the TextField. The problem is that when I set the content…
Lukas
  • 251
  • 2
  • 13
2
votes
1 answer

SwiftUI: updateUIView() function in UIViewRepresentable causes app to freeze and CPU to spike

I have a custom Text Field in SwiftUI, that adjusts the number of lines it has according to the amount of content in the text field. In the app, the user can add text fields, and so I'm storing the heights, and content of the text fields in arrays,…
2
votes
1 answer

SwiftUI: how to resize the UIViewRepresentable output?

I try to build a basic Live Photo app on SwiftUI and struggle with display of the selected photo. To do so I tried to make UIViewRepresentable for PHLivePhotoView: import SwiftUI import PhotosUI struct LivePhotoView: UIViewRepresentable { …
Igor Kashin
  • 113
  • 8
2
votes
1 answer

Swiftui - Access UIKit methods/properties from UIViewRepresentable

I have created a SwiftUI TextView based on a UITextView using UIViewRepresentable (s. code below). Displaying text in Swiftui works OK. But now I need to access internal functions of UITextView from my model. How do I call e.g. …
Chris
  • 1,231
  • 2
  • 10
  • 20
2
votes
1 answer

SwiftUI + UIView touch events collision

I have a View that contains UIViewRepresentable (some UIView). That UIView has a button as a subView that has its own action. I have 2 problems: If SwiftUI view has no tap gestures attached, UIView's button event (UIControlEventTouchUpInside)…
protspace
  • 2,047
  • 1
  • 25
  • 30
2
votes
1 answer

How to add onCommit, isEditing, and ability to have a custom binding to a custom textview?

What is the best way to give the below UIViewRepresentable isEditing and onCommit properties? I'd like it to have the same exact functionality on call of TextFields in SwiftUI (where you can add code for what to do when the return key is pressed…
nickcoding
  • 305
  • 8
  • 35
2
votes
1 answer

TableView Reload Not working with UIViewRepresentable in SwiftUI

I am trying to reload tableView after I have a response from API. TableView reload does not call cellForRowAt as initially it was initialized with empty items. I have added the minimum required code to replicate the issue. Code for…
user832
  • 796
  • 5
  • 18
2
votes
1 answer

UIToolbar in iOS 13 SwiftUI?

I'm attempting to adapt UIToolbar to UIViewRepresentable to use it within SwiftUI. I'm required to support iOS 13, otherwise I would be using Apple's new toolbar in iOS 14. So far I have code that displays the toolbar on the screen, however it…
2
votes
2 answers

Understanding UIViewRepresentable

Swift 5.0 iOS 13 Trying to understand how UIViewRepresentable works, and put together this simple example, almost there, but maybe its complete nonsense. Yes, I know there is already a tapGesture in SwiftUI, this is just a test. Won't compile…
user3069232
  • 8,587
  • 7
  • 46
  • 87
2
votes
2 answers

SwiftUI recording video with live preview

Trying to make screen that allows user to record video with 30-second timer, and then I want to send it on server. The problem is delegate method is not called (see 2nd code part). What I did, is PreviewView as UIView, time and session settings.…
George Heints
  • 1,303
  • 3
  • 20
  • 37
2
votes
1 answer

CollectionView : UIViewRepresentable + NavigationView

I use SwiftUI and this is UIViewRepresentable. I did CollectionView by this way. When I try to. add NavigationView in the controller, it works, but incorrect. When I scroll, the space between the collectionView and the navigationView is freed…
Egor
  • 199
  • 2
  • 12
2
votes
1 answer

Using `UIViewRepresentable` to bridge a `UITextView` that grows and shrinks to fit its text to SwiftUI

If I want a non-scrolling UITextView that takes the entire width and grows and shrinks vertically to fit its text, I can do it like this in UIKit: import UIKit class TestViewController: UIViewController { private lazy var textView =…
jjoelson
  • 5,771
  • 5
  • 31
  • 51
2
votes
5 answers

Implement PencilKit undo functionality using SwiftUI

Edit: Thanks to some of the feedback, I have been able to get this partially working (updated code to reflect current changes). Even though the app appears to be working as intended, I am still getting the 'Modifying state...' warning. How can I…
PointOfNilReturn
  • 416
  • 4
  • 13