Merge commit 'bd782b04029d65fb9802880c142157717a2f0cae'

This commit is contained in:
Ali 2023-04-13 17:02:07 +04:00
commit 76a78d3fb0
17 changed files with 292 additions and 57 deletions

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina6_7" orientation="portrait" appearance="light"/>
<device id="ipad12_9" orientation="landscape" layout="fullscreen" appearance="dark"/>
<dependencies>
<deployment version="4096" identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@ -10,7 +11,7 @@
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="O8c-13-3vw">
<rect key="frame" x="0.0" y="0.0" width="428" height="926"/>
<rect key="frame" x="0.0" y="0.0" width="1366" height="1024"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<point key="canvasLocation" x="139" y="117"/>

View File

@ -437,10 +437,22 @@ public extension UIImage {
}
}
private func makeSubtreeSnapshot(layer: CALayer, keepTransform: Bool = false) -> UIView? {
private func makeSubtreeSnapshot(layer: CALayer, keepPortals: Bool = false, keepTransform: Bool = false) -> UIView? {
if layer is AVSampleBufferDisplayLayer {
return nil
}
if keepPortals && layer.description.contains("PortalLayer") {
let sourceView = (layer.delegate as? UIView)?.value(forKey: "sourceView") as? UIView
if let snapshotView = sourceView?.snapshotContentTree() {
let globalFrame = layer.convert(layer.bounds, to: sourceView?.layer)
snapshotView.frame = CGRect(origin: CGPoint(x: -globalFrame.minX, y: -globalFrame.minY), size: snapshotView.frame.size)
snapshotView.alpha = 1.0
snapshotView.tag = 0xbeef
return snapshotView
} else {
return nil
}
}
let view = UIView()
view.layer.isHidden = layer.isHidden
view.layer.opacity = layer.opacity
@ -475,21 +487,23 @@ private func makeSubtreeSnapshot(layer: CALayer, keepTransform: Bool = false) ->
view.layer.backgroundColor = layer.backgroundColor
if let sublayers = layer.sublayers {
for sublayer in sublayers {
let subtree = makeSubtreeSnapshot(layer: sublayer, keepTransform: keepTransform)
let subtree = makeSubtreeSnapshot(layer: sublayer, keepPortals: keepPortals, keepTransform: keepTransform)
if let subtree = subtree {
if keepTransform {
subtree.layer.transform = sublayer.transform
}
if subtree.tag != 0xbeef {
subtree.layer.transform = sublayer.transform
subtree.layer.position = sublayer.position
subtree.layer.bounds = sublayer.bounds
subtree.layer.anchorPoint = sublayer.anchorPoint
subtree.layer.layerTintColor = sublayer.layerTintColor
}
if let maskLayer = subtree.layer.mask {
maskLayer.transform = sublayer.transform
maskLayer.position = sublayer.position
maskLayer.bounds = sublayer.bounds
maskLayer.anchorPoint = sublayer.anchorPoint
// maskLayer.transform = sublayer.transform
// maskLayer.position = sublayer.position
// maskLayer.bounds = sublayer.bounds
// maskLayer.anchorPoint = sublayer.anchorPoint
maskLayer.layerTintColor = sublayer.layerTintColor
}
view.addSubview(subtree)
@ -685,12 +699,12 @@ private func makeLayerSubtreeSnapshotAsView(layer: CALayer) -> UIView? {
public extension UIView {
func snapshotContentTree(unhide: Bool = false, keepTransform: Bool = false) -> UIView? {
func snapshotContentTree(unhide: Bool = false, keepPortals: Bool = false, keepTransform: Bool = false) -> UIView? {
let wasHidden = self.isHidden
if unhide && wasHidden {
self.isHidden = false
}
let snapshot = makeSubtreeSnapshot(layer: self.layer, keepTransform: keepTransform)
let snapshot = makeSubtreeSnapshot(layer: self.layer, keepPortals: keepPortals, keepTransform: keepTransform)
if unhide && wasHidden {
self.isHidden = true
}

View File

@ -169,7 +169,7 @@ const CGFloat TGPhotoEditorToolbarSize = 49.0f;
_upperTransitionView.alpha = 0.0;
_upperTransitionView.frame = [parentView convertRect:referenceFrame toView:self.view];
_upperTransitionTargetFrame = [self _targetFrameForTransitionInFromFrame:referenceFrame];
[self.view insertSubview:_upperTransitionView atIndex:0];
[self.view insertSubview:_upperTransitionView atIndex:2];
}
}
@ -219,9 +219,14 @@ const CGFloat TGPhotoEditorToolbarSize = 49.0f;
}
[self _finishedTransitionInWithView:transitionView];
[UIView animateWithDuration:0.2 animations:^{
_upperTransitionView.alpha = 0.0;
} completion:^(BOOL finished) {
[_upperTransitionView removeFromSuperview];
_upperTransitionView = nil;
}];
}];
}
- (void)prepareForCustomTransitionOut

View File

@ -2030,7 +2030,6 @@ public func wallpaperMediaPickerController(
return nil
})
controller.animateAppearance = animateAppearance
//controller.supportedOrientations = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .portrait)
controller.requestController = { [weak controller] _, present in
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
let mediaPickerController = MediaPickerScreen(context: context, peer: nil, threadTitle: nil, chatLocation: nil, bannedSendPhotos: nil, bannedSendVideos: nil, subject: .assets(nil, .wallpaper), mainButtonState: AttachmentMainButtonState(text: presentationData.strings.Conversation_Theme_SetColorWallpaper, font: .regular, background: .color(.clear), textColor: presentationData.theme.actionSheet.controlAccentColor, isVisible: true, progress: .none, isEnabled: true), mainButtonAction: {
@ -2040,5 +2039,6 @@ public func wallpaperMediaPickerController(
mediaPickerController.customSelection = completion
present(mediaPickerController, mediaPickerController.mediaPickerContext)
}
controller.supportedOrientations = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .portrait)
return controller
}

View File

@ -232,6 +232,7 @@ private final class ThemeCarouselThemeItemIconNode : ListViewItemNode {
self.imageNode.isLayerBacked = true
self.imageNode.cornerRadius = 8.0
self.imageNode.clipsToBounds = true
self.imageNode.contentAnimations = [.subsequentUpdates]
self.overlayNode = ASImageNode()
self.overlayNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: 84.0, height: 110.0))

View File

@ -116,11 +116,11 @@ final class ThemeAccentColorController: ViewController {
if case .background = mode {
self.title = self.presentationData.strings.Wallpaper_Title
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Cancel, style: .plain, target: self, action: #selector(self.cancelPressed))
} else {
self.navigationItem.titleView = self.segmentedTitleView
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: UIView())
}
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Cancel, style: .plain, target: self, action: #selector(self.cancelPressed))
}
required init(coder aDecoder: NSCoder) {

View File

@ -188,7 +188,7 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate
private var messageNodes: [ListViewItemNode]?
private let colorPanelNode: WallpaperColorPanelNode
private let patternPanelNode: WallpaperPatternPanelNode
private let toolbarNode: WallpaperGalleryToolbarNode
private let toolbarNode: WallpaperGalleryToolbar
private var serviceColorDisposable: Disposable?
private var stateDisposable: Disposable?
@ -312,9 +312,14 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate
} else {
doneButtonType = .set
}
self.toolbarNode = WallpaperGalleryToolbarNode(theme: self.theme, strings: self.presentationData.strings, doneButtonType: doneButtonType)
self.toolbarNode.dark = true
self.toolbarNode.setDoneIsSolid(true, transition: .immediate)
if case .background = mode {
let toolbarNode = WallpaperGalleryToolbarNode(theme: self.theme, strings: self.presentationData.strings, doneButtonType: doneButtonType)
toolbarNode.dark = true
toolbarNode.setDoneIsSolid(true, transition: .immediate)
self.toolbarNode = toolbarNode
} else {
self.toolbarNode = WallpaperGalleryOldToolbarNode(theme: self.theme, strings: self.presentationData.strings, doneButtonType: doneButtonType)
}
self.maskNode = ASImageNode()
self.maskNode.displaysAsynchronously = false
@ -1168,8 +1173,12 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate
self.pageControlNode.setPage(0.0)
}
let toolbarHeight = 49.0 + layout.intrinsicInsets.bottom
transition.updateFrame(node: self.toolbarNode, frame: CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - toolbarHeight), size: CGSize(width: layout.size.width, height: 49.0 + layout.intrinsicInsets.bottom)))
var toolbarBottomInset = layout.intrinsicInsets.bottom
if case .background = mode, toolbarBottomInset.isZero {
toolbarBottomInset = 16.0
}
let toolbarHeight = 49.0 + toolbarBottomInset
transition.updateFrame(node: self.toolbarNode, frame: CGRect(origin: CGPoint(x: 0.0, y: layout.size.height - toolbarHeight), size: CGSize(width: layout.size.width, height: toolbarHeight)))
self.toolbarNode.updateLayout(size: CGSize(width: layout.size.width, height: 49.0), layout: layout, transition: transition)
var bottomInset = toolbarHeight
@ -1179,26 +1188,29 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate
var colorPanelOffset: CGFloat = 0.0
var colorPanelY = layout.size.height - bottomInset - colorPanelHeight
let originalBottomInset = bottomInset
if self.state.colorPanelCollapsed {
colorPanelOffset = colorPanelHeight
colorPanelY = layout.size.height
}
let colorPanelFrame = CGRect(origin: CGPoint(x: 0.0, y: colorPanelY), size: CGSize(width: layout.size.width, height: colorPanelHeight))
bottomInset += (colorPanelHeight - colorPanelOffset)
self.toolbarNode.setDoneIsSolid(!self.state.colorPanelCollapsed, transition: transition)
if let toolbarNode = self.toolbarNode as? WallpaperGalleryToolbarNode {
toolbarNode.setDoneIsSolid(!self.state.colorPanelCollapsed, transition: transition)
}
if bottomInset + navigationBarHeight > bounds.height {
return
}
transition.updateFrame(node: self.colorPanelNode, frame: colorPanelFrame)
self.colorPanelNode.updateLayout(size: colorPanelFrame.size, bottomInset: 0.0, transition: transition)
let colorPanelFrame = CGRect(origin: CGPoint(x: 0.0, y: colorPanelY), size: CGSize(width: layout.size.width, height: colorPanelHeight))
transition.updateFrame(node: self.colorPanelNode, frame: CGRect(origin: colorPanelFrame.origin, size: CGSize(width: colorPanelFrame.width, height: colorPanelFrame.height + originalBottomInset)))
self.colorPanelNode.updateLayout(size: colorPanelFrame.size, bottomInset: originalBottomInset, transition: transition)
let patternPanelAlpha: CGFloat = self.state.displayPatternPanel ? 1.0 : 0.0
let patternPanelFrame = colorPanelFrame
transition.updateFrame(node: self.patternPanelNode, frame: patternPanelFrame)
self.patternPanelNode.updateLayout(size: patternPanelFrame.size, bottomInset: 0.0, transition: transition)
self.patternPanelNode.updateLayout(size: patternPanelFrame.size, bottomInset: originalBottomInset, transition: transition)
self.patternPanelNode.isUserInteractionEnabled = self.state.displayPatternPanel
transition.updateAlpha(node: self.patternPanelNode, alpha: patternPanelAlpha)

View File

@ -394,7 +394,6 @@ public func standaloneColorPickerController(
let controller = AttachmentController(context: context, updatedPresentationData: updatedPresentationData, chatLocation: nil, buttons: [.standalone], initialButton: .standalone, fromMenu: false, hasTextInput: false, makeEntityInputView: {
return nil
})
//controller.supportedOrientations = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .portrait)
controller.requestController = { _, present in
let colorPickerController = ThemeColorsGridController(context: context, mode: .peer(peer))
colorPickerController.pushController = { controller in
@ -406,5 +405,6 @@ public func standaloneColorPickerController(
colorPickerController.openGallery = openGallery
present(colorPickerController, colorPickerController.mediaPickerContext)
}
controller.supportedOrientations = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .portrait)
return controller
}

View File

@ -259,6 +259,12 @@ final class ThemeColorsGridControllerNode: ASDisplayNode {
self.backgroundColor = presentationData.theme.list.plainBackgroundColor
}
self.leftOverlayNode.backgroundColor = presentationData.theme.list.blocksBackgroundColor
self.rightOverlayNode.backgroundColor = presentationData.theme.list.blocksBackgroundColor
self.topBackgroundNode.backgroundColor = presentationData.theme.list.blocksBackgroundColor
self.separatorNode.backgroundColor = presentationData.theme.list.itemBlocksSeparatorColor
self.customColorItem = ItemListActionItem(presentationData: ItemListPresentationData(presentationData), title: presentationData.strings.WallpaperColors_SetCustomColor, kind: .generic, alignment: .natural, sectionId: 0, style: .blocks, action: { [weak self] in
self?.presentColorPicker()
})

View File

@ -523,9 +523,42 @@ public class WallpaperGalleryController: ViewController {
let options = centralItemNode.options
if !strongSelf.entries.isEmpty {
let entry = strongSelf.entries[centralItemNode.index]
let apply = strongSelf.apply
if case .peer = strongSelf.mode {
strongSelf.apply?(entry, options, centralItemNode.editedFullSizeImage, centralItemNode.editedCropRect, centralItemNode.brightness)
if case let .wallpaper(wallpaper, _) = entry, options.contains(.blur) {
var resource: MediaResource?
switch wallpaper {
case let .file(file):
resource = file.file.resource
case let .image(representations, _):
if let largestSize = largestImageRepresentation(representations) {
resource = largestSize.resource
}
default:
break
}
if let resource = resource {
let representation = CachedBlurredWallpaperRepresentation()
var data: Data?
if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
data = maybeData
} else if let path = strongSelf.context.sharedContext.accountManager.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
data = maybeData
}
if let data = data {
strongSelf.context.sharedContext.accountManager.mediaBox.storeResourceData(resource.id, data: data, synchronous: true)
let _ = (strongSelf.context.sharedContext.accountManager.mediaBox.cachedResourceRepresentation(resource, representation: representation, complete: true, fetch: true)
|> filter({ $0.complete })
|> take(1)
|> deliverOnMainQueue).start(next: { _ in
apply?(entry, options, nil, nil, centralItemNode.brightness)
})
}
}
} else {
apply?(entry, options, centralItemNode.editedFullSizeImage, centralItemNode.editedCropRect, centralItemNode.brightness)
}
return
}
@ -595,7 +628,6 @@ public class WallpaperGalleryController: ViewController {
if options.contains(.blur) {
if let resource = resource {
let representation = CachedBlurredWallpaperRepresentation()
var data: Data?
if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) {
data = maybeData

View File

@ -343,7 +343,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
private func switchTheme() {
if let messageNodes = self.messageNodes {
for messageNode in messageNodes.prefix(2) {
if let snapshotView = messageNode.view.snapshotContentTree() {
if let snapshotView = messageNode.view.snapshotContentTree(keepPortals: true) {
messageNode.view.addSubview(snapshotView)
snapshotView.frame = messageNode.bounds
snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.35, removeOnCompletion: false, completion: { [weak snapshotView] _ in
@ -640,7 +640,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
self.nativeNode.isHidden = false
self.patternButtonNode.isSelected = file.isPattern
if file.isPattern && file.settings.colors.count >= 3 {
if file.settings.colors.count >= 3 {
self.playButtonNode.setIcon(self.playButtonPlayImage)
} else {
self.playButtonNode.setIcon(self.playButtonRotateImage)
@ -733,7 +733,6 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
let dimensions = file.file.dimensions ?? PixelDimensions(width: 2000, height: 4000)
contentSize = dimensions.cgSize
displaySize = dimensions.cgSize.dividedByScreenScale().integralFloor
var convertedRepresentations: [ImageRepresentationWithReference] = []
for representation in file.file.previewRepresentations {
convertedRepresentations.append(ImageRepresentationWithReference(representation: representation, reference: reference(for: representation.resource, media: file.file, message: message, slug: file.slug)))
@ -857,7 +856,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
case let .asset(asset):
let dimensions = CGSize(width: asset.pixelWidth, height: asset.pixelHeight)
contentSize = dimensions
displaySize = dimensions.dividedByScreenScale().integralFloor
displaySize = dimensions.aspectFittedOrSmaller(CGSize(width: 2048.0, height: 2048.0))
signal = photoWallpaper(postbox: context.account.postbox, photoLibraryResource: PhotoLibraryMediaResource(localIdentifier: asset.localIdentifier, uniqueId: Int64.random(in: Int64.min ... Int64.max)))
fetchSignal = .complete()
statusSignal = .single(.Local)
@ -899,7 +898,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
if let imageResource = imageResource, let imageDimensions = imageDimensions {
contentSize = imageDimensions
displaySize = imageDimensions.dividedByScreenScale().integralFloor
displaySize = imageDimensions.aspectFittedOrSmaller(CGSize(width: 2048.0, height: 2048.0))
var representations: [TelegramMediaImageRepresentation] = []
if let thumbnailResource = thumbnailResource, let thumbnailDimensions = thumbnailDimensions {

View File

@ -17,7 +17,19 @@ enum WallpaperGalleryToolbarDoneButtonType {
case none
}
final class WallpaperGalleryToolbarNode: ASDisplayNode {
protocol WallpaperGalleryToolbar: ASDisplayNode {
var cancelButtonType: WallpaperGalleryToolbarCancelButtonType { get set }
var doneButtonType: WallpaperGalleryToolbarDoneButtonType { get set }
var cancel: (() -> Void)? { get set }
var done: (() -> Void)? { get set }
func updateThemeAndStrings(theme: PresentationTheme, strings: PresentationStrings)
func updateLayout(size: CGSize, layout: ContainerViewLayout, transition: ContainedViewLayoutTransition)
}
final class WallpaperGalleryToolbarNode: ASDisplayNode, WallpaperGalleryToolbar {
private var theme: PresentationTheme
private let strings: PresentationStrings
@ -203,3 +215,134 @@ final class WallpaperGalleryToolbarNode: ASDisplayNode {
self.done?()
}
}
final class WallpaperGalleryOldToolbarNode: ASDisplayNode, WallpaperGalleryToolbar {
private var theme: PresentationTheme
private let strings: PresentationStrings
var cancelButtonType: WallpaperGalleryToolbarCancelButtonType {
didSet {
self.updateThemeAndStrings(theme: self.theme, strings: self.strings)
}
}
var doneButtonType: WallpaperGalleryToolbarDoneButtonType {
didSet {
self.updateThemeAndStrings(theme: self.theme, strings: self.strings)
}
}
private let cancelButton = HighlightTrackingButtonNode()
private let cancelHighlightBackgroundNode = ASDisplayNode()
private let doneButton = HighlightTrackingButtonNode()
private let doneHighlightBackgroundNode = ASDisplayNode()
private let backgroundNode = NavigationBackgroundNode(color: .clear)
private let separatorNode = ASDisplayNode()
private let topSeparatorNode = ASDisplayNode()
var cancel: (() -> Void)?
var done: (() -> Void)?
init(theme: PresentationTheme, strings: PresentationStrings, cancelButtonType: WallpaperGalleryToolbarCancelButtonType = .cancel, doneButtonType: WallpaperGalleryToolbarDoneButtonType = .set) {
self.theme = theme
self.strings = strings
self.cancelButtonType = cancelButtonType
self.doneButtonType = doneButtonType
self.cancelHighlightBackgroundNode.alpha = 0.0
self.doneHighlightBackgroundNode.alpha = 0.0
super.init()
self.addSubnode(self.backgroundNode)
self.addSubnode(self.cancelHighlightBackgroundNode)
self.addSubnode(self.cancelButton)
self.addSubnode(self.doneHighlightBackgroundNode)
self.addSubnode(self.doneButton)
self.addSubnode(self.separatorNode)
self.addSubnode(self.topSeparatorNode)
self.updateThemeAndStrings(theme: theme, strings: strings)
self.cancelButton.highligthedChanged = { [weak self] highlighted in
if let strongSelf = self {
if highlighted {
strongSelf.cancelHighlightBackgroundNode.layer.removeAnimation(forKey: "opacity")
strongSelf.cancelHighlightBackgroundNode.alpha = 1.0
} else {
strongSelf.cancelHighlightBackgroundNode.alpha = 0.0
strongSelf.cancelHighlightBackgroundNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3)
}
}
}
self.doneButton.highligthedChanged = { [weak self] highlighted in
if let strongSelf = self {
if highlighted {
strongSelf.doneHighlightBackgroundNode.layer.removeAnimation(forKey: "opacity")
strongSelf.doneHighlightBackgroundNode.alpha = 1.0
} else {
strongSelf.doneHighlightBackgroundNode.alpha = 0.0
strongSelf.doneHighlightBackgroundNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3)
}
}
}
self.cancelButton.addTarget(self, action: #selector(self.cancelPressed), forControlEvents: .touchUpInside)
self.doneButton.addTarget(self, action: #selector(self.donePressed), forControlEvents: .touchUpInside)
}
func setDoneEnabled(_ enabled: Bool) {
self.doneButton.alpha = enabled ? 1.0 : 0.4
self.doneButton.isUserInteractionEnabled = enabled
}
func updateThemeAndStrings(theme: PresentationTheme, strings: PresentationStrings) {
self.theme = theme
self.backgroundNode.updateColor(color: theme.rootController.tabBar.backgroundColor, transition: .immediate)
self.separatorNode.backgroundColor = theme.rootController.tabBar.separatorColor
self.topSeparatorNode.backgroundColor = theme.rootController.tabBar.separatorColor
self.cancelHighlightBackgroundNode.backgroundColor = theme.list.itemHighlightedBackgroundColor
self.doneHighlightBackgroundNode.backgroundColor = theme.list.itemHighlightedBackgroundColor
let cancelTitle: String
switch self.cancelButtonType {
case .cancel:
cancelTitle = strings.Common_Cancel
case .discard:
cancelTitle = strings.WallpaperPreview_PatternPaternDiscard
}
let doneTitle: String
switch self.doneButtonType {
case .set, .setPeer:
doneTitle = strings.Wallpaper_Set
case .proceed:
doneTitle = strings.Theme_Colors_Proceed
case .apply:
doneTitle = strings.WallpaperPreview_PatternPaternApply
case .none:
doneTitle = ""
self.doneButton.isUserInteractionEnabled = false
}
self.cancelButton.setTitle(cancelTitle, with: Font.regular(17.0), with: theme.list.itemPrimaryTextColor, for: [])
self.doneButton.setTitle(doneTitle, with: Font.regular(17.0), with: theme.list.itemPrimaryTextColor, for: [])
}
func updateLayout(size: CGSize, layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
self.cancelButton.frame = CGRect(origin: CGPoint(), size: CGSize(width: floor(size.width / 2.0), height: size.height))
self.cancelHighlightBackgroundNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: floor(size.width / 2.0), height: size.height))
self.doneButton.frame = CGRect(origin: CGPoint(x: floor(size.width / 2.0), y: 0.0), size: CGSize(width: size.width - floor(size.width / 2.0), height: size.height))
self.doneHighlightBackgroundNode.frame = CGRect(origin: CGPoint(x: floor(size.width / 2.0), y: 0.0), size: CGSize(width: size.width - floor(size.width / 2.0), height: size.height))
self.separatorNode.frame = CGRect(origin: CGPoint(x: floor(size.width / 2.0), y: 0.0), size: CGSize(width: UIScreenPixel, height: size.height + layout.intrinsicInsets.bottom))
self.topSeparatorNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: UIScreenPixel))
self.backgroundNode.frame = CGRect(origin: CGPoint(), size: size)
self.backgroundNode.update(size: CGSize(width: size.width, height: size.height + layout.intrinsicInsets.bottom), transition: .immediate)
}
@objc func cancelPressed() {
self.cancel?()
}
@objc func donePressed() {
self.done?()
}
}

View File

@ -239,7 +239,7 @@ public final class TextNodeWithEntities {
let id = InlineStickerItemLayer.Key(id: stickerItem.emoji.fileId, index: index)
validIds.append(id)
let itemSize = floor(stickerItem.fontSize * 24.0 / 17.0)
let itemSize = floorToScreenPixels(stickerItem.fontSize * 24.0 / 17.0)
var itemFrame = CGRect(origin: item.rect.offsetBy(dx: textLayout.insets.left, dy: textLayout.insets.top + 1.0).center, size: CGSize()).insetBy(dx: -itemSize / 2.0, dy: -itemSize / 2.0)
itemFrame.origin.x = floorToScreenPixels(itemFrame.origin.x)

View File

@ -858,19 +858,21 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
}
strongSelf.chatDisplayNode.dismissInput()
let wallpaperPreviewController = WallpaperGalleryController(context: strongSelf.context, source: .wallpaper(wallpaper, nil, [], nil, nil, nil), mode: .peer(EnginePeer(peer), true))
wallpaperPreviewController.apply = { [weak wallpaperPreviewController] entry, options, _, _, _ in
if case let .wallpaper(wallpaper, _) = entry, case let .file(file) = wallpaper, !file.isPattern && options.contains(.blur) {
uploadCustomPeerWallpaper(context: strongSelf.context, wallpaper: entry, mode: options, editedImage: nil, cropRect: nil, brightness: nil, peerId: message.id.peerId, completion: {
wallpaperPreviewController?.dismiss()
})
} else {
let _ = (strongSelf.context.engine.themes.setExistingChatWallpaper(messageId: message.id, settings: nil)
wallpaperPreviewController.apply = { [weak wallpaperPreviewController] entry, options, _, _, brightness in
var settings: WallpaperSettings?
if case let .wallpaper(wallpaper, _) = entry, case let .file(file) = wallpaper, !file.isPattern {
var intensity: Int32?
if let brightness {
intensity = max(0, min(100, Int32(brightness * 100.0)))
}
settings = WallpaperSettings(blur: options.contains(.blur), motion: options.contains(.motion), intensity: intensity)
}
let _ = (strongSelf.context.engine.themes.setExistingChatWallpaper(messageId: message.id, settings: settings)
|> deliverOnMainQueue).start()
Queue.mainQueue().after(0.1) {
wallpaperPreviewController?.dismiss()
}
}
}
strongSelf.push(wallpaperPreviewController)
return true
case .setSameChatWallpaper:

View File

@ -270,6 +270,7 @@ private final class ThemeSettingsThemeItemIconNode : ListViewItemNode {
self.imageNode.isLayerBacked = true
self.imageNode.cornerRadius = 8.0
self.imageNode.clipsToBounds = true
self.imageNode.contentAnimations = [.subsequentUpdates]
self.overlayNode = ASImageNode()
self.overlayNode.frame = CGRect(origin: CGPoint(), size: CGSize(width: 84.0, height: 110.0))
@ -1330,6 +1331,10 @@ private class ChatThemeScreenNode: ViewControllerTracingNode, UIScrollViewDelega
if self.controller?.canResetWallpaper == true {
contentHeight += 50.0
}
if cleanInsets.bottom.isZero {
insets.bottom += 14.0
contentHeight += 14.0
}
let width = horizontalContainerFillingSizeForLayout(layout: layout, sideInset: 0.0)

View File

@ -1058,12 +1058,12 @@ final class WallpaperBackgroundNodeImpl: ASDisplayNode, WallpaperBackgroundNode
if let (size, displayMode) = self.validLayout {
self.updateLayout(size: size, displayMode: displayMode, transition: .immediate)
self.updateBubbles()
if scheduleLoopingEvent {
self.animateEvent(transition: .animated(duration: 0.7, curve: .linear), extendAnimation: false)
}
}
self.updateBubbles()
self.updateDimming()
}

View File

@ -553,6 +553,8 @@ private func patternWallpaperImageInternal(fullSizeData: Data?, fullSizeComplete
c.restoreGState()
}
var patternIsLoaded = false
var patternIsInverted = false
let displayMode = customArguments.displayMode
let overlayImage = generateImage(arguments.drawingRect.size, rotatedContext: { size, c in
c.clear(CGRect(origin: CGPoint(), size: size))
@ -566,6 +568,7 @@ private func patternWallpaperImageInternal(fullSizeData: Data?, fullSizeComplete
}
if let customPatternColor = customArguments.customPatternColor, customPatternColor.alpha < 1.0 {
patternIsInverted = true
c.setBlendMode(.copy)
c.setFillColor(UIColor.black.cgColor)
c.fill(CGRect(origin: CGPoint(), size: size))
@ -574,6 +577,7 @@ private func patternWallpaperImageInternal(fullSizeData: Data?, fullSizeComplete
}
if let image = image {
patternIsLoaded = true
var fittedSize = image.size
if abs(fittedSize.width - arguments.boundingSize.width).isLessThanOrEqualTo(CGFloat(1.0)) {
fittedSize.width = arguments.boundingSize.width
@ -660,6 +664,10 @@ private func patternWallpaperImageInternal(fullSizeData: Data?, fullSizeComplete
c.translateBy(x: -drawingRect.midX, y: -drawingRect.midY)
c.setAlpha(1.0)
}
if !patternIsLoaded && patternIsInverted {
c.setFillColor(UIColor.black.cgColor)
c.fill(CGRect(origin: .zero, size: drawingRect.size))
}
}
addCorners(context, arguments: arguments)
return context
@ -1526,7 +1534,7 @@ public func themeIconImage(account: Account, accountManager: AccountManager<Tele
let image = context?.generateImage()
if !file.settings.colors.isEmpty {
return .single((effectiveBackgroundColor, incomingColors, outgoingColors, image, false, isMask, alpha, rotation))
return .single((image == nil ? backgroundColor : effectiveBackgroundColor, incomingColors, outgoingColors, image, false, isMask, alpha, rotation))
} else {
return .complete()
}
@ -1569,8 +1577,10 @@ public func themeIconImage(account: Account, accountManager: AccountManager<Tele
context.withContext { c in
let isBlack = UIColor.average(of: colors.0.2.map(UIColor.init(rgb:))).hsb.b <= 0.01
var patternIntensity: CGFloat = 0.5
var isPattern = false
if let wallpaper = wallpaper, case let .file(file) = wallpaper {
if !file.settings.colors.isEmpty {
isPattern = file.isPattern
if let intensity = file.settings.intensity {
patternIntensity = CGFloat(intensity) / 100.0
}
@ -1578,8 +1588,13 @@ public func themeIconImage(account: Account, accountManager: AccountManager<Tele
}
if colors.0.2.count >= 3 {
if isPattern && patternIntensity < 0.0 && colors.3 == nil {
c.setFillColor(UIColor.black.cgColor)
c.fill(drawingRect)
} else {
let image = GradientBackgroundNode.generatePreview(size: CGSize(width: 60.0, height: 60.0), colors: colors.0.2.map(UIColor.init(rgb:)))
c.draw(image.cgImage!, in: drawingRect)
}
} else if let secondBackgroundColor = colors.0.1 {
let gradientColors = [colors.0.0, secondBackgroundColor].map { $0.cgColor } as CFArray
var locations: [CGFloat] = [0.0, 1.0]