Skip to content

Commit

Permalink
Fix iOS widget has a white border mozilla-mobile#4005
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtCC committed Jan 25, 2024
1 parent 29217ca commit cda4837
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public struct CardBannerView: View {
}

var widget: some View {
SearchWidgetView(title: config.widget.title)
SearchWidgetView(title: config.widget.title, background: true)
.frame(width: .searchWidgetSize, height: .searchWidgetSize)
.clipShape(RoundedRectangle(cornerRadius: 20))
.colorScheme(.light)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public struct ShowMeHowOnboardingView: View {
}
HStack {
Spacer()
SearchWidgetView(title: config.widgetText)
SearchWidgetView(title: config.widgetText, background: true)
.frame(width: .searchWidgetSize, height: .searchWidgetSize)
.clipShape(RoundedRectangle(cornerRadius: 20))
.colorScheme(.light)
Expand Down
18 changes: 10 additions & 8 deletions focus-ios/BlockzillaPackage/Sources/Widget/SearchWidgetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import SwiftUI

public struct SearchWidgetView: View {
let title: String
let background: Bool

public init(title: String) {
public init(title: String, background: Bool) {
self.title = title
self.background = background
}

public var body: some View {
Expand All @@ -17,11 +19,11 @@ public struct SearchWidgetView: View {
Text(title)
.font(.headline)
.fontWeight(.medium)
.minimumScaleFactor(0.8)
.foregroundColor(.white)
.minimumScaleFactor(0.8)
.foregroundColor(.white)

Spacer()

Image.magnifyingGlass
.foregroundColor(.white)
.frame(height: .magnifyingGlassHeight)
Expand All @@ -36,20 +38,20 @@ public struct SearchWidgetView: View {
.frame(height: .logoHeight)
}
}
.padding()
.padding(.all, background ? 10 : 0)
.background(
LinearGradient(
background ? LinearGradient(
gradient: .quickAccessWidget,
startPoint: .topLeading,
endPoint: .bottomTrailing)
endPoint: .bottomTrailing) : nil
)
}
}

@available(iOS 14, *)
struct SearchWidgetView_Previews: PreviewProvider {
static var previews: some View {
SearchWidgetView(title: "Search in Focus")
SearchWidgetView(title: "Search in Focus", background: true)
.previewLayout(.sizeThatFits)
.frame(width: 135, height: 135)
.clipShape(RoundedRectangle(cornerRadius: 20))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.796",
"green" : "0.165",
"red" : "0.349"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x33",
"green" : "0x2A",
"red" : "0x2B"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "0.443",
"red" : "0.671"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x33",
"green" : "0x2A",
"red" : "0x2B"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
23 changes: 22 additions & 1 deletion focus-ios/Widgets/Widgets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ struct FocusWidgetsEntryView : View {
var entry: Provider.Entry

var body: some View {
SearchWidgetView(title: String(format: .searchInAppFormat, String.appNameForBundle))
SearchWidgetView(title: String(format: .searchInAppFormat, String.appNameForBundle), background: false)
.widgetURL(.deepLinkURL)
.widgetBackground(backgroundView:
LinearGradient(
gradient: .quickAccessWidget,
startPoint: .topLeading,
endPoint: .bottomTrailing))
}
}

Expand All @@ -57,6 +62,10 @@ struct FocusWidgets_Previews: PreviewProvider {
}
}

fileprivate extension Gradient {
static let quickAccessWidget = Gradient(colors: [Color("GradientFirst"), Color("GradientSecond")])
}

fileprivate extension String {
static var appNameForBundle: String {
var isKlar: Bool { return (Bundle.main.infoDictionary!["CFBundleIdentifier"] as! String).contains("Klar") }
Expand Down Expand Up @@ -88,3 +97,15 @@ fileprivate extension String {
fileprivate extension URL {
static let deepLinkURL: URL = URL(string: "firefox-focus://widget")!
}

fileprivate extension View {
func widgetBackground(backgroundView: some View) -> some View {
if #available(watchOS 10.0, iOSApplicationExtension 17.0, iOS 17.0, macOSApplicationExtension 14.0, *) {
return containerBackground(for: .widget) {
backgroundView
}
} else {
return background(backgroundView)
}
}
}

0 comments on commit cda4837

Please sign in to comment.