Skip to content

Commit 2051e64

Browse files
committed
Display widget animation when it's hidden
1 parent 58e90f0 commit 2051e64

2 files changed

Lines changed: 60 additions & 51 deletions

File tree

Core/Sources/SuggestionWidget/WidgetPositionStrategy.swift

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,24 @@ enum UpdateLocationStrategy {
102102
mainScreen.frame.height - editorFrame.minY - Style.widgetHeight - Style
103103
.widgetPadding
104104
)
105-
106-
let proposedAnchorFrameOnTheRightSide = {
107-
if hideCircularWidget {
108-
return CGRect(
109-
x: editorFrame.maxX,
110-
y: y,
111-
width: 0,
112-
height: 0
113-
)
114-
} else {
115-
return CGRect(
116-
x: editorFrame.maxX - Style.widgetPadding - Style.widgetWidth,
117-
y: y,
118-
width: Style.widgetWidth,
119-
height: Style.widgetHeight
120-
)
121-
}
122-
}()
105+
106+
var proposedAnchorFrameOnTheRightSide = CGRect(
107+
x: editorFrame.maxX,
108+
y: y,
109+
width: 0,
110+
height: 0
111+
)
112+
113+
let widgetFrameOnTheRightSide = CGRect(
114+
x: editorFrame.maxX - Style.widgetPadding - Style.widgetWidth,
115+
y: y,
116+
width: Style.widgetWidth,
117+
height: Style.widgetHeight
118+
)
119+
120+
if !hideCircularWidget {
121+
proposedAnchorFrameOnTheRightSide = widgetFrameOnTheRightSide
122+
}
123123

124124
let proposedPanelX = proposedAnchorFrameOnTheRightSide.maxX + Style
125125
.widgetPadding * 2
@@ -148,7 +148,7 @@ enum UpdateLocationStrategy {
148148
)
149149

150150
return .init(
151-
widgetFrame: anchorFrame,
151+
widgetFrame: widgetFrameOnTheRightSide,
152152
tabFrame: tabFrame,
153153
defaultPanelLocation: .init(
154154
frame: panelFrame,
@@ -157,23 +157,24 @@ enum UpdateLocationStrategy {
157157
suggestionPanelLocation: nil
158158
)
159159
} else {
160-
let proposedAnchorFrameOnTheLeftSide = {
161-
if hideCircularWidget {
162-
return CGRect(
163-
x: editorFrame.minX,
164-
y: proposedAnchorFrameOnTheRightSide.origin.y,
165-
width: 0,
166-
height: 0
167-
)
168-
} else {
169-
return CGRect(
170-
x: editorFrame.minX + Style.widgetPadding,
171-
y: proposedAnchorFrameOnTheRightSide.origin.y,
172-
width: Style.widgetWidth,
173-
height: Style.widgetHeight
174-
)
175-
}
176-
}()
160+
var proposedAnchorFrameOnTheLeftSide = CGRect(
161+
x: editorFrame.minX,
162+
y: proposedAnchorFrameOnTheRightSide.origin.y,
163+
width: 0,
164+
height: 0
165+
)
166+
167+
let widgetFrameOnTheLeftSide = CGRect(
168+
x: editorFrame.minX + Style.widgetPadding,
169+
y: proposedAnchorFrameOnTheRightSide.origin.y,
170+
width: Style.widgetWidth,
171+
height: Style.widgetHeight
172+
)
173+
174+
if !hideCircularWidget {
175+
proposedAnchorFrameOnTheLeftSide = widgetFrameOnTheLeftSide
176+
}
177+
177178
let proposedPanelX = proposedAnchorFrameOnTheLeftSide.minX - Style
178179
.widgetPadding * 2 - Style.panelWidth
179180
let putAnchorToTheLeft = {
@@ -204,7 +205,7 @@ enum UpdateLocationStrategy {
204205
height: Style.widgetHeight
205206
)
206207
return .init(
207-
widgetFrame: anchorFrame,
208+
widgetFrame: widgetFrameOnTheLeftSide,
208209
tabFrame: tabFrame,
209210
defaultPanelLocation: .init(
210211
frame: panelFrame,
@@ -229,7 +230,7 @@ enum UpdateLocationStrategy {
229230
height: Style.widgetHeight
230231
)
231232
return .init(
232-
widgetFrame: anchorFrame,
233+
widgetFrame: widgetFrameOnTheRightSide,
233234
tabFrame: tabFrame,
234235
defaultPanelLocation: .init(
235236
frame: panelFrame,

Core/Sources/SuggestionWidget/WidgetView.swift

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,31 @@ struct WidgetView: View {
1010
@State var isHovering: Bool = false
1111
var onOpenChatClicked: () -> Void = {}
1212
var onCustomCommandClicked: (CustomCommand) -> Void = { _ in }
13+
14+
@AppStorage(\.hideCircularWidget) var hideCircularWidget
1315

1416
var body: some View {
15-
Circle()
16-
.fill(isHovering ? .white.opacity(0.8) : .white.opacity(0.3))
17-
.onTapGesture {
18-
withAnimation(.easeInOut(duration: 0.2)) {
19-
store.send(.widgetClicked)
17+
WithViewStore(store, observe: { $0.isProcessing }) { viewStore in
18+
Circle()
19+
.fill(isHovering ? .white.opacity(0.8) : .white.opacity(0.3))
20+
.onTapGesture {
21+
withAnimation(.easeInOut(duration: 0.2)) {
22+
store.send(.widgetClicked)
23+
}
2024
}
21-
}
22-
.overlay { overlayCircle }
23-
.onHover { yes in
24-
withAnimation(.easeInOut(duration: 0.2)) {
25-
isHovering = yes
25+
.overlay { overlayCircle }
26+
.onHover { yes in
27+
withAnimation(.easeInOut(duration: 0.2)) {
28+
isHovering = yes
29+
}
30+
}.contextMenu {
31+
WidgetContextMenu(store: store)
2632
}
27-
}.contextMenu {
28-
WidgetContextMenu(store: store)
29-
}
33+
.opacity({
34+
if !hideCircularWidget { return 1 }
35+
return viewStore.state ? 1 : 0
36+
}())
37+
}
3038
}
3139

3240
struct OverlayCircleState: Equatable {

0 commit comments

Comments
 (0)