Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #6859: Ensure valid favicon image sizes are used within fav widgets
Browse files Browse the repository at this point in the history
Also fixes the overlay border not being visible for transparent icons
  • Loading branch information
kylehickinson committed Mar 3, 2023
1 parent 0891c01 commit 99f586b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions App/BraveWidgets/FavoritesWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SwiftUI
import Strings
import BraveShared
import BraveWidgetsModels
import Favicon

struct FavoritesWidget: Widget {
var body: some WidgetConfiguration {
Expand Down Expand Up @@ -127,6 +128,15 @@ private struct FavoritesGridView: View {
return redactionReasons.contains(.placeholder)
}
}

func image(for favicon: Favicon) -> UIImage? {
guard let image = favicon.image else { return nil }
if #available(iOS 15.0, *) {
return image.preparingThumbnail(of: CGSize(width: 128, height: 128))
} else {
return image.scale(toSize: CGSize(width: 128, height: 128))
}
}

var body: some View {
LazyVGrid(columns: Array(repeating: .init(.flexible()), count: 4), spacing: 8) {
Expand All @@ -136,7 +146,7 @@ private struct FavoritesGridView: View {
destination: favorite.url,
label: {
Group {
if let attributes = favorite.favicon, let image = attributes.image {
if let attributes = favorite.favicon, let image = image(for: attributes) {
FaviconImage(image: image, contentMode: .scaleAspectFit, includePadding: false)
.background(Color(attributes.backgroundColor))
} else {
Expand All @@ -153,7 +163,7 @@ private struct FavoritesGridView: View {
.background(Color(UIColor.braveBackground).opacity(0.05).clipShape(itemShape))
.overlay(
itemShape
.strokeBorder(Color(UIColor.braveSeparator).opacity(0.1), lineWidth: pixelLength)
.strokeBorder(Color(UIColor.braveLabel).opacity(0.2), lineWidth: pixelLength)
)
.padding(widgetFamily == .systemMedium ? 4 : 0)
})
Expand Down

0 comments on commit 99f586b

Please sign in to comment.