Underline Text wrapped in another View - swiftui

The SwiftUI modifier .underline() can be used to underline Text:
Text("Hello").underline()
Similarly, the modifier .font(…) can be used to change to font of text:
Text("A nice picture").font(.caption)
The .font(…) modifier also works on any View as well as a Text, so you can use .font() on a Group or HStack or your own View conforming struct. Doing so will change the font used by Text in that View – sweet. If I look up .font(), I can see it's an extension on View, so this makes sense, although seems rather magical!
However, the .underline() modifier can't (as far as I can tell) be used on any View to cause Text in it to be underlined. Similarly, .strikethrough() and .italic() and lots of other Text modifiers aren't available. They're defined as an extension on Text, so only work on this type.
I was wondering:
Is there a nice solution for this so that I can .underline() on parent view to get underlining on its contained Text children?
Why is SwiftUI currently like this?

Related

SwiftUI present sheet in a TabItem of TabView using presentationDetents

I am trying to create the same experience where a sheet is presented in one of the tab items of a TabView - not covering the tabs.
I am using .presentationDetents() and SwiftUI4.0 for that.
See example of Apple's own app doing that
The sheet is covering the child view inside TabView.
However, instead in my own code I am getting
this - the tabs of the parent view are covered by the modal sheet
The link https://developer.apple.com/forums/thread/711702 suggests that it is not possible to achieve the same behaviour you see in Apple's Maps and Find My apps with the current SwiftUI API.

SwiftUI custom font meta data requirements for "native" `.bold()` modifier

From https://blog.eidinger.info/what-can-go-wrong-when-using-custom-fonts-in-swiftui I recently learned, that if we have a font-regular and font-bold SwiftUI can infer the bold font when we use the .bold() modifier, which is awesome. (If we registre them).
Now I have two licensed fonts, one where it works and one where it doesn't, and I wonder what in the meta-data of the fonts could break this behaviour?
I have the two fonts: SharpSans and SharpGrotesk, both in a medium and a bold format. For the SharpSans it all just works. It uses the medium as regular, and responds to .bold(), .fontWeight() and even SwiftUI.Text markdown boldness. However, for SharpGrotesk it only works by using .fontWeight() but I would very much like it to support both .bold() and SwiftUI.Text markdown formatting.

Is there a way to avoid view type erasure when implementing the view style pattern?

Is there any trick that Apple uses to avoid style body type erasure?
I'm assuming a typical style modifier method just passes the style through environment.
func buttonStyle<S>(_ style: S) -> some View where S: ButtonStyle {
environment(\.buttonStyle, AnyButtonStyle(style))
}
where AnyButtonStyle wraps body made of the wrapped style into AnyView.
If my assumption is wrong, how do they pass a style down into a view hierarchy without losing specialized type of the style?
If my assumption is correct, it seems like basically most views (Label, Button, Picker, List, Toggle, TextField...) must be resolved in a view graph from AnyView since their bodies are made type erased from a style. How it isn't too bad for the view graph resolver?

SwiftUI accessibilityScrollAction not accepting rectangle edge as valid?

So I'm trying to make an accessible game using SwiftUI, and it would be awesome to have a custom scroll action for blind users so that they don't have to swipe items using an extra set of gestures.
I'm trying to implement the scroll action on a view, but so far I've had no luck.
I have tried setting the edge to something like .leading, but it says that type Edge has no member leading. I also tried putting a . and letting it auto complete (nothing), and reading the documentation, which also gives me nothing, except that things like .leading, .top, etc should be working and are not.
.accessibilityScrollAction(handler: (.leading))
Type '(Edge) -> Void' has no member 'leading', mainView.swift, Error

Best way to display static text in a view RubyMotion

I have a two view app. The root view has items that simply have a details view. In that details view is a simple section label (the item name) followed by a paragraph description.
What is the best way to display this static text? Is the best option UILabel?
Usually a UILabel works fine. Make sure you set the lineBreakMode to zero (0) so it will wrap.