Skip to content

Commit

Permalink
Tweaked the design and updated examples project
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddevdploeg committed Oct 29, 2023
1 parent 8b7f4dd commit 1c85b37
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Example/BillboardExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct ContentView: View {
List {
if let advert = allAds.randomElement() {
Section {
BillboardBannerView(advert: advert)
BillboardBannerView(advert: advert, hideDismissButtonAndTimer: true)
.listRowBackground(Color.clear)
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
}
Expand Down
17 changes: 11 additions & 6 deletions Sources/Billboard/Views/BillboardBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public struct BillboardBannerView : View {
Button {
if let url = advert.appStoreLink {
openURL(url)
canDismiss = true
}
canDismiss = true
} label: {
HStack(spacing: 10) {
if let appIcon {
Expand Down Expand Up @@ -120,12 +120,17 @@ public struct BillboardBannerView : View {
}
}

@ViewBuilder
var backgroundView : some View {
RoundedRectangle(cornerRadius: 16, style: .continuous)
.fill(advert.background)
.shadow(color: includeShadow ? advert.background.opacity(0.5) : Color.clear,
radius: 6,
x: 0, y: 2)
if #available(iOS 16.0, *) {
RoundedRectangle(cornerRadius: 16, style: .continuous)
.fill(advert.background.gradient)
.shadow(color: includeShadow ? advert.background.opacity(0.5) : Color.clear, radius: 6, x: 0, y: 2)
} else {
RoundedRectangle(cornerRadius: 16, style: .continuous)
.fill(advert.background)
.shadow(color: includeShadow ? advert.background.opacity(0.5) : Color.clear, radius: 6, x: 0, y: 2)
}
}
}

Expand Down
36 changes: 25 additions & 11 deletions Sources/Billboard/Views/BillboardCountdownView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct BillboardCountdownView : View {
@Binding var canDismiss : Bool


@State private var seconds : Int = 15
@State private var seconds : Double = 15
@State private var timerProgress : CGFloat = 0.0

private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
Expand All @@ -26,22 +26,36 @@ struct BillboardCountdownView : View {
Circle()
.trim(from: 0, to: timerProgress)
.stroke(advert.tint, style: StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round))

Text("\(seconds)")
.font(.compatibleSystem(.caption, design: .rounded, weight: .bold)).monospacedDigit()
.rotationEffect(.degrees(90))
.minimumScaleFactor(0.5)
.onReceive(timer) { _ in
if seconds > 0 {
seconds -= 1
if #available(iOS 17.0, *) {
Text("\(seconds, specifier: "%.0f")")
.font(.compatibleSystem(.caption, design: .rounded, weight: .heavy)).monospacedDigit()
.rotationEffect(.degrees(90))
.minimumScaleFactor(0.5)
.animation(.default, value: seconds)
.transition(.identity)
.contentTransition(.numericText(value: seconds))
.onReceive(timer) { _ in
if seconds > 0 {
seconds -= 1
}
}
} else {
Text("\(seconds, specifier: "%.0f")")
.font(.compatibleSystem(.caption, design: .rounded, weight: .bold)).monospacedDigit()
.rotationEffect(.degrees(90))
.minimumScaleFactor(0.5)
.onReceive(timer) { _ in
if seconds > 0 {
seconds -= 1
}
}
}
}
}
.foregroundColor(advert.tint)
.rotationEffect(.degrees(-90))
.frame(width: 32, height: 32)
.onAppear {
seconds = Int(totalDuration)
seconds = totalDuration
withAnimation(.linear(duration: totalDuration)) {
timerProgress = 1.0
}
Expand Down

0 comments on commit 1c85b37

Please sign in to comment.