Adjust input activation

This commit is contained in:
Ali 2023-06-26 17:38:22 +03:00
parent f0809b0aae
commit 4a3292df29
5 changed files with 54 additions and 15 deletions

View File

@ -105,6 +105,9 @@ func telegramMediaFileAttributesFromApiAttributes(_ attributes: [Api.DocumentAtt
if (flags & (1 << 1)) != 0 { if (flags & (1 << 1)) != 0 {
videoFlags.insert(.supportsStreaming) videoFlags.insert(.supportsStreaming)
} }
if (flags & (1 << 3)) != 0 {
videoFlags.insert(.isSilent)
}
result.append(.Video(duration: Double(duration), size: PixelDimensions(width: w, height: h), flags: videoFlags, preloadSize: preloadSize)) result.append(.Video(duration: Double(duration), size: PixelDimensions(width: w, height: h), flags: videoFlags, preloadSize: preloadSize))
case let .documentAttributeAudio(flags, duration, title, performer, waveform): case let .documentAttributeAudio(flags, duration, title, performer, waveform):
let isVoice = (flags & (1 << 10)) != 0 let isVoice = (flags & (1 << 10)) != 0

View File

@ -569,6 +569,9 @@ func inputDocumentAttributesFromFileAttributes(_ fileAttributes: [TelegramMediaF
if preloadSize != nil { if preloadSize != nil {
flags |= (1 << 2) flags |= (1 << 2)
} }
if videoFlags.contains(.isSilent) {
flags |= (1 << 3)
}
attributes.append(.documentAttributeVideo(flags: flags, duration: duration, w: Int32(size.width), h: Int32(size.height), preloadPrefixSize: preloadSize)) attributes.append(.documentAttributeVideo(flags: flags, duration: duration, w: Int32(size.width), h: Int32(size.height), preloadPrefixSize: preloadSize))
case let .Audio(isVoice, duration, title, performer, waveform): case let .Audio(isVoice, duration, title, performer, waveform):

View File

@ -188,6 +188,7 @@ public struct TelegramMediaVideoFlags: OptionSet {
public static let instantRoundVideo = TelegramMediaVideoFlags(rawValue: 1 << 0) public static let instantRoundVideo = TelegramMediaVideoFlags(rawValue: 1 << 0)
public static let supportsStreaming = TelegramMediaVideoFlags(rawValue: 1 << 1) public static let supportsStreaming = TelegramMediaVideoFlags(rawValue: 1 << 1)
public static let isSilent = TelegramMediaVideoFlags(rawValue: 1 << 3)
} }
public struct StickerMaskCoords: PostboxCoding, Equatable { public struct StickerMaskCoords: PostboxCoding, Equatable {

View File

@ -392,30 +392,46 @@ private final class StoryContainerScreenComponent: Component {
let translation = recognizer.translation(in: self) let translation = recognizer.translation(in: self)
self.verticalPanState = ItemSetPanState(fraction: max(-1.0, min(1.0, translation.y / self.bounds.height)), didBegin: true) self.verticalPanState = ItemSetPanState(fraction: max(-1.0, min(1.0, translation.y / self.bounds.height)), didBegin: true)
self.state?.updated(transition: .immediate) self.state?.updated(transition: .immediate)
case .cancelled, .ended:
let translation = recognizer.translation(in: self)
let velocity = recognizer.velocity(in: self)
self.verticalPanState = nil if translation.y < -40.0 {
var updateState = true
if translation.y > 100.0 || velocity.y > 10.0 {
self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring)))
self.environment?.controller()?.dismiss()
} else if translation.y < -100.0 || velocity.y < -40.0 {
if let component = self.component, let stateValue = component.content.stateValue, let slice = stateValue.slice, let itemSetView = self.visibleItemSetViews[slice.peer.id] { if let component = self.component, let stateValue = component.content.stateValue, let slice = stateValue.slice, let itemSetView = self.visibleItemSetViews[slice.peer.id] {
if let itemSetComponentView = itemSetView.view.view as? StoryItemSetContainerComponent.View { if let itemSetComponentView = itemSetView.view.view as? StoryItemSetContainerComponent.View {
if itemSetComponentView.activateInput() { if let activateInputWhileDragging = itemSetComponentView.activateInputWhileDragging() {
updateState = false activateInputWhileDragging()
self.verticalPanState = nil
recognizer.state = .cancelled
self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring)))
} }
} }
} }
}
case .cancelled, .ended:
if self.verticalPanState != nil {
let translation = recognizer.translation(in: self)
let velocity = recognizer.velocity(in: self)
if updateState || "".isEmpty { self.verticalPanState = nil
var updateState = true
if translation.y > 100.0 || velocity.y > 10.0 {
self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring)))
self.environment?.controller()?.dismiss()
} else if translation.y < -100.0 || velocity.y < -40.0 {
if let component = self.component, let stateValue = component.content.stateValue, let slice = stateValue.slice, let itemSetView = self.visibleItemSetViews[slice.peer.id] {
if let itemSetComponentView = itemSetView.view.view as? StoryItemSetContainerComponent.View {
if itemSetComponentView.activateInput() {
updateState = false
}
}
}
if updateState || "".isEmpty {
self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring)))
}
} else {
self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring))) self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring)))
} }
} else {
self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring)))
} }
default: default:
break break

View File

@ -969,6 +969,22 @@ public final class StoryItemSetContainerComponent: Component {
return false return false
} }
func activateInputWhileDragging() -> (() -> Void)? {
guard let component = self.component else {
return nil
}
if component.slice.peer.id == component.context.account.peerId {
} else {
if let inputPanelView = self.inputPanel.view as? MessageInputPanelComponent.View {
return { [weak inputPanelView] in
inputPanelView?.activateInput()
}
}
}
return nil
}
func animateIn(transitionIn: StoryContainerScreen.TransitionIn) { func animateIn(transitionIn: StoryContainerScreen.TransitionIn) {
self.closeButton.layer.animateScale(from: 0.001, to: 1.0, duration: 0.2, delay: 0.12, timingFunction: kCAMediaTimingFunctionSpring) self.closeButton.layer.animateScale(from: 0.001, to: 1.0, duration: 0.2, delay: 0.12, timingFunction: kCAMediaTimingFunctionSpring)