Skip to content

Commit a9aa9a2

Browse files
committed
fix: Backport vertical animation fix from 5.x
1 parent e3cc1e5 commit a9aa9a2

5 files changed

Lines changed: 65 additions & 33 deletions

File tree

packages/notifications/dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/notifications/resources/css/database-notifications.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
&.fi-modal-window-has-footer .fi-modal-content {
2828
@apply border-b border-gray-200 dark:border-white/10;
2929
}
30+
31+
& .fi-modal-footer {
32+
@apply pt-6;
33+
}
3034
}
3135

3236
& .fi-no-notification-unread-ctn {

packages/notifications/resources/js/components/notification.js

Lines changed: 58 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,15 @@ export default (Alpine) => {
7676
},
7777

7878
configureAnimations() {
79-
let animation
79+
// Inline notifications, such as those in the database
80+
// notifications modal, are removed instantly, without animation.
81+
if (this.$el.classList.contains('fi-inline')) {
82+
return
83+
}
8084

8185
this.unsubscribeLivewireHook = Livewire.hook(
8286
'commit',
83-
({ component, commit, succeed, fail, respond }) => {
87+
({ component, succeed }) => {
8488
if (
8589
!component.snapshot.data
8690
.isFilamentNotificationsComponent
@@ -95,44 +99,54 @@ export default (Alpine) => {
9599
this.$el.getBoundingClientRect().top
96100
const oldTop = getTop()
97101

98-
respond(() => {
99-
animation = () => {
100-
if (!this.isShown) {
101-
return
102-
}
103-
104-
this.$el.animate(
105-
[
102+
succeed(() => {
103+
// `succeed` runs before Livewire morphs the DOM, which it
104+
// defers using two nested `queueMicrotask()` calls, so the
105+
// animation is deferred in the same way to run once the DOM
106+
// has been morphed, before the browser paints, so the new
107+
// position can be measured and the animation started without
108+
// the notification flashing in its final position.
109+
queueMicrotask(() =>
110+
queueMicrotask(() => {
111+
if (!this.isShown) {
112+
return
113+
}
114+
115+
// Finish any running animations so they do not distort
116+
// the measurement of the new position.
117+
this.$el
118+
.getAnimations()
119+
.forEach((animation) =>
120+
animation.finish(),
121+
)
122+
123+
const newTop = getTop()
124+
125+
if (oldTop === newTop) {
126+
return
127+
}
128+
129+
this.$el.animate(
130+
[
131+
{
132+
transform: `translateY(${oldTop - newTop}px)`,
133+
},
134+
{ transform: 'translateY(0px)' },
135+
],
106136
{
107-
transform: `translateY(${
108-
oldTop - getTop()
109-
}px)`,
137+
duration: this.transitionDuration,
138+
easing: this.transitionEasing,
110139
},
111-
{ transform: 'translateY(0px)' },
112-
],
113-
{
114-
duration: this.transitionDuration,
115-
easing: this.transitionEasing,
116-
},
117-
)
118-
}
119-
120-
this.$el
121-
.getAnimations()
122-
.forEach((animation) => animation.finish())
123-
})
124-
125-
succeed(({ snapshot, effect }) => {
126-
animation()
140+
)
141+
}),
142+
)
127143
})
128144
})
129145
},
130146
)
131147
},
132148

133149
close(isImmediate = false) {
134-
this.isShown = false
135-
136150
const dispatchClosedEvent = () =>
137151
window.dispatchEvent(
138152
new CustomEvent('notificationClosed', {
@@ -143,11 +157,24 @@ export default (Alpine) => {
143157
)
144158

145159
if (isImmediate === true) {
160+
this.isShown = false
161+
146162
dispatchClosedEvent()
147163

148164
return
149165
}
150166

167+
// Inline notifications, such as those in the database
168+
// notifications modal, are part of a list, so they are removed
169+
// from it as soon as possible instead of fading out first.
170+
if (this.$root.classList.contains('fi-inline')) {
171+
dispatchClosedEvent()
172+
173+
return
174+
}
175+
176+
this.isShown = false
177+
151178
setTimeout(dispatchClosedEvent, this.transitionDuration)
152179
},
153180

packages/notifications/resources/views/database-notifications.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class="fi-no-database"
7474

7575
@foreach ($notifications as $notification)
7676
<div
77+
wire:key="{{ $notification->getKey() }}.database-notifications.ctn"
7778
@class([
7879
'fi-no-notification-read-ctn' => ! $notification->unread(),
7980
'fi-no-notification-unread-ctn' => $notification->unread(),

packages/panels/dist/theme.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)