StanfordSpezi / SpeziOnboarding

Spezi Onboarding module to inform a user or retrieve consent for a study participation
https://swiftpackageindex.com/StanfordSpezi/SpeziOnboarding/documentation/
MIT License
11 stars 5 forks source link

Unable to add modifiers to icon images in an OnboardingView #27

Closed vishnuravi closed 7 months ago

vishnuravi commented 8 months ago

Description

The OnboardingView allows each area to have an icon, which must be an Image. However, we cannot currently add modifiers such as .foregroundColor() to the icon, which limits the customizability.

Reproduction

Create an OnboardingView and attempt to add a modifier to an icon:

OnboardingView(
   title: "WELCOME_TITLE",
   subtitle: "WELCOME_SUBTITLE",
      areas: [
         .init(
            icon: Image(systemName: "apps.iphone")
                        .foregroundColor(.red),
            title: "WELCOME_AREA1_TITLE",
            description: "WELCOME_AREA1_DESCRIPTION"
          )
        ],
       actionText: "WELCOME_BUTTON",
       action: {
          onboardingNavigationPath.nextStep()
       }
     )

This results in an error: Cannot convert value of type 'some View' to expected argument type 'Image'

Expected behavior

It should be possible to add modifiers to images.

Additional context

No response

Code of Conduct

PSchmiedmayer commented 8 months ago

Thank you for the feedback, agree as discussed in the meeting that this is something that we should improve. I would suggest that we store an AnyView in the content (https://github.com/StanfordSpezi/SpeziOnboarding/blob/main/Sources/SpeziOnboarding/OnboardingInformationView.swift#L37) and make the initializer generic of a View that can be passed in the initializer using a ViewBuilder. This should allow you to pass in any view. Some of the modifiers in the view might need to be adjusted: https://github.com/StanfordSpezi/SpeziOnboarding/blob/main/Sources/SpeziOnboarding/OnboardingInformationView.swift#L96