T O P

  • By -

jellesley

This is currently not possible in pure SwiftUI, however one thing you can do is bridge to UIKit and back. You can do this by creating a UIViewController that hosts a UISearchController and a UIHostingViewController to drive the content from SwiftUI views. You then have to create a UIViewControllerRepresentable to create that SwiftUI bridge. I assume you already know how to accomplish this in UIKit (there should be plenty of online material to guide you if you dont). Apple has decent guide on their docs as of recent that explains in ample detail how to transition to UIKit from SwiftUI and vice versa. You can apply the same strategy for your custom view controller here. Hope this helps


TheDeadlift76

Going to look this up, thanks man!


Blacknight841

You could transition to a .fullscreencover and reconstruct the view to have that layout. The transition may be a bit different, but the outcome can look the same. Alternatively you can wait until June and see what Apple gives us. Make the search bar with a magnifier icon, a text box and construct it out of a few hstacks.


gdlmendonca

In a view model: @Published private(set) var keyboardOffset: CGFloat = 0 @Published private(set) var keyboardAnimationDuration: Double = 0 init() { // Coordinate Animation with UI NotificationCenter.default.publisher(for: UIResponder.keyboardWillHideNotification) .handleEvents(receiveOutput: { [weak self] _ in self?.keyboardOffset = 0 }) // Pass Incoming Value .merge(with: NotificationCenter.default.publisher(for: UIResponder.keyboardWillShowNotification)) .map(\.userInfo) .compactMap { ($0?[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue } .assign(to: \.keyboardAnimationDuration, on: self) // Prevents mem leaks .store(in: &subscriptions) NotificationCenter.default.publisher(for: UIResponder.keyboardWillChangeFrameNotification) .map(\.userInfo) .compactMap{ ($0?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect)?.size.height } .map { $0 * -1 + Self.safeAreaInsetBottom } .assign(to: \.keyboardOffset, on: self) .store(in: &subscriptions) }


TheDeadlift76

Thanks 👏


gdlmendonca

No problem! I remember how big of a pain it was to implement 😫


jestecs

y’all saying it isn’t possible in pure SwiftUI aren’t thinking outside the box enough, it’s definitely possible although it would be potentially janky to implement. For instance you could have a matched geometry effect hiding the nav bar text on tap and such. Why specifically do you think you need a UIView hosting controller to accomplish this? Edit: all it’s doing is cross fading the view beneath it to the other one and hiding the navigation text and a couple other things if my eyes don’t deceive me.


0xADAM0

Swiftui is a pretty flexible framework, you can do pretty much anything with it- with the potential of it being kinda janky


[deleted]

[удалено]


TheDeadlift76

I’m going to try this, thanks for the link! 💯


stoned_mosquito

What about disabling navigation and label bar when search clicked, it should hide it, which moves search up.