Skip to content

Commit b1f0d41

Browse files
Merge pull request #18 from quassum/fix-background-color-artifact
Fixed background color artifact
2 parents 0a1d5a6 + e77f72e commit b1f0d41

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

Sources/SwiftUITooltip/TooltipModifier.swift

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,13 @@ struct TooltipModifier<TooltipContent: View>: ViewModifier {
129129
return ArrowShape()
130130
.rotation(Angle(radians: self.arrowRotation))
131131
.stroke(self.config.borderColor)
132-
.background(ArrowShape().rotation(Angle(radians: self.arrowRotation)).foregroundColor(self.config.backgroundColor))
133-
.frame(width: self.config.arrowWidth, height: self.config.arrowHeight)
132+
.background(ArrowShape()
133+
.offset(x: 0, y: 1)
134+
.rotation(Angle(radians: self.arrowRotation))
135+
.frame(width: self.config.arrowWidth+2, height: self.config.arrowHeight+1)
136+
.foregroundColor(self.config.backgroundColor)
137+
138+
).frame(width: self.config.arrowWidth, height: self.config.arrowHeight)
134139
.offset(x: self.arrowOffsetX, y: self.arrowOffsetY)
135140
}
136141

@@ -158,23 +163,13 @@ struct TooltipModifier<TooltipContent: View>: ViewModifier {
158163
var tooltipBody: some View {
159164
GeometryReader { g in
160165
ZStack {
161-
162-
Rectangle()
163-
.frame(
164-
width: self.config.arrowWidth,
165-
height: self.config.borderWidth)
166-
.rotationEffect(Angle(radians: self.arrowRotation))
167-
.offset(
168-
x: self.arrowOffsetX,
169-
y: self.contentHeight/2)
170-
.foregroundColor(self.config.backgroundColor)
171-
172166
RoundedRectangle(cornerRadius: self.config.borderRadius)
173167
.stroke(self.config.borderWidth == 0 ? Color.clear : self.config.borderColor)
174168
.background(RoundedRectangle(cornerRadius: self.config.borderRadius)
175169
.foregroundColor(self.config.backgroundColor))
176170
.frame(width: self.contentWidth, height: self.contentHeight)
177171
.mask(self.arrowCutoutMask)
172+
178173
ZStack {
179174
content
180175
.padding(self.config.contentPaddingEdgeInsets)
@@ -201,11 +196,14 @@ struct TooltipModifier<TooltipContent: View>: ViewModifier {
201196

202197
struct Tooltip_Previews: PreviewProvider {
203198
static var previews: some View {
204-
VStack {
205-
Text("Say something nice...")
206-
.tooltip(.top, config: DefaultTooltipConfig()) {
199+
var config = DefaultTooltipConfig(side: .top)
200+
config.backgroundColor = Color(red: 0.8, green: 0.9, blue: 1)
201+
202+
203+
return VStack {
204+
Text("Say...").tooltip(config: config) {
207205
Text("Something nice!")
208206
}
209-
}
207+
}.previewDevice(.init(stringLiteral: "iPhone 12 mini"))
210208
}
211209
}

0 commit comments

Comments
 (0)