修复第一条通知不显示,通知组展开状态下新增通知没有背景色,左滑样式错误的bug

This commit is contained in:
wurou 2022-12-30 10:20:26 +08:00
parent e8319eaca6
commit fe7dfc974f
3 changed files with 38 additions and 9 deletions

View File

@ -80,6 +80,7 @@ export class StarNotificationGroup extends LitElement {
super.connectedCallback() super.connectedCallback()
window.addEventListener('notification-delete', this) window.addEventListener('notification-delete', this)
window.addEventListener('notification-touchmove', this) window.addEventListener('notification-touchmove', this)
window.addEventListener('notification-touchmove-right', this)
window.addEventListener('resize', this.resize) window.addEventListener('resize', this.resize)
// 用于监控自身高度变化, 用于第一时间设置自身高度 // 用于监控自身高度变化, 用于第一时间设置自身高度
@ -143,6 +144,8 @@ export class StarNotificationGroup extends LitElement {
break break
// 左滑通知时,对未闭合操作按钮的其它通知进行闭合 // 左滑通知时,对未闭合操作按钮的其它通知进行闭合
case 'notification-touchmove': case 'notification-touchmove':
this.setAttribute('removeBackground', 'true')
this.style.setProperty('--single-noti-bgc', 'var(--notification-bgc)')
let targetId = (event as any).detail.id let targetId = (event as any).detail.id
if (this.slotElements.length > 1) { if (this.slotElements.length > 1) {
;(this.slotElements as StarNotification[]).forEach( ;(this.slotElements as StarNotification[]).forEach(
@ -154,6 +157,10 @@ export class StarNotificationGroup extends LitElement {
) )
} }
break break
case 'notification-touchmove-right':
this.setAttribute('removeBackground', 'false')
this.style.setProperty('--single-noti-bgc', 'transparent')
break
} }
} }
@ -180,6 +187,7 @@ export class StarNotificationGroup extends LitElement {
'group-with-one-notification' 'group-with-one-notification'
) )
this.show = false this.show = false
this.contentOpacity = 1
firstChild.withArrowUp = false firstChild.withArrowUp = false
firstChild.removeEventListener('notification-tap', allNotificationshown) firstChild.removeEventListener('notification-tap', allNotificationshown)
} else if (slotLen > 1) { } else if (slotLen > 1) {
@ -187,11 +195,13 @@ export class StarNotificationGroup extends LitElement {
if (this.show) { if (this.show) {
// 展开 // 展开
this.addGroupHeight(this._singleHeight * this.slotElements.length)
firstChild.setAttribute('radiusType', 'top-border-radius') firstChild.setAttribute('radiusType', 'top-border-radius')
firstChild.setAttribute('notificationType', 'more-notifiactions') firstChild.setAttribute('notificationType', 'more-notifiactions')
firstChild.withArrowUp = true firstChild.withArrowUp = true
} else { } else {
// 折叠 // 折叠
this.addGroupHeight(0)
firstChild.setAttribute('radiusType', 'border-radius') firstChild.setAttribute('radiusType', 'border-radius')
firstChild.setAttribute( firstChild.setAttribute(
'notificationType', 'notificationType',
@ -237,7 +247,6 @@ export class StarNotificationGroup extends LitElement {
} }
allNotificationshown(event: Event) { allNotificationshown(event: Event) {
console.log('allNotificationshown')
let firstChild = this.slotElements[0] as StarNotification let firstChild = this.slotElements[0] as StarNotification
if (firstChild !== event.target || this.slotElements.length == 1) { if (firstChild !== event.target || this.slotElements.length == 1) {
return return
@ -250,7 +259,6 @@ export class StarNotificationGroup extends LitElement {
} }
let isShow = this.show let isShow = this.show
console.log('hellowq allNotificationshown isShow: ', isShow)
if (isShow) { if (isShow) {
// 当前是展开状态,点击需折叠 // 当前是展开状态,点击需折叠
let self = this let self = this
@ -358,6 +366,10 @@ export class StarNotificationGroup extends LitElement {
--single-noti-bgc: transparent; --single-noti-bgc: transparent;
} }
:host([removeBackground='true']) {
background: unset !important;
}
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
:host { :host {
--notification-bgc: var(--opacity-black-25); --notification-bgc: var(--opacity-black-25);

View File

@ -122,13 +122,11 @@ export class StarNotification extends StarBaseElement {
render(): HTMLTemplateResult | typeof nothing { render(): HTMLTemplateResult | typeof nothing {
switch (this.notificationType) { switch (this.notificationType) {
case NotificationType.ONE: case NotificationType.ONE:
case NotificationType.MORE:
case NotificationType.GROUP_ONE: case NotificationType.GROUP_ONE:
return this.getone() return this.getone()
case NotificationType.MORE:
case NotificationType.MORE_FIRST: case NotificationType.MORE_FIRST:
return html` return this.getmorefirst()
${this.getmorefirst()} ${this.getone()}
`
case NotificationType.BLUETOOTH_TRANSFER: case NotificationType.BLUETOOTH_TRANSFER:
return this.getbluetoothtransfer() return this.getbluetoothtransfer()
default: default:
@ -391,6 +389,7 @@ export class StarNotification extends StarBaseElement {
event.preventDefault() event.preventDefault()
break break
case 'swipeleft': case 'swipeleft':
event.stopPropagation()
this.touchAction.last.clientX = event.detail.endTouch.clientX this.touchAction.last.clientX = event.detail.endTouch.clientX
let touchPosX = let touchPosX =
this.touchAction.last.clientX - this.touchAction.start.clientX this.touchAction.last.clientX - this.touchAction.start.clientX
@ -456,6 +455,7 @@ export class StarNotification extends StarBaseElement {
break break
case 'swiperight': case 'swiperight':
event.preventDefault() event.preventDefault()
event.stopPropagation()
this.notification.style.transform = 'translateX(' + 0 + 'px)' this.notification.style.transform = 'translateX(' + 0 + 'px)'
let tranEnd = () => { let tranEnd = () => {
this.notification.removeEventListener('transitionend', tranEnd) this.notification.removeEventListener('transitionend', tranEnd)
@ -467,6 +467,16 @@ export class StarNotification extends StarBaseElement {
} }
this.notification.addEventListener('transitionend', tranEnd) this.notification.addEventListener('transitionend', tranEnd)
this.moveDirection = 'right' this.moveDirection = 'right'
this.dispatchEvent(
new CustomEvent('notification-touchmove-right', {
detail: {
id: this.id,
direction: this.moveDirection,
},
bubbles: true,
composed: true,
})
)
break break
case 'click': case 'click':
event.stopPropagation() event.stopPropagation()

View File

@ -113,6 +113,7 @@ export const sharedStyles: CSSResult = css`
} }
.notification > div.title-container .title { .notification > div.title-container .title {
overflow: hidden;
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; text-overflow: ellipsis;
flex: none; flex: none;
@ -127,6 +128,7 @@ export const sharedStyles: CSSResult = css`
line-height: 1; line-height: 1;
// font-size: 2.3vw; // font-size: 2.3vw;
font-size: var(--auto-28px); font-size: var(--auto-28px);
max-width: var(--auto-640px);
} }
.notification > div.title-container .timestamp { .notification > div.title-container .timestamp {
@ -181,7 +183,7 @@ export const sharedStyles: CSSResult = css`
// font-size: 2.2vw; // font-size: 2.2vw;
font-size: var(--auto-26px); font-size: var(--auto-26px);
max-width: var(--auro-640px); max-width: var(--auto-640px);
// width: 246px; // width: 246px;
// height: 11px; // height: 11px;
// font-size: 8px; // font-size: 8px;
@ -337,12 +339,17 @@ export const sharedStyles: CSSResult = css`
// line-height: 28px; // line-height: 28px;
// font-size: 28px; // font-size: 28px;
height: 18.4%; // height: 18.4%;
line-height: 1; // line-height: 1;
// font-size: 1.45vh; // font-size: 1.45vh;
// font-size: 2.3vw; // font-size: 2.3vw;
font-size: var(--auto-28px); font-size: var(--auto-28px);
line-height: var(--auto-38px); line-height: var(--auto-38px);
height: var(--auto-38px);
max-width: 40%;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
} }
/* 打开通知组动画过程中时 */ /* 打开通知组动画过程中时 */