Add the possibility to add a View instead of just a text to WhatsNew.Title #7

Open
opened 2025-10-14 15:54:30 -06:00 by navan · 0 comments
Owner

Originally created by @velco-greg on 1/22/2025

It's only possible to pass a text/localized Text to the title.
It would be great to pass a View, that way a combo Text + Image content could be presented on top of the feature List.

What solution would you like?

Having a new constructor with a Content in parameter instead of title, where Content is a View
Something like that:

init(
        version: Version = .current(),
        topContent: @escaping () -> Content,
        features: [Feature],
        primaryAction: PrimaryAction = .init(),
        secondaryAction: SecondaryAction? = nil
    )

It would make that great framework more flexible in terms of customization (even if I imagine that you want to stick to Apple design).

What alternatives have you considered?

Title could accept an optional Image with the actual Text, and it could be displayed in a VStack.

struct Title: Hashable {
        // MARK: Properties
        
        /// The title Text
        public var text: Text

        public var image: Image?
        
        /// The foreground color
        public var foregroundColor: Color
        
        // MARK: Initializer
        
        /// Creates a new instance of `WhatsNew.Title`
        /// - Parameters:
        ///   - text: The title Text
        ///   - foregroundColor: The foreground color. Default value `.primary`
        public init(
            text: Text,
            image: Image? = nil,
            foregroundColor: Color = .primary
        ) {
            self.text = text
            self.image = image
            self.foregroundColor = foregroundColor
        }

Then in WhatsNewView :

private extension WhatsNewView {
    
    /// The Title View
    var title: some View {
        VStack {
             self.whatsnew.title.image.view()
             Text(
            whatsNewText: self.whatsNew.title.text
        )
        .font(.largeTitle.bold())
        .multilineTextAlignment(.center)
        .fixedSize(horizontal: false, vertical: true)
        }
    }
    
}

Any additional context?

No response

*Originally created by @velco-greg on 1/22/2025* ### Is your feature request related to a problem? It's only possible to pass a text/localized Text to the title. It would be great to pass a View, that way a combo Text + Image content could be presented on top of the feature List. ### What solution would you like? Having a new constructor with a Content in parameter instead of title, where Content is a View Something like that: ``` init( version: Version = .current(), topContent: @escaping () -> Content, features: [Feature], primaryAction: PrimaryAction = .init(), secondaryAction: SecondaryAction? = nil ) ``` It would make that great framework more flexible in terms of customization (even if I imagine that you want to stick to Apple design). ### What alternatives have you considered? Title could accept an optional Image with the actual Text, and it could be displayed in a VStack. ``` struct Title: Hashable { // MARK: Properties /// The title Text public var text: Text public var image: Image? /// The foreground color public var foregroundColor: Color // MARK: Initializer /// Creates a new instance of `WhatsNew.Title` /// - Parameters: /// - text: The title Text /// - foregroundColor: The foreground color. Default value `.primary` public init( text: Text, image: Image? = nil, foregroundColor: Color = .primary ) { self.text = text self.image = image self.foregroundColor = foregroundColor } ``` Then in WhatsNewView : ``` private extension WhatsNewView { /// The Title View var title: some View { VStack { self.whatsnew.title.image.view() Text( whatsNewText: self.whatsNew.title.text ) .font(.largeTitle.bold()) .multilineTextAlignment(.center) .fixedSize(horizontal: false, vertical: true) } } } ``` ### Any additional context? _No response_
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github/WhatsNewKit#7
No description provided.