Post

Replies

Boosts

Views

Activity

DismissAction or PresentationMode from Environment break Accent Color on presented sheets?
Anyone else notice that the DismissAction or PresentationMode will break accent color on sheets? struct ContentView: View { // Un-comment either of the below lines, and the tint color of SheetView becomes gray, rather than red. // @Environment(\.dismiss) var dismiss // @Environment(\.presentationMode) var presentationMode @State var sheetPresented = false var body: some View { Button("Show Sheet") { sheetPresented.toggle() } .sheet(isPresented: $sheetPresented) { SheetView() .accentColor(.red) } } } struct SheetView: View { @Environment(\.dismiss) var dismiss var body: some View { Button("Dismiss") { dismiss() } .foregroundColor(.accentColor) } }
4
0
1.1k
Jul ’21
AttributedString with Markdown not rendering in Text in SwiftUI?
I assumed this was a beta 1 or 2 bug, but as of beta 4 I'm still seeing this behavior, so perhaps I'm doing something wrong: Text is supposed to render AttributedStrings with Markdown. It appears to render correctly when a direct String literal is passed into the Text, but not when the AttributedString is a variable. Am I doing something super dumb? struct ContentView: View {     var text = AttributedString("**Hello**, `world`! Visit our [website](https://www.capitalone.com).")     var body: some View {         VStack {             Text("**Hello**, `world`! Visit our [website](https://www.capitalone.com).")                 .padding()             Text(text)                 .padding()         }     } }
1
0
1.9k
Jul ’21
SwiftUI List/Form Header Alignment on iOS 15?
Hi there, With the following code on iOS 15, the header text is aligned with the text within the List or Form: Form {     Section {         Text("Hello, world!")     } header: {         Text("Section Header").sectionHeaderStyle()     } } .listStyle(InsetGroupedListStyle()) //... public extension Text {     func sectionHeaderStyle() -> some View {         self             .font(.system(.title3))             .fontWeight(.bold)             .foregroundColor(.primary)             .textCase(nil)     } } However, back on iOS 14, the analogous code aligns the header with the List Section itself: Form {     Section(header: Text("Section Header").sectionHeaderStyle()) {         Text("Hello, world!")     } } .listStyle(InsetGroupedListStyle()) Does anyone know how to get the iOS 14 behavior of aligning the section header with the List Section itself, and not aligning with the text within the Section?
2
0
6.3k
Jul ’21
Is List re-ordering broken on macOS 11 and 12?
I have a simple List in a macOS app, and on a button click I change some state and re-sort the array of items. However, it seems like it breaks cell layout in the process. Is this type of thing not allowed or preferred? Is there an alternative way to re-order items in a List? class Model: ObservableObject {     @Published var items: [Item]     init(items: [Item]) {         self.items = items         updateQuestStatuses()     }     func updateQuestStatuses() {         items = items.sorted(by: { $0.status.rank > $1.status.rank })     } } struct ListView: View {     @StateObject var model: Model         var body: some View {         NavigationView {             List {                 ForEach($model.items, id: \.id) { $item in                     NavigationLink(destination: DetailView(item: $item, onUpdate: { [unowned model] in model.updateQuestStatuses() })) {                         HStack {                             Circle()                                 .foregroundColor(item.status.color)                                 .frame(width: 8, height: 8)                             Text(item.title)                         }                     }                 }             }             .frame(width: 350)         }         .background(Color(NSColor.textBackgroundColor))         .frame(maxWidth: .infinity, maxHeight: .infinity)     } } struct DetailView: View {     @Binding var item: Item     let onUpdate: () -> ()     var body: some View {         Button("Change It") {             item.status = .waiting             onUpdate()         }     } } See project: https://github.com/UberJason/ListReorderBug
2
0
785
Jun ’21
Apple Notes-like Text Editing?
Apple Notes on iOS and macOS does some wonderful simple text formatting, including supporting text styles (title, heading, body, monospace) and formatting (bold, italic, underline, monospace), lists (bulleted, dashed, numbered) and checklists. As the user types, Notes intelligently inserts the formatting (e.g. as the user types a dash, Notes automatically indents it and inserts an em-dash to start a dashed list). Is there a way to get Apple Notes-like text editing and formatting with minimal effort (ideally without dropping down into TextKit)? Ideally the experience is as close to the Notes app as possible, where the user can just start typing and the text editor automatically applies the appropriate formatting.
2
1
1.4k
Jun ’21
Foundation Markdown: What specification, what attributes are supported?
Hi there, I'm wondering what Markdown specification and/or attributes are supported? For example, as of iOS 15 beta 1, it seems like bolds, italics, links, and inline code blocks with single backticks work, but multi-line code blocks with three backticks lose newlines, and lists don't seem to be supported, just to make a few examples. See attached screenshot. I can't tell which of these are bugs or just unsupported.
1
0
1.2k
Jun ’21
onTapGesture and UITapGestureRecognizer unreliable in Big Sur Catalyst apps
Reposting from this post, - https://developer.apple.com/forums/thread/667401 in case it was missed. I also noticed that trying to workaround by using a UIViewRepresentable wrapper around a UIView that uses a tap gesture recognizer is just as unreliable. See project here: https://github.com/UberJason/TapGestureBug Filed as feedback FB8923074. Is there any update available?
0
0
927
Dec ’20
SwiftUI on watchOS: How to set initial focus?
I have an overall Form which contains, among other cells, a picker, e.g.: Form { 	 SomeCell() 	 SomeCell() 	 Picker(...) } The Picker isn't even initially on-screen - it's further down in the scroll view. But when the user first enters the screen, the picker has focus - the Digital Crown starts scrolling the picker. Then if the user uses their finger to scroll, the Digital Crown transfers focus to the overall Form scrolling, and I can't get the picker to regain focus for the Digital Crown at all anymore. How can I tell the system that the Digital Crown should initially focus on scrolling the Form and not the Picker, and to allow tapping on the Picker to give it focus for the Digital Crown? (i.e. the expected user experience.) This was one area which WatchKit seemed to handle better than SwiftUI does. For the record, I tried playing around a bit with focusable(), prefersDefaultFocus(in:), and focusScope() and declared a single namespace for the entire screen, but it didn't seem to help. I'm not sure if the Form object itself can really respond to focusable() anyhow.
1
0
1.3k
Sep ’20
Disable default styling of NavigationLink on watchOS?
NavigationLink is the only API I'm aware of for doing navigation controller push transitions in watchOS. However, a NavigationLink appears to add some default styling that I'd like to disable. For example, it appears to add padding to your content view in a ScrollView, and whether in a ScrollView or not, it sets a default platter background color and some corner rounding. The Button API does the same thing, but you can override this with .buttonStyle(PlainButtonStyle()) to disable styling and provide your own styling entirely. Is there a way to disable the styling of NavigationLink in watchOS, similar to how you can disable the Button styling with PlainButtonStyle?
1
0
1.8k
Sep ’20
How to access color from an asset catalog in a shared framework in a watchOS app?
Hi there, I have a shared framework between my iOS and watchOS apps which contains an asset catalog with some named colors. I'd like to access the named colors in my watchOS app. In iOS, I can use UIColor.init(named name: String, in bundle: Bundle, compatibleWith traitCollection: UITraitCollection) to tell the system to access the name from the passed-in Bundle. watchOS also claims to have this initializer available since watchOS 4; however, Xcode autocomplete doesn't find it, I get a build error when I try to use it, and it's a bit odd because UITraitCollection (which is part of that method signature) isn't exposed to us in watchOS anyhow. How can I access an asset from the asset catalog in my shared framework?
1
0
1.6k
Sep ’20
watchOS Button background color in SwiftUI?
How can I set the background color of a Button in watchOS using SwiftUI? If I use the regular .background(Color.blue) modifier (using blue as an example), the background draws as a sharp rectangle, ignoring the cornerRadius of the button (though you can see the cornerRadius faintly in the rectangle, which is almost worse). The cornerRadius is supposed to be 22.0 pt on Series 4 and 5 watches, but 9.0 pt on Series 3 and earlier. I'd rather not try to conditionally set the corner radius based on device (and I'm not even sure how to determine the type of device I'm running on).
3
0
5.0k
Aug ’20
How to render an inset grouped list as in the Watch Camera app?
At around 8:47 in the video, in the example of a More button for the watch Camera app, a sheet is presented with a "robust set of options" which are rendered in a style somewhat similar to the iOS UITableViewStyle.insetGrouped / InsetGroupedListStyle. However, InsetGroupedListStyle isn't exposed on watchOS 7. The closest analog I could see was when you embed a Picker into a List, the picker is rendered as a title/subtitle cell, and tapping on that cell presents a modal sheet with that one Picker's list of options in the same inset grouped style. However, this isn't an exact match - this picker has to be in a list, rather than a More button, and the picker only selects from one set of options, as opposed to multiple heterogeneous groups of options. Can anyone provide guidance on how to render a sheet with multiple, heterogeneous groups of options, like the Camera app's More sheet, in this video?
0
0
882
Aug ’20
SwiftUI .redaction(reason:) modifier renders question mark boxes for custom fonts
FB8236490 See project: https://github.com/UberJason/PlaceholderCustomFontBug In iOS 14 beta 3, SwiftUI's new redaction() modifier does not render custom fonts correctly. Instead, it renders a series of question mark boxes, similar to when a new emoji is attempted to be rendered on an older iOS version that doesn't recognize the emoji. See a screenshot here. - https://github.com/UberJason/PlaceholderCustomFontBug/blob/main/Screenshot.png Any workarounds?
2
0
863
Aug ’20