Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use custom label for CompatibilityContentUnavailableView #4647

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,22 @@ struct CompatibilityContentUnavailableView: View {
if #available(iOS 17.0, *) {
#if swift(>=5.9)
if let description {
ContentUnavailableView(
title,
systemImage: systemImage,
description: description
)
ContentUnavailableView {
Label {
titleView
} icon: {
iconView
}
}
description: { description }
} else {
ContentUnavailableView(
title,
systemImage: systemImage
)
ContentUnavailableView {
Label {
titleView
} icon: {
iconView
}
}
Copy link
Member

@ajpallares ajpallares Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious 🤔. Would it be possible to remove the if let description and keep only this?

ContentUnavailableView {
    Label {
        titleView
    } icon: {
        iconView
    }
}
description: { description }

I don't know if nil would have the same effect as EmptyView() (which is the default value for the description parameter when the parameter is not included)

}

#else
Expand All @@ -60,16 +66,8 @@ struct CompatibilityContentUnavailableView: View {
#endif
} else {
VStack {
Image(systemName: systemImage)
.resizable()
.scaledToFill()
.frame(width: 48, height: 48)
.foregroundStyle(.secondary)
.padding()

Text(title)
.font(.title2)
.bold()
iconView
titleView

if let description {
description
Expand All @@ -80,6 +78,22 @@ struct CompatibilityContentUnavailableView: View {
}

}

private var titleView: some View {
Text(title)
.font(.title2)
.bold()
.fixedSize(horizontal: false, vertical: true)
}

private var iconView: some View {
Image(systemName: systemImage)
.resizable()
.scaledToFill()
.frame(width: 48, height: 48)
.foregroundStyle(.secondary)
.padding()
}
}

#endif