Questions tagged [uihostingcontroller]

78 questions
5
votes
4 answers

NavigationView embedded in a UIHostingController has additional safe area insets

Anyone know how to deal with this? Seems as though when you have a UIHostingController with a NavigationView the following happens: Notice the big grey tab bar safe area. This is primarily a UIKit application. Were replacing on of our tabs in the…
Xaxxus
  • 1,083
  • 12
  • 19
5
votes
4 answers

UITabBar containing SwiftUI View

I have the below series of controllers and views. However, when I use the navigation link on the MoreView it changes the tabBarItem.title value. For instance it will say more, but when the privacy policy button is clicked and the user is navigated…
Austin E
  • 823
  • 1
  • 9
  • 22
4
votes
0 answers

Disable keyboard avoidance in a bottom sheet

TLDR: The view modifier .ignoresSafeArea(.keyboard) does not appear to work when used inside a bottom sheet. Is there a workaround? In a SwiftUI View, tapping a TextField invokes the keyboard and the Textfield then moves upwards to avoid the…
Dave Robertson
  • 431
  • 3
  • 6
4
votes
1 answer

UIHostingController doesn't update its size properly properly

I am using UIHostingController in one of the apps I'm working on and I have a problem. The embedded SwiftUI View changes its' height dynamically, but I can't seem to get the grasp on how to update it in the view it is embedded in. The problem…
4
votes
0 answers

Add SwiftUI view to UIView subview, without access to parent UIViewController

I have seen many examples of how to add a SwiftUI view into a UIKit view using Container Views, which assume you have access to the parent UIViewController on the UIKit side. I have a case where I can't do that; specifically, I want to add a SwiftUI…
Z S
  • 7,039
  • 12
  • 53
  • 105
4
votes
2 answers

Delegate for SwiftUI View from Hosting View Controller

I add UIHostingViewController to my Storyboard and make class for this. Load mySwiftUIView in controller init. Everything works good. But i want to make hosting controller like delegate for mySwiftUIView because I want to handle button pressing in…
Ivan
  • 43
  • 1
  • 3
3
votes
1 answer

Inserting UIHostingController with changeable height into UIStackView

I have an issue where I'm trying to insert a SwiftUI view into an existing UIKit view. The SwiftUI view can change height dynamically, but the UIStackView does not adjust to the new size. I've created a (hideous) test project to highlight…
DevB1
  • 1,235
  • 3
  • 17
  • 43
3
votes
1 answer

Get sourceRect of a SwiftUI view for popover presentation in UIKit ViewController (via UIHostingController)

I'm using the following pattern: UIViewController that has UIHostingController as immediate child and of course the UIHostingController view added as subview of the main VC and anchoring to the edges lazy var hostingVC =…
vomi
  • 993
  • 8
  • 18
3
votes
1 answer

SwiftUI View inside UIView

I am trying to inject a SwiftUI view inside of a UIView, and it is showing my SwiftUI view but the frame is way off and I cannot figure out why. UPDATE: After dismissing the view controller and reloading it again, the SwiftUI view is…
tHatpart
  • 1,302
  • 3
  • 12
  • 27
3
votes
1 answer

Does UIHostingController have to be in the view controller hierarchy?

I want to embed some SwiftUI in my UIKit-based UI, and unfortunately Apple doesn't provide UIHostingView, only UIHostingController. Can I more or less ignore that controller and just use its view, or do I really need to add it as a child view…
Uncommon
  • 3,323
  • 2
  • 18
  • 36
3
votes
1 answer

Casting UIWindow.rootView to UIHostingController which has environment variables

Casting UIWindow.rootView to a hosting controller like: window?.rootViewController as? UIHostingController works fine, unless it has environmentObjects. As my MainTabView has been initialized with .environmentObject, I cannot cast it…
Rashid
  • 1,515
  • 16
  • 16
3
votes
2 answers

How to Instantiate UIHostingController with CoreData?

As a long-time Obj-C dev (since iPhone OS 2) I decided that SwiftUI was the nudge to use Swift! ¯\(ツ)/¯ Thus, I am still trying to understand how a language can be so type-vague in code, and so type-pedantic in the compiler!!! Pulling my hair out…
Linasses
  • 395
  • 4
  • 14
3
votes
2 answers

How to make a button that dismisses a view presented using UIHostingController/SwiftUI?

I have a fairly extensive project that I started with UIKit and now I've decided to use SwiftUI to make some simple form pages, but I need to make a button in SwiftUI to dismiss the current view which is presented with the following code: func…
Watermamal
  • 357
  • 3
  • 12
3
votes
1 answer

How to dismiss swiftUI from Viewcontroller?

In my an viewController I have this function ...{ let vc = UIHostingController(rootView: SwiftUIView()) present(vc, animated: true, completion: nil) } Which present the following SwiftUIView. Q How to dismiss the SwiftUIView when…
RyanTCB
  • 7,400
  • 5
  • 42
  • 62
2
votes
1 answer

How do I fix this layout of a SwiftUI view inside of a UIHostingController?

In my UIKit based app, I have a simple SwiftUI view that my app shows when a screen has no records to show. I'm embedding it in a UIHostingController to do this. The problem is that the contents of the view are shoved off to the upper left corner of…
Jim
  • 1,260
  • 15
  • 37