Skip to content

Commit

Permalink
Merge pull request #18 from quassum/fix-background-color-artifact
Browse files Browse the repository at this point in the history
Fixed background color artifact
  • Loading branch information
bring-shrubbery authored Mar 21, 2022
2 parents 0a1d5a6 + e77f72e commit b1f0d41
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions Sources/SwiftUITooltip/TooltipModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,13 @@ struct TooltipModifier<TooltipContent: View>: ViewModifier {
return ArrowShape()
.rotation(Angle(radians: self.arrowRotation))
.stroke(self.config.borderColor)
.background(ArrowShape().rotation(Angle(radians: self.arrowRotation)).foregroundColor(self.config.backgroundColor))
.frame(width: self.config.arrowWidth, height: self.config.arrowHeight)
.background(ArrowShape()
.offset(x: 0, y: 1)
.rotation(Angle(radians: self.arrowRotation))
.frame(width: self.config.arrowWidth+2, height: self.config.arrowHeight+1)
.foregroundColor(self.config.backgroundColor)

).frame(width: self.config.arrowWidth, height: self.config.arrowHeight)
.offset(x: self.arrowOffsetX, y: self.arrowOffsetY)
}

Expand Down Expand Up @@ -158,23 +163,13 @@ struct TooltipModifier<TooltipContent: View>: ViewModifier {
var tooltipBody: some View {
GeometryReader { g in
ZStack {

Rectangle()
.frame(
width: self.config.arrowWidth,
height: self.config.borderWidth)
.rotationEffect(Angle(radians: self.arrowRotation))
.offset(
x: self.arrowOffsetX,
y: self.contentHeight/2)
.foregroundColor(self.config.backgroundColor)

RoundedRectangle(cornerRadius: self.config.borderRadius)
.stroke(self.config.borderWidth == 0 ? Color.clear : self.config.borderColor)
.background(RoundedRectangle(cornerRadius: self.config.borderRadius)
.foregroundColor(self.config.backgroundColor))
.frame(width: self.contentWidth, height: self.contentHeight)
.mask(self.arrowCutoutMask)

ZStack {
content
.padding(self.config.contentPaddingEdgeInsets)
Expand All @@ -201,11 +196,14 @@ struct TooltipModifier<TooltipContent: View>: ViewModifier {

struct Tooltip_Previews: PreviewProvider {
static var previews: some View {
VStack {
Text("Say something nice...")
.tooltip(.top, config: DefaultTooltipConfig()) {
var config = DefaultTooltipConfig(side: .top)
config.backgroundColor = Color(red: 0.8, green: 0.9, blue: 1)


return VStack {
Text("Say...").tooltip(config: config) {
Text("Something nice!")
}
}
}.previewDevice(.init(stringLiteral: "iPhone 12 mini"))
}
}

0 comments on commit b1f0d41

Please sign in to comment.