I have a View that defines a row to be displayed in a ScrollView in a macOS app. On the right side of the view is a button, which is custom styled. When the row view is on its own or embedded in another normal view, everything draws normally. However, when it's embedded in a ScrollView, the button appears shifted up and to the left from where it should be drawn. This happens regardless of whether the scrollbar is hidden or shown (with the showsIndicator: argument label or by turning it off manually in System Preferences).
Here's how the ScrollView is built up:
Also, here's an abridged version of the row View:
At imgur.com/a/FKa33bf (For some reason, I'm not allowed to actually link) is an Imgur album of screenshots of the previews of these views. I have a .border(Color(.red)) on the button for demonstration purposes.
Does anyone know what's going on? Or is this just a SwiftUI bug that may be patched up later?
Here's how the ScrollView is built up:
Code Block ScrollView { ForEach(permissions.indices) { PermissionCell(permissionUpdateBlock: self.calculateEnabledCount, permission: permissions[$0]) .background(Color(($0 % 2 == 0 ? scrollViewBackgroundColor : scrollViewBackgroundAlternateColor) ?? .white)) } } .padding(0) .border(Color(isDarkTheme ? .darkGray : .lightGray)) .background(Color(scrollViewBackgroundColor))
Also, here's an abridged version of the row View:
Code Block struct PermissionCell: View { var permissionUpdateBlock: (() -> ()) var permission: TSKPermission @State private var permissionStatus = PermissionStatus.notDetermined var body: some View { VStack { HStack { if permission.icon != nil { Image(nsImage: permission.icon!) .padding(.vertical, 15) .padding(.trailing, 10) } VStack(alignment: .leading) { Text(permission.title) .fontWeight(.bold) Text(permission.purpose) .font(.caption) } Spacer() if permissionStatus == .notDetermined { Button(action: { self.permission.askForPermission { self.updatePermissionStatus() } }) { Text("Enable") } .buttonStyle(TSKButtonStyle(backgroundColor: Color(TSKThemeManager.sharedInstance.snagitBlueColor()), textColor: .white)) .frame(width: 80, height: 25) .border(Color.red) } else { ... } } .padding(.horizontal, 15) .frame(height: 70) } ...
At imgur.com/a/FKa33bf (For some reason, I'm not allowed to actually link) is an Imgur album of screenshots of the previews of these views. I have a .border(Color(.red)) on the button for demonstration purposes.
Does anyone know what's going on? Or is this just a SwiftUI bug that may be patched up later?