Modal Picker Not Scrolling Right Swiftui

Modal picker not scrolling right SwiftUI

What if I told you the reason your Picker not working was this line?

.cornerRadius(20).shadow(radius: 20)

Unfortunately, SwiftUI is still quite buggy and sometimes it doesn't do what it is supposed to do and especially Pickers are not that reliable. I guess we'll need to wait and see the next iteration of SwiftUI, but for now you can replace that line with the code below:

.mask(RoundedRectangle(cornerRadius: 20))
.shadow(radius: 20)

Popup view pushes current view SwiftUI

Just use ZStack instead of VStack. Tested with Xcode 11.4 / iOS 13.4

var body: some View {

ZStack { // << here
Button(action: {

SwiftUI Issues with sheet modifier

.sheet being embedded inside a List does only open once is a known bug and I hope they fix it. Until then you have to move .sheet outside of any List.

But since the .sheet is not inside a List but inside a NavigationView, it might a good idea to try to move the .sheet outside of it.

But do not attach two .sheet two the same View, but add them the following way instead:

VStack{
NavigationView{ ... }
Text("").hidden().sheet(...)
Text("").hidden().sheet(...)
}

SwiftUI fileImporter modifier: document picker shows up blank at first run

New development: this only happens when the initial document browser view is configured to show its content in COLUMNS mode - if in ICONS or LIST mode, works fine, the picker shows appropriately populated. I am scratching this one as a bug, already reported to Apple.

SwiftUI - Remove padding around Picker SegmentedPickerStyle when in a Form Section

Because Forms are using grouped list style, you'll have to set the inset to zero and change the background color of the picker row:

        Form {
Picker("My Picker", selection: .constant(0)) {
ForEach(0..<3) {
Text(String($0))
}
}
.pickerStyle(SegmentedPickerStyle())
.listRowInsets(.init())
.listRowBackground(Color(.secondarySystemBackground))
}

SwiftUI view content layout unexpectedly pop / jumps on appear?

Providing a section with a header text fixes the issue, even if the text is blank. Although this will leave a gap between the navigation title and first row.

Works with both Forms & Lists styled as grouped.

struct TestView: View {

var body: some View {
Form {
Section(header: Text("")) {
Text("Test View")
}
}
.nvigationBarTitle("Test View")
}
}

SwiftUI Form and StackNavigationViewStyle run berserk

Update: With Xcode 12 this bug is fixed.

With Xcode 11.3.1 there seems to be a bug in Form, making a new copy of the view with every orientation change of the device.

Sample code:

import SwiftUI

struct ContentView: View {
var body: some View {
Form{
Text("Text")
}
}
}

Visual debugger at beginning, rotate left and then rotate right:

Visual debugger

A Form automatically adopts the GroupedListStyle and it seems that it’s actually there the bug is. Because a List with GroupedListStyle shows the same behaviour in the visual debugger.

import SwiftUI

struct ContentView: View {

var body: some View {
List{
Text("Text")
}.listStyle(GroupedListStyle())
}
}

Dismiss a SwiftUI View that is contained in a UIHostingController

UPDATE: From the release notes of iOS 15 beta 1:

isPresented, PresentationMode, and the new DismissAction action dismiss a hosting controller presented from UIKit. (52556186)


I ended up finding a much simpler solution than what was offered:


final class SettingsViewController: UIHostingController<SettingsView> {
required init?(coder: NSCoder) {
super.init(coder: coder, rootView: SettingsView())
rootView.dismiss = dismiss
}

func dismiss() {
dismiss(animated: true, completion: nil)
}
}

struct SettingsView: View {
var dismiss: (() -> Void)?

var body: some View {
NavigationView {
Form {
Section {
Button("Dimiss", action: dismiss!)
}
}
.navigationBarTitle("Settings")
}
}
}


Related Topics



Leave a reply



Submit