This commit is contained in:
Isaac 2025-12-30 21:18:43 +08:00
parent 38053570c9
commit 79142834fb
3 changed files with 34 additions and 22 deletions

View file

@ -1121,6 +1121,9 @@ public final class ChatListHeaderComponent: Component {
if rightButtonsEffectiveWidth != 0.0 {
let rightButtonsBackgroundContainer: GlassBackgroundView
var rightButtonsBackgroundContainerTransition = transition
let rightButtonsContainerFrame = CGRect(origin: CGPoint(x: availableSize.width - component.sideInset - max(44.0, rightButtonsEffectiveWidth), y: 0.0), size: CGSize(width: max(44.0, rightButtonsEffectiveWidth), height: 44.0))
if let current = self.rightButtonsBackgroundContainer {
rightButtonsBackgroundContainer = current
} else {
@ -1129,15 +1132,18 @@ public final class ChatListHeaderComponent: Component {
self.rightButtonsBackgroundContainer = rightButtonsBackgroundContainer
self.addSubview(rightButtonsBackgroundContainer)
rightButtonsBackgroundContainer.contentView.addSubview(self.rightButtonsContainer)
rightButtonsBackgroundContainer.update(size: rightButtonsContainerFrame.size, cornerRadius: rightButtonsContainerFrame.height * 0.5, isDark: component.theme.overallDarkAppearance, tintColor: .init(kind: .panel, color: UIColor(white: component.theme.overallDarkAppearance ? 0.0 : 1.0, alpha: 0.6)), isInteractive: true, isVisible: false, transition: .immediate)
}
let rightButtonsContainerFrame = CGRect(origin: CGPoint(x: availableSize.width - component.sideInset - max(44.0, rightButtonsEffectiveWidth), y: 0.0), size: CGSize(width: max(44.0, rightButtonsEffectiveWidth), height: 44.0))
rightButtonsBackgroundContainerTransition.setFrame(view: rightButtonsBackgroundContainer, frame: rightButtonsContainerFrame)
rightButtonsBackgroundContainer.update(size: rightButtonsContainerFrame.size, cornerRadius: rightButtonsContainerFrame.height * 0.5, isDark: component.theme.overallDarkAppearance, tintColor: .init(kind: .panel, color: UIColor(white: component.theme.overallDarkAppearance ? 0.0 : 1.0, alpha: 0.6)), isInteractive: true, transition: rightButtonsBackgroundContainerTransition)
rightButtonsBackgroundContainerTransition.setFrame(view: self.rightButtonsContainer, frame: CGRect(origin: CGPoint(), size: rightButtonsContainerFrame.size))
rightButtonsBackgroundContainer.update(size: rightButtonsContainerFrame.size, cornerRadius: rightButtonsContainerFrame.height * 0.5, isDark: component.theme.overallDarkAppearance, tintColor: .init(kind: .panel, color: UIColor(white: component.theme.overallDarkAppearance ? 0.0 : 1.0, alpha: 0.6)), isInteractive: true, transition: transition)
rightButtonsBackgroundContainerTransition.setFrame(view: self.rightButtonsContainer, frame: CGRect(origin: CGPoint(), size: rightButtonsContainerFrame.size))
} else {
if let rightButtonsBackgroundContainer = self.rightButtonsBackgroundContainer {
self.rightButtonsBackgroundContainer = nil
transition.setAlpha(view: rightButtonsBackgroundContainer, alpha: 0.0, completion: { [weak rightButtonsBackgroundContainer] _ in
rightButtonsBackgroundContainer.update(size: rightButtonsBackgroundContainer.bounds.size, cornerRadius: rightButtonsBackgroundContainer.bounds.height * 0.5, isDark: component.theme.overallDarkAppearance, tintColor: .init(kind: .panel, color: UIColor(white: component.theme.overallDarkAppearance ? 0.0 : 1.0, alpha: 0.6)), isInteractive: true, isVisible: false, transition: transition)
transition.attachAnimation(view: rightButtonsBackgroundContainer, id: "remove", completion: { [weak rightButtonsBackgroundContainer] _ in
rightButtonsBackgroundContainer?.removeFromSuperview()
})
}

View file

@ -434,6 +434,7 @@ public class GlassBackgroundView: UIView {
legacyView.update(size: size, cornerRadius: cornerRadius, transition: transition)
}
transition.setFrame(view: legacyView, frame: CGRect(origin: CGPoint(), size: size))
transition.setAlpha(view: legacyView, alpha: isVisible ? 1.0 : 0.0)
}
let shadowInset: CGFloat = 32.0
@ -500,6 +501,7 @@ public class GlassBackgroundView: UIView {
context.setBlendMode(.copy)
context.fillEllipse(in: CGRect(origin: CGPoint(x: shadowInset + shadowInnerInset, y: shadowInset + shadowInnerInset), size: CGSize(width: size.width - shadowInset * 2.0 - shadowInnerInset * 2.0, height: size.height - shadowInset * 2.0 - shadowInnerInset * 2.0)))
})?.stretchableImage(withLeftCapWidth: Int(shadowInset + outerCornerRadius), topCapHeight: Int(shadowInset + outerCornerRadius))
transition.setAlpha(view: shadowView, alpha: isVisible ? 1.0 : 0.0)
}
if let foregroundView = self.foregroundView {
@ -515,6 +517,7 @@ public class GlassBackgroundView: UIView {
fillColor = tintColor.color
}
foregroundView.image = GlassBackgroundView.generateLegacyGlassImage(size: CGSize(width: outerCornerRadius * 2.0, height: outerCornerRadius * 2.0), inset: shadowInset, isDark: isDark, fillColor: fillColor)
transition.setAlpha(view: foregroundView, alpha: isVisible ? 1.0 : 0.0)
} else {
if let nativeParamsView = self.nativeParamsView, let nativeView = self.nativeView {
if #available(iOS 26.0, *) {
@ -536,21 +539,15 @@ public class GlassBackgroundView: UIView {
glassEffect = glassEffectValue
}
if glassEffect == nil && nativeView.effect != nil {
if transition.animation.isImmediate {
if #available(iOS 26.2, *) {
if glassEffect == nil {
if nativeView.effect is UIGlassEffect {
if transition.animation.isImmediate {
nativeView.effect = nil
} else {
nativeView.effect = UIBlurEffect(style: .regular)
}
nativeView.effect = glassEffect
} else {
UIView.animate(withDuration: 0.2, animations: {
if #available(iOS 26.2, *) {
} else {
nativeView.effect = UIBlurEffect(style: .regular)
UIView.animate {
nativeView.effect = nil
}
nativeView.effect = glassEffect
})
}
}
} else {
if transition.animation.isImmediate {
@ -558,9 +555,9 @@ public class GlassBackgroundView: UIView {
} else {
if let glassEffect, let currentEffect = nativeView.effect as? UIGlassEffect, currentEffect.tintColor == glassEffect.tintColor, currentEffect.isInteractive == glassEffect.isInteractive {
} else {
UIView.animate(withDuration: 0.15, animations: {
UIView.animate {
nativeView.effect = glassEffect
})
}
}
}
}

View file

@ -52,11 +52,20 @@ private func calculateWallpaperBrightness(from colors: [UInt32]) -> CGFloat {
}
private func calculateWallpaperBrightness(from image: UIImage) -> CGFloat {
let targetSize = CGSize(width: 10.0, height: 10.0)
guard let cgImage = image.cgImage else {
return 1.0
}
let sourceWidth = cgImage.width
let sourceHeight = cgImage.height
let topRegionHeight = max(1, Int(CGFloat(sourceHeight) * 0.1))
let cropRect = CGRect(x: 0, y: 0, width: sourceWidth, height: topRegionHeight)
guard let croppedImage = cgImage.cropping(to: cropRect) else {
return 1.0
}
let targetSize = CGSize(width: 10.0, height: 10.0)
let width = Int(targetSize.width)
let height = Int(targetSize.height)
let bytesPerPixel = 4
@ -77,12 +86,12 @@ private func calculateWallpaperBrightness(from image: UIImage) -> CGFloat {
return 1.0
}
context.draw(cgImage, in: CGRect(origin: .zero, size: targetSize))
context.draw(croppedImage, in: CGRect(origin: .zero, size: targetSize))
var totalLuminance: CGFloat = 0.0
let pixelCount = width * height
for i in 0..<pixelCount {
for i in 0 ..< pixelCount {
let offset = i * bytesPerPixel
let r = CGFloat(pixelData[offset]) / 255.0
let g = CGFloat(pixelData[offset + 1]) / 255.0