mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix story drawing discarding
This commit is contained in:
parent
f49a6f63f3
commit
de9cf59c28
@ -197,6 +197,17 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
|
||||
}
|
||||
}
|
||||
|
||||
public func setup(with entities: [DrawingEntity]) {
|
||||
self.clear()
|
||||
|
||||
for entity in entities {
|
||||
if entity is DrawingMediaEntity {
|
||||
continue
|
||||
}
|
||||
self.add(entity, announce: false)
|
||||
}
|
||||
}
|
||||
|
||||
public static func encodeEntities(_ entities: [DrawingEntity], entitiesView: DrawingEntitiesView? = nil) -> [CodableDrawingEntity] {
|
||||
let entities = entities
|
||||
guard !entities.isEmpty else {
|
||||
@ -230,7 +241,14 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
|
||||
let entitiesData = self.entitiesData
|
||||
return entitiesData != initialEntitiesData
|
||||
} else {
|
||||
let filteredEntities = self.entities.filter { !$0.isMedia }
|
||||
let filteredEntities = self.entities.filter { entity in
|
||||
if entity.isMedia {
|
||||
return false
|
||||
} else if let stickerEntity = entity as? DrawingStickerEntity, case .dualVideoReference = stickerEntity.content {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
return !filteredEntities.isEmpty
|
||||
}
|
||||
}
|
||||
|
@ -3010,6 +3010,10 @@ public final class DrawingToolsInteraction {
|
||||
self.activate()
|
||||
}
|
||||
|
||||
public func reset() {
|
||||
self.drawingView.stateUpdated = { _ in }
|
||||
}
|
||||
|
||||
public func activate() {
|
||||
self.isActive = true
|
||||
|
||||
|
@ -391,6 +391,8 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, UIPencilInt
|
||||
}
|
||||
|
||||
public func setup(withDrawing drawingData: Data?) {
|
||||
self.undoStack = []
|
||||
self.redoStack = []
|
||||
if let drawingData = drawingData, let image = UIImage(data: drawingData) {
|
||||
self.hasOpaqueData = true
|
||||
|
||||
@ -406,11 +408,15 @@ public final class DrawingView: UIView, UIGestureRecognizerDelegate, UIPencilInt
|
||||
}
|
||||
self.layer.contents = image.cgImage
|
||||
self.updateInternalState()
|
||||
} else {
|
||||
self.drawingImage = nil
|
||||
self.layer.contents = nil
|
||||
self.updateInternalState()
|
||||
}
|
||||
}
|
||||
|
||||
var hasOpaqueData = false
|
||||
var drawingData: Data? {
|
||||
public var drawingData: Data? {
|
||||
guard !self.undoStack.isEmpty || self.hasOpaqueData else {
|
||||
return nil
|
||||
}
|
||||
|
@ -2737,6 +2737,9 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
||||
private var drawingScreen: DrawingScreen?
|
||||
private var stickerScreen: StickerPickerScreen?
|
||||
|
||||
private var previousDrawingData: Data?
|
||||
private var previousDrawingEntities: [DrawingEntity]?
|
||||
|
||||
func requestLayout(forceUpdate: Bool, transition: Transition) {
|
||||
guard let layout = self.validLayout else {
|
||||
return
|
||||
@ -2862,38 +2865,57 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
||||
self.controller?.requestLayout(transition: .immediate)
|
||||
return
|
||||
case .drawing:
|
||||
self.previousDrawingData = self.drawingView.drawingData
|
||||
self.previousDrawingEntities = self.entitiesView.entities
|
||||
|
||||
self.interaction?.deactivate()
|
||||
let controller = DrawingScreen(context: self.context, sourceHint: .storyEditor, size: self.previewContainerView.frame.size, originalSize: storyDimensions, isVideo: false, isAvatar: false, drawingView: self.drawingView, entitiesView: self.entitiesView, selectionContainerView: self.selectionContainerView, existingStickerPickerInputData: self.stickerPickerInputData)
|
||||
self.drawingScreen = controller
|
||||
self.drawingView.isUserInteractionEnabled = true
|
||||
|
||||
controller.requestDismiss = { [weak controller, weak self] in
|
||||
self?.drawingScreen = nil
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
self.drawingScreen = nil
|
||||
controller?.animateOut({
|
||||
controller?.dismiss()
|
||||
})
|
||||
self?.drawingView.isUserInteractionEnabled = false
|
||||
self?.animateInFromTool()
|
||||
self.drawingView.isUserInteractionEnabled = false
|
||||
self.animateInFromTool()
|
||||
|
||||
self?.interaction?.activate()
|
||||
self?.entitiesView.selectEntity(nil)
|
||||
self.interaction?.reset()
|
||||
|
||||
self.interaction?.activate()
|
||||
self.entitiesView.selectEntity(nil)
|
||||
|
||||
self.drawingView.setup(withDrawing: self.previousDrawingData)
|
||||
self.entitiesView.setup(with: self.previousDrawingEntities ?? [])
|
||||
|
||||
self.previousDrawingData = nil
|
||||
self.previousDrawingEntities = nil
|
||||
}
|
||||
controller.requestApply = { [weak controller, weak self] in
|
||||
self?.drawingScreen = nil
|
||||
guard let self else {
|
||||
return
|
||||
}
|
||||
self.drawingScreen = nil
|
||||
controller?.animateOut({
|
||||
controller?.dismiss()
|
||||
})
|
||||
self?.drawingView.isUserInteractionEnabled = false
|
||||
self?.animateInFromTool()
|
||||
self.drawingView.isUserInteractionEnabled = false
|
||||
self.animateInFromTool()
|
||||
|
||||
self.interaction?.reset()
|
||||
|
||||
if let result = controller?.generateDrawingResultData() {
|
||||
self?.mediaEditor?.setDrawingAndEntities(data: result.data, image: result.drawingImage, entities: result.entities)
|
||||
self.mediaEditor?.setDrawingAndEntities(data: result.data, image: result.drawingImage, entities: result.entities)
|
||||
} else {
|
||||
self?.mediaEditor?.setDrawingAndEntities(data: nil, image: nil, entities: [])
|
||||
self.mediaEditor?.setDrawingAndEntities(data: nil, image: nil, entities: [])
|
||||
}
|
||||
|
||||
self?.interaction?.activate()
|
||||
self?.entitiesView.selectEntity(nil)
|
||||
self.interaction?.activate()
|
||||
self.entitiesView.selectEntity(nil)
|
||||
}
|
||||
self.controller?.present(controller, in: .window(.root))
|
||||
self.animateOutToTool()
|
||||
|
Loading…
x
Reference in New Issue
Block a user