Hi, I would to like create a custom Text modifier that returns a Text, so that I can use the sum operator: Text(..) + Text(..) + Text(..)
The accepted answer to the below seems close:
https://developer.apple.com/forums/thread/132627
But not quite, so I tried the following mods:
protocol TextModifier {
func body(text: Text) -> Text
}
extension Text {
func modifier<TM: TextModifier>(_ theModifier: TM) -> Text {
return theModifier.body(text: self)
}
}
struct TestModifier: TextModifier {
func body(text: Text) -> Text {
return text.foregroundColor(.orange).font(.largeTitle)
}
}
extension Text {
func mymodifier() -> Text {
modifier(TestModifier())
}
}
// In some view code I can do:
Text("abc").mymodifier() + Text("def").mymodifier()
And the above works fine. The problem that I have though is that in the TestModifier body I need to apply modifiers that return "some View", and then I'm toast as I need that body to return a "Text". In the above I'm only using modifiers that return Text, so all is good, but that's not useful for me.
Is there some way to get back the original Text object after applying modifiers that return "some View"?