Various fixes

This commit is contained in:
Ilya Laktyushin 2024-03-27 18:00:49 +04:00
parent d4e0dd8ef9
commit 75dbdec6f6
6 changed files with 47 additions and 33 deletions

View File

@ -60,7 +60,7 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
private let context: AccountContext private let context: AccountContext
private let size: CGSize private let size: CGSize
private let hasBin: Bool private let hasBin: Bool
private let isStickerEditor: Bool public let isStickerEditor: Bool
weak var drawingView: DrawingView? weak var drawingView: DrawingView?
public weak var selectionContainerView: DrawingSelectionContainerView? public weak var selectionContainerView: DrawingSelectionContainerView?

View File

@ -98,6 +98,7 @@ class DrawingEntitySnapTool {
guard let snapCenterLocation = (entityView.superview as? DrawingEntitiesView)?.getEntityCenterPosition() else { guard let snapCenterLocation = (entityView.superview as? DrawingEntitiesView)?.getEntityCenterPosition() else {
return updatedPosition return updatedPosition
} }
let isStickerEditor = (entityView.superview as? DrawingEntitiesView)?.isStickerEditor ?? false
let snapEdgeLocations = (entityView.superview as? DrawingEntitiesView)?.getEntityEdgePositions() let snapEdgeLocations = (entityView.superview as? DrawingEntitiesView)?.getEntityEdgePositions()
let currentTimestamp = CACurrentMediaTime() let currentTimestamp = CACurrentMediaTime()
@ -202,7 +203,7 @@ class DrawingEntitySnapTool {
self.yState = updatedYState self.yState = updatedYState
self.previousYSnapTimestamp = updatedYPreviousTimestamp self.previousYSnapTimestamp = updatedYPreviousTimestamp
if let snapEdgeLocations { if let snapEdgeLocations, !isStickerEditor {
if updatedXState == nil { if updatedXState == nil {
let (updatedXLeftEdgeValue, updatedLeftEdgeState, updatedLeftEdgePreviousTimestamp) = process( let (updatedXLeftEdgeValue, updatedLeftEdgeState, updatedLeftEdgePreviousTimestamp) = process(
state: self.leftEdgeState, state: self.leftEdgeState,

View File

@ -1676,16 +1676,11 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable {
} else if collection == nil { } else if collection == nil {
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Cancel, style: .plain, target: self, action: #selector(self.cancelPressed)) self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Cancel, style: .plain, target: self, action: #selector(self.cancelPressed))
if [.story, .createSticker].contains(mode) { if [.createSticker].contains(mode) {
self.navigationItem.rightBarButtonItem = UIBarButtonItem(customDisplayNode: self.moreButtonNode) self.navigationItem.rightBarButtonItem = UIBarButtonItem(customDisplayNode: self.moreButtonNode)
self.navigationItem.rightBarButtonItem?.action = #selector(self.rightButtonPressed) self.navigationItem.rightBarButtonItem?.action = #selector(self.rightButtonPressed)
self.navigationItem.rightBarButtonItem?.target = self self.navigationItem.rightBarButtonItem?.target = self
} }
// if mode == .story || mode == .addImage {
// self.navigationItem.rightBarButtonItem = UIBarButtonItem(customDisplayNode: self.moreButtonNode)
// self.navigationItem.rightBarButtonItem?.action = #selector(self.rightButtonPressed)
// self.navigationItem.rightBarButtonItem?.target = self
// }
} else { } else {
self.navigationItem.leftBarButtonItem = UIBarButtonItem(backButtonAppearanceWithTitle: self.presentationData.strings.Common_Back, target: self, action: #selector(self.backPressed)) self.navigationItem.leftBarButtonItem = UIBarButtonItem(backButtonAppearanceWithTitle: self.presentationData.strings.Common_Back, target: self, action: #selector(self.backPressed))
} }

View File

@ -250,8 +250,12 @@ func _internal_renameStickerSet(account: Account, packReference: StickerPackRefe
return .complete() return .complete()
} }
return account.postbox.transaction { transaction -> Void in return account.postbox.transaction { transaction -> Void in
transaction.replaceItemCollectionInfos(namespace: Namespaces.ItemCollection.CloudStickerPacks, itemCollectionInfos: [(info.id, info)]) let collectionNamespace = Namespaces.ItemCollection.CloudStickerPacks
var currentInfos = transaction.getItemCollectionsInfos(namespace: collectionNamespace).map { $0.1 as! StickerPackCollectionInfo }
if let index = currentInfos.firstIndex(where: { $0.id == info.id }) {
currentInfos[index] = info
}
transaction.replaceItemCollectionInfos(namespace: collectionNamespace, itemCollectionInfos: currentInfos.map { ($0.id, $0) })
cacheStickerPack(transaction: transaction, info: info, items: items) cacheStickerPack(transaction: transaction, info: info, items: items)
} }
|> castError(RenameStickerSetError.self) |> castError(RenameStickerSetError.self)

View File

@ -151,7 +151,7 @@ private func getPathFromMaskImage(_ image: CIImage, size: CGSize, values: MediaE
var contour = findContours(pixelBuffer: pixelBuffer) var contour = findContours(pixelBuffer: pixelBuffer)
contour = simplify(contour, tolerance: 1.4) contour = simplify(contour, tolerance: 1.4)
let path = UIBezierPath(points: contour, close: true) let path = UIBezierPath(points: contour, smooth: false)
let firstScale = min(size.width, size.height) / 256.0 let firstScale = min(size.width, size.height) / 256.0
let secondScale = size.width / 1080.0 let secondScale = size.width / 1080.0
@ -480,13 +480,16 @@ fileprivate extension Array {
return (index + self.count) % self.count return (index + self.count) % self.count
} }
} }
extension UIBezierPath {
convenience init(points: [CGPoint], close: Bool) { private extension UIBezierPath {
convenience init(points: [CGPoint], smooth: Bool) {
self.init() self.init()
if smooth {
let K: CGFloat = 0.2 let K: CGFloat = 0.2
var c1 = [Int: CGPoint]() var c1 = [Int: CGPoint]()
var c2 = [Int: CGPoint]() var c2 = [Int: CGPoint]()
let count = close ? points.count + 1 : points.count - 1 let count = points.count - 1
for index in 1 ..< count { for index in 1 ..< count {
let p = points[circularIndex: index] let p = points[circularIndex: index]
let vP1 = points[circularIndex: index + 1] let vP1 = points[circularIndex: index + 1]
@ -503,5 +506,12 @@ extension UIBezierPath {
self.addCurve(to: points[circularIndex: index + 1], controlPoint1: c1, controlPoint2: c2) self.addCurve(to: points[circularIndex: index + 1], controlPoint1: c1, controlPoint2: c2)
} }
self.close() self.close()
} else {
self.move(to: points[0])
for index in 1 ..< points.count - 1 {
self.addLine(to: points[index])
}
self.close()
}
} }
} }

View File

@ -61,7 +61,7 @@ public final class BirthdayPickerComponent: Component {
private let calendar = Calendar(identifier: .gregorian) private let calendar = Calendar(identifier: .gregorian)
private var value = TelegramBirthday(day: 1, month: 1, year: nil) private var value = TelegramBirthday(day: 1, month: 1, year: nil)
private let minYear: Int32 = 1900 private var minYear: Int32 = 1900
private let maxYear: Int32 private let maxYear: Int32
override init(frame: CGRect) { override init(frame: CGRect) {
@ -84,6 +84,10 @@ public final class BirthdayPickerComponent: Component {
self.component = component self.component = component
self.componentState = state self.componentState = state
if let year = component.value.year, year < self.minYear {
self.minYear = year
}
self.pickerView.frame = CGRect(origin: .zero, size: availableSize) self.pickerView.frame = CGRect(origin: .zero, size: availableSize)
if isFirstTime || self.value != component.value { if isFirstTime || self.value != component.value {