Various fixes

This commit is contained in:
Ilya Laktyushin 2023-08-01 14:27:45 +02:00
parent 6dce0c9c12
commit 9e18b91f57
6 changed files with 63 additions and 29 deletions

View File

@ -301,10 +301,16 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
return CGSize(width: width, height: width) return CGSize(width: width, height: width)
} }
public func prepareNewEntity(_ entity: DrawingEntity, setup: Bool = true, relativeTo: DrawingEntity? = nil) { public func prepareNewEntity(_ entity: DrawingEntity, setup: Bool = true, relativeTo: DrawingEntity? = nil, scale: CGFloat? = nil, position: CGPoint? = nil) {
let center = self.startPosition(relativeTo: relativeTo, onlyVertical: entity is DrawingTextEntity) var center = self.startPosition(relativeTo: relativeTo, onlyVertical: entity is DrawingTextEntity)
if let position {
center = position
}
let rotation = self.getEntityInitialRotation() let rotation = self.getEntityInitialRotation()
let zoomScale = 1.0 / (self.drawingView?.zoomScale ?? 1.0) var zoomScale = 1.0 / (self.drawingView?.zoomScale ?? 1.0)
if let scale {
zoomScale = scale
}
if let shape = entity as? DrawingSimpleShapeEntity { if let shape = entity as? DrawingSimpleShapeEntity {
shape.position = center shape.position = center
@ -357,7 +363,7 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
if setup { if setup {
location.rotation = rotation location.rotation = rotation
location.referenceDrawingSize = self.size location.referenceDrawingSize = self.size
location.width = floor(self.size.width * 0.9) location.width = floor(self.size.width * 0.85)
location.scale = zoomScale location.scale = zoomScale
} }
} }
@ -471,7 +477,7 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
return newEntity return newEntity
} }
func remove(uuid: UUID, animated: Bool = false, announce: Bool = true) { public func remove(uuid: UUID, animated: Bool = false, announce: Bool = true) {
if let view = self.getView(for: uuid) { if let view = self.getView(for: uuid) {
if self.selectedEntityView === view { if self.selectedEntityView === view {
self.selectedEntityView = nil self.selectedEntityView = nil

View File

@ -2445,6 +2445,7 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController, U
} }
}, },
onTextEditingEnded: { _ in }, onTextEditingEnded: { _ in },
editEntity: { _ in },
getCurrentImage: { [weak controller] in getCurrentImage: { [weak controller] in
return controller?.getCurrentImage() return controller?.getCurrentImage()
}, },
@ -2961,6 +2962,7 @@ public final class DrawingToolsInteraction {
private let onInteractionUpdated: (Bool) -> Void private let onInteractionUpdated: (Bool) -> Void
private let onTextEditingEnded: (Bool) -> Void private let onTextEditingEnded: (Bool) -> Void
private let editEntity: (DrawingEntity) -> Void
public let getCurrentImage: () -> UIImage? public let getCurrentImage: () -> UIImage?
private let getControllerNode: () -> ASDisplayNode? private let getControllerNode: () -> ASDisplayNode?
@ -2990,6 +2992,7 @@ public final class DrawingToolsInteraction {
updateColor: @escaping (DrawingColor) -> Void, updateColor: @escaping (DrawingColor) -> Void,
onInteractionUpdated: @escaping (Bool) -> Void, onInteractionUpdated: @escaping (Bool) -> Void,
onTextEditingEnded: @escaping (Bool) -> Void, onTextEditingEnded: @escaping (Bool) -> Void,
editEntity: @escaping (DrawingEntity) -> Void,
getCurrentImage: @escaping () -> UIImage?, getCurrentImage: @escaping () -> UIImage?,
getControllerNode: @escaping () -> ASDisplayNode?, getControllerNode: @escaping () -> ASDisplayNode?,
present: @escaping (ViewController, PresentationContextType, Any?) -> Void, present: @escaping (ViewController, PresentationContextType, Any?) -> Void,
@ -3006,6 +3009,7 @@ public final class DrawingToolsInteraction {
self.updateColor = updateColor self.updateColor = updateColor
self.onInteractionUpdated = onInteractionUpdated self.onInteractionUpdated = onInteractionUpdated
self.onTextEditingEnded = onTextEditingEnded self.onTextEditingEnded = onTextEditingEnded
self.editEntity = editEntity
self.getCurrentImage = getCurrentImage self.getCurrentImage = getCurrentImage
self.getControllerNode = getControllerNode self.getControllerNode = getControllerNode
self.present = present self.present = present
@ -3066,7 +3070,14 @@ public final class DrawingToolsInteraction {
self.entitiesView.remove(uuid: entityView.entity.uuid, animated: true) self.entitiesView.remove(uuid: entityView.entity.uuid, animated: true)
} }
})) }))
if let entityView = entityView as? DrawingTextEntityView { if let entityView = entityView as? DrawingLocationEntityView {
actions.append(ContextMenuAction(content: .text(title: presentationData.strings.Paint_Edit, accessibilityLabel: presentationData.strings.Paint_Edit), action: { [weak self, weak entityView] in
if let self, let entityView {
self.editEntity(entityView.entity)
self.entitiesView.selectEntity(entityView.entity)
}
}))
} else if let entityView = entityView as? DrawingTextEntityView {
actions.append(ContextMenuAction(content: .text(title: presentationData.strings.Paint_Edit, accessibilityLabel: presentationData.strings.Paint_Edit), action: { [weak self, weak entityView] in actions.append(ContextMenuAction(content: .text(title: presentationData.strings.Paint_Edit, accessibilityLabel: presentationData.strings.Paint_Edit), action: { [weak self, weak entityView] in
if let self, let entityView { if let self, let entityView {
entityView.beginEditing(accessoryView: self.textEditAccessoryView) entityView.beginEditing(accessoryView: self.textEditAccessoryView)
@ -3117,11 +3128,8 @@ public final class DrawingToolsInteraction {
self.isActive = false self.isActive = false
} }
public func insertEntity(_ entity: DrawingEntity, scale: CGFloat? = nil) { public func insertEntity(_ entity: DrawingEntity, scale: CGFloat? = nil, position: CGPoint? = nil) {
self.entitiesView.prepareNewEntity(entity) self.entitiesView.prepareNewEntity(entity, scale: scale, position: position)
if let scale {
entity.scale = scale
}
self.entitiesView.add(entity) self.entitiesView.add(entity)
self.entitiesView.selectEntity(entity, animate: !(entity is DrawingTextEntity)) self.entitiesView.selectEntity(entity, animate: !(entity is DrawingTextEntity))

View File

@ -46,7 +46,11 @@ public final class DrawingLocationEntity: DrawingEntity, Codable {
public var referenceDrawingSize: CGSize public var referenceDrawingSize: CGSize
public var position: CGPoint public var position: CGPoint
public var width: CGFloat public var width: CGFloat
public var scale: CGFloat public var scale: CGFloat {
didSet {
self.scale = min(2.5, self.scale)
}
}
public var rotation: CGFloat public var rotation: CGFloat
public var center: CGPoint { public var center: CGPoint {
@ -82,9 +86,6 @@ public final class DrawingLocationEntity: DrawingEntity, Codable {
self.title = try container.decode(String.self, forKey: .title) self.title = try container.decode(String.self, forKey: .title)
self.style = try container.decode(Style.self, forKey: .style) self.style = try container.decode(Style.self, forKey: .style)
let locationData = try container.decode(AdaptedPostboxDecoder.RawObjectData.self, forKey: .location)
self.location = TelegramMediaMap(decoder: PostboxDecoder(buffer: MemoryBuffer(data: locationData.data)))
if let locationData = try container.decodeIfPresent(Data.self, forKey: .location) { if let locationData = try container.decodeIfPresent(Data.self, forKey: .location) {
self.location = PostboxDecoder(buffer: MemoryBuffer(data: locationData)).decodeRootObject() as! TelegramMediaMap self.location = PostboxDecoder(buffer: MemoryBuffer(data: locationData)).decodeRootObject() as! TelegramMediaMap
} else { } else {

View File

@ -2043,6 +2043,13 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
}).start() }).start()
} }
}, },
editEntity: { [weak self] entity in
if let self {
if let location = entity as? DrawingLocationEntity {
self.presentLocationPicker(location)
}
}
},
getCurrentImage: { [weak self] in getCurrentImage: { [weak self] in
guard let self else { guard let self else {
return nil return nil
@ -2698,7 +2705,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
controller.push(galleryController) controller.push(galleryController)
} }
func presentLocationPicker() { func presentLocationPicker(_ existingEntity: DrawingLocationEntity? = nil) {
guard let controller = self.controller else { guard let controller = self.controller else {
return return
} }
@ -2714,15 +2721,21 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
} else { } else {
title = address ?? "Location" title = address ?? "Location"
} }
let position = existingEntity?.position
let scale = existingEntity?.scale ?? 1.0
if let existingEntity {
self.entitiesView.remove(uuid: existingEntity.uuid, animated: true)
}
self.interaction?.insertEntity( self.interaction?.insertEntity(
DrawingLocationEntity( DrawingLocationEntity(
title: title, title: title,
style: .white, style: existingEntity?.style ?? .white,
location: location, location: location,
queryId: queryId, queryId: queryId,
resultId: resultId resultId: resultId
), ),
scale: 1.0 scale: scale,
position: position
) )
} }
}) })

View File

@ -186,10 +186,10 @@ final class ContextResultPanelComponent: Component {
let visibleBounds = self.scrollView.bounds.insetBy(dx: 0.0, dy: -200.0) let visibleBounds = self.scrollView.bounds.insetBy(dx: 0.0, dy: -200.0)
var synchronousLoad = false // var synchronousLoad = false
if let hint = transition.userData(PeerListItemComponent.TransitionHint.self) { // if let hint = transition.userData(PeerListItemComponent.TransitionHint.self) {
synchronousLoad = hint.synchronousLoad // synchronousLoad = hint.synchronousLoad
} // }
var validIds: [AnyHashable] = [] var validIds: [AnyHashable] = []
if let range = itemLayout.visibleItems(for: visibleBounds), case let .mentions(peers) = component.results { if let range = itemLayout.visibleItems(for: visibleBounds), case let .mentions(peers) = component.results {
@ -241,16 +241,16 @@ final class ContextResultPanelComponent: Component {
containerSize: itemFrame.size containerSize: itemFrame.size
) )
if let itemView = visibleItem.view { if let itemView = visibleItem.view {
var animateIn = false // var animateIn = false
if itemView.superview == nil { if itemView.superview == nil {
animateIn = true // animateIn = true
self.scrollView.addSubview(itemView) self.scrollView.addSubview(itemView)
} }
itemTransition.setFrame(view: itemView, frame: itemFrame) itemTransition.setFrame(view: itemView, frame: itemFrame)
if animateIn, synchronousLoad { // if animateIn {
itemView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) // itemView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
} // }
} }
} }
} }
@ -274,8 +274,8 @@ final class ContextResultPanelComponent: Component {
} }
func update(component: ContextResultPanelComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize { func update(component: ContextResultPanelComponent, availableSize: CGSize, state: EmptyComponentState, environment: Environment<Empty>, transition: Transition) -> CGSize {
//let itemUpdated = self.component?.results != component.results var transition = transition
let previousComponent = self.component
self.component = component self.component = component
self.state = state self.state = state
@ -306,6 +306,10 @@ final class ContextResultPanelComponent: Component {
containerSize: CGSize(width: availableSize.width, height: 1000.0) containerSize: CGSize(width: availableSize.width, height: 1000.0)
) )
if previousComponent?.results != component.results {
transition = transition.withUserData(PeerListItemComponent.TransitionHint(synchronousLoad: true))
}
let itemLayout = ItemLayout( let itemLayout = ItemLayout(
containerSize: CGSize(width: availableSize.width, height: minimizedHeight), containerSize: CGSize(width: availableSize.width, height: minimizedHeight),
bottomInset: 0.0, bottomInset: 0.0,

View File

@ -267,6 +267,8 @@ public final class PeerListItemComponent: Component {
let themeUpdated = self.component?.theme !== component.theme let themeUpdated = self.component?.theme !== component.theme
self.avatarButtonView.isUserInteractionEnabled = component.openStories != nil
var hasSelectionUpdated = false var hasSelectionUpdated = false
if let previousComponent = self.component { if let previousComponent = self.component {
switch previousComponent.selectionState { switch previousComponent.selectionState {