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)
}
public func prepareNewEntity(_ entity: DrawingEntity, setup: Bool = true, relativeTo: DrawingEntity? = nil) {
let center = self.startPosition(relativeTo: relativeTo, onlyVertical: entity is DrawingTextEntity)
public func prepareNewEntity(_ entity: DrawingEntity, setup: Bool = true, relativeTo: DrawingEntity? = nil, scale: CGFloat? = nil, position: CGPoint? = nil) {
var center = self.startPosition(relativeTo: relativeTo, onlyVertical: entity is DrawingTextEntity)
if let position {
center = position
}
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 {
shape.position = center
@ -357,7 +363,7 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
if setup {
location.rotation = rotation
location.referenceDrawingSize = self.size
location.width = floor(self.size.width * 0.9)
location.width = floor(self.size.width * 0.85)
location.scale = zoomScale
}
}
@ -471,7 +477,7 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
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 self.selectedEntityView === view {
self.selectedEntityView = nil

View File

@ -2445,6 +2445,7 @@ public class DrawingScreen: ViewController, TGPhotoDrawingInterfaceController, U
}
},
onTextEditingEnded: { _ in },
editEntity: { _ in },
getCurrentImage: { [weak controller] in
return controller?.getCurrentImage()
},
@ -2961,6 +2962,7 @@ public final class DrawingToolsInteraction {
private let onInteractionUpdated: (Bool) -> Void
private let onTextEditingEnded: (Bool) -> Void
private let editEntity: (DrawingEntity) -> Void
public let getCurrentImage: () -> UIImage?
private let getControllerNode: () -> ASDisplayNode?
@ -2990,6 +2992,7 @@ public final class DrawingToolsInteraction {
updateColor: @escaping (DrawingColor) -> Void,
onInteractionUpdated: @escaping (Bool) -> Void,
onTextEditingEnded: @escaping (Bool) -> Void,
editEntity: @escaping (DrawingEntity) -> Void,
getCurrentImage: @escaping () -> UIImage?,
getControllerNode: @escaping () -> ASDisplayNode?,
present: @escaping (ViewController, PresentationContextType, Any?) -> Void,
@ -3006,6 +3009,7 @@ public final class DrawingToolsInteraction {
self.updateColor = updateColor
self.onInteractionUpdated = onInteractionUpdated
self.onTextEditingEnded = onTextEditingEnded
self.editEntity = editEntity
self.getCurrentImage = getCurrentImage
self.getControllerNode = getControllerNode
self.present = present
@ -3066,7 +3070,14 @@ public final class DrawingToolsInteraction {
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
if let self, let entityView {
entityView.beginEditing(accessoryView: self.textEditAccessoryView)
@ -3117,11 +3128,8 @@ public final class DrawingToolsInteraction {
self.isActive = false
}
public func insertEntity(_ entity: DrawingEntity, scale: CGFloat? = nil) {
self.entitiesView.prepareNewEntity(entity)
if let scale {
entity.scale = scale
}
public func insertEntity(_ entity: DrawingEntity, scale: CGFloat? = nil, position: CGPoint? = nil) {
self.entitiesView.prepareNewEntity(entity, scale: scale, position: position)
self.entitiesView.add(entity)
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 position: CGPoint
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 center: CGPoint {
@ -82,9 +86,6 @@ public final class DrawingLocationEntity: DrawingEntity, Codable {
self.title = try container.decode(String.self, forKey: .title)
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) {
self.location = PostboxDecoder(buffer: MemoryBuffer(data: locationData)).decodeRootObject() as! TelegramMediaMap
} else {

View File

@ -2043,6 +2043,13 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
}).start()
}
},
editEntity: { [weak self] entity in
if let self {
if let location = entity as? DrawingLocationEntity {
self.presentLocationPicker(location)
}
}
},
getCurrentImage: { [weak self] in
guard let self else {
return nil
@ -2698,7 +2705,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
controller.push(galleryController)
}
func presentLocationPicker() {
func presentLocationPicker(_ existingEntity: DrawingLocationEntity? = nil) {
guard let controller = self.controller else {
return
}
@ -2714,15 +2721,21 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
} else {
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(
DrawingLocationEntity(
title: title,
style: .white,
style: existingEntity?.style ?? .white,
location: location,
queryId: queryId,
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)
var synchronousLoad = false
if let hint = transition.userData(PeerListItemComponent.TransitionHint.self) {
synchronousLoad = hint.synchronousLoad
}
// var synchronousLoad = false
// if let hint = transition.userData(PeerListItemComponent.TransitionHint.self) {
// synchronousLoad = hint.synchronousLoad
// }
var validIds: [AnyHashable] = []
if let range = itemLayout.visibleItems(for: visibleBounds), case let .mentions(peers) = component.results {
@ -241,16 +241,16 @@ final class ContextResultPanelComponent: Component {
containerSize: itemFrame.size
)
if let itemView = visibleItem.view {
var animateIn = false
// var animateIn = false
if itemView.superview == nil {
animateIn = true
// animateIn = true
self.scrollView.addSubview(itemView)
}
itemTransition.setFrame(view: itemView, frame: itemFrame)
if animateIn, synchronousLoad {
itemView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
}
// if animateIn {
// 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 {
//let itemUpdated = self.component?.results != component.results
var transition = transition
let previousComponent = self.component
self.component = component
self.state = state
@ -306,6 +306,10 @@ final class ContextResultPanelComponent: Component {
containerSize: CGSize(width: availableSize.width, height: 1000.0)
)
if previousComponent?.results != component.results {
transition = transition.withUserData(PeerListItemComponent.TransitionHint(synchronousLoad: true))
}
let itemLayout = ItemLayout(
containerSize: CGSize(width: availableSize.width, height: minimizedHeight),
bottomInset: 0.0,

View File

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