Various fixes

This commit is contained in:
Ilya Laktyushin 2022-07-10 20:35:05 +02:00
parent fc609c6c70
commit aa46e81a49
5 changed files with 140 additions and 138 deletions

View File

@ -38,6 +38,7 @@ final class AttachmentContainer: ASDisplayNode, UIGestureRecognizerDelegate {
var controllerRemoved: ((ViewController) -> Void)?
var shouldCancelPanGesture: (() -> Bool)?
var requestDismiss: (() -> Void)?
var updateModalProgress: ((CGFloat, ContainedViewLayoutTransition) -> Void)?
@ -236,6 +237,7 @@ final class AttachmentContainer: ASDisplayNode, UIGestureRecognizerDelegate {
if !self.isExpanded, translation > 40.0, let shouldCancelPanGesture = self.shouldCancelPanGesture, shouldCancelPanGesture() {
self.cancelPanGesture()
self.requestDismiss?()
return
}
@ -284,8 +286,13 @@ final class AttachmentContainer: ASDisplayNode, UIGestureRecognizerDelegate {
let offset = currentTopInset + panOffset
let topInset: CGFloat = edgeTopInset
var ignoreDismiss = false
if let shouldCancelPanGesture = self.shouldCancelPanGesture, shouldCancelPanGesture() {
ignoreDismiss = true
}
var dismissing = false
if bounds.minY < -60 || (bounds.minY < 0.0 && velocity.y > 300.0) || (self.isExpanded && bounds.minY.isZero && velocity.y > 1800.0) {
if (bounds.minY < -60 || (bounds.minY < 0.0 && velocity.y > 300.0) || (self.isExpanded && bounds.minY.isZero && velocity.y > 1800.0)) && !ignoreDismiss {
self.interactivelyDismissed?()
dismissing = true
} else if self.isExpanded {

View File

@ -320,11 +320,6 @@ public class AttachmentController: ViewController {
self.container.shouldCancelPanGesture = { [weak self] in
if let strongSelf = self, let currentController = strongSelf.currentControllers.last {
if !currentController.shouldDismissImmediately() {
currentController.requestDismiss { [weak self] in
if let strongSelf = self {
strongSelf.controller?.dismiss(animated: true)
}
}
return true
} else {
return false
@ -334,6 +329,16 @@ public class AttachmentController: ViewController {
}
}
self.container.requestDismiss = { [weak self] in
if let strongSelf = self, let currentController = strongSelf.currentControllers.last {
currentController.requestDismiss { [weak self] in
if let strongSelf = self {
strongSelf.controller?.dismiss(animated: true)
}
}
}
}
self.panel.selectionChanged = { [weak self] type in
if let strongSelf = self {
return strongSelf.switchToController(type)

View File

@ -50,11 +50,11 @@ private func generateDiffuseTexture() -> UIImage {
class GiftAvatarComponent: Component {
let context: AccountContext
let peer: EnginePeer
let peer: EnginePeer?
let isVisible: Bool
let hasIdleAnimations: Bool
init(context: AccountContext, peer: EnginePeer, isVisible: Bool, hasIdleAnimations: Bool) {
init(context: AccountContext, peer: EnginePeer?, isVisible: Bool, hasIdleAnimations: Bool) {
self.context = context
self.peer = peer
self.isVisible = isVisible
@ -62,7 +62,7 @@ class GiftAvatarComponent: Component {
}
static func ==(lhs: GiftAvatarComponent, rhs: GiftAvatarComponent) -> Bool {
return lhs.isVisible == rhs.isVisible && lhs.hasIdleAnimations == rhs.hasIdleAnimations
return lhs.peer == rhs.peer && lhs.isVisible == rhs.isVisible && lhs.hasIdleAnimations == rhs.hasIdleAnimations
}
final class View: UIView, SCNSceneRendererDelegate, ComponentTaggedView {
@ -276,7 +276,9 @@ class GiftAvatarComponent: Component {
self.hasIdleAnimations = component.hasIdleAnimations
let avatarSize = CGSize(width: 100.0, height: 100.0)
self.avatarNode.setSignal(peerAvatarCompleteImage(account: component.context.account, peer: component.peer, size: avatarSize, font: avatarPlaceholderFont(size: 43.0), fullSize: true))
if let peer = component.peer {
self.avatarNode.setSignal(peerAvatarCompleteImage(account: component.context.account, peer: peer, size: avatarSize, font: avatarPlaceholderFont(size: 43.0), fullSize: true))
}
self.avatarNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - avatarSize.width) / 2.0), y: 63.0), size: avatarSize)
return availableSize

View File

@ -500,14 +500,14 @@ private final class PremiumGiftScreenContentComponent: CombinedComponent {
typealias EnvironmentType = (ViewControllerComponentContainer.Environment, ScrollChildEnvironment)
let context: AccountContext
let peer: EnginePeer
let products: [InAppPurchaseManager.Product]
let selectedProductId: String
let peer: EnginePeer?
let products: [InAppPurchaseManager.Product]?
let selectedProductId: String?
let present: (ViewController) -> Void
let selectProduct: (String) -> Void
init(context: AccountContext, peer: EnginePeer, products: [InAppPurchaseManager.Product], selectedProductId: String, present: @escaping (ViewController) -> Void, selectProduct: @escaping (String) -> Void) {
init(context: AccountContext, peer: EnginePeer?, products: [InAppPurchaseManager.Product]?, selectedProductId: String?, present: @escaping (ViewController) -> Void, selectProduct: @escaping (String) -> Void) {
self.context = context
self.peer = peer
self.products = products
@ -583,7 +583,6 @@ private final class PremiumGiftScreenContentComponent: CombinedComponent {
let textColor = theme.list.itemPrimaryTextColor
let subtitleColor = theme.list.itemSecondaryTextColor
// let arrowColor = theme.list.disclosureArrowColor
let textFont = Font.regular(15.0)
let boldTextFont = Font.semibold(15.0)
@ -594,7 +593,7 @@ private final class PremiumGiftScreenContentComponent: CombinedComponent {
let text = text.update(
component: MultilineTextComponent(
text: .markdown(
text: strings.Premium_Gift_Description(component.peer.compactDisplayTitle).string,
text: strings.Premium_Gift_Description(component.peer?.compactDisplayTitle ?? "").string,
attributes: markdownAttributes
),
horizontalAlignment: .center,
@ -620,7 +619,8 @@ private final class PremiumGiftScreenContentComponent: CombinedComponent {
]
var i = 0
for product in component.products {
if let products = component.products {
for product in products {
let monthsCount: Int
let giftTitle: String
let discount: String
@ -667,6 +667,7 @@ private final class PremiumGiftScreenContentComponent: CombinedComponent {
)
i += 1
}
}
let section = section.update(
component: ProductGroupComponent(
@ -960,14 +961,13 @@ private final class PremiumGiftScreenComponent: CombinedComponent {
.position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height / 2.0))
)
if let peer = state.peer, let products = state.products, let selectedProductId = state.selectedProductId {
let scrollContent = scrollContent.update(
component: ScrollComponent<EnvironmentType>(
content: AnyComponent(PremiumGiftScreenContentComponent(
context: context.component.context,
peer: peer,
products: products,
selectedProductId: selectedProductId,
peer: state.peer,
products: state.products,
selectedProductId: state.selectedProductId,
present: context.component.present,
selectProduct: { [weak state] productId in
state?.selectProduct(id: productId)
@ -997,7 +997,6 @@ private final class PremiumGiftScreenComponent: CombinedComponent {
context.add(scrollContent
.position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height / 2.0))
)
}
let topPanelAlpha: CGFloat
let titleOffset: CGFloat
@ -1019,11 +1018,10 @@ private final class PremiumGiftScreenComponent: CombinedComponent {
titleAlpha = 1.0
}
if let peer = context.state.peer {
let star = star.update(
component: GiftAvatarComponent(
context: context.component.context,
peer: peer,
peer: context.state.peer,
isVisible: starIsVisible,
hasIdleAnimations: state.hasIdleAnimations
),
@ -1035,7 +1033,6 @@ private final class PremiumGiftScreenComponent: CombinedComponent {
.position(CGPoint(x: context.availableSize.width / 2.0, y: topInset + star.size.height / 2.0 - 30.0 - titleOffset * titleScale))
.scale(titleScale)
)
}
context.add(topPanel
.position(CGPoint(x: context.availableSize.width / 2.0, y: topPanel.size.height / 2.0))
@ -1252,26 +1249,15 @@ public final class PremiumGiftScreen: ViewControllerComponentContainer {
}
}
// presentImpl = { [weak self] c in
// self?.present(c, in: .window(.root))
// }
pushImpl = { [weak self] c in
self?.push(c)
}
completionImpl = { [weak self] duration in
if let strongSelf = self, let navigationController = strongSelf.navigationController as? NavigationController {
// let introController = PremiumIntroScreen(context: context, source: .gift(from: context.account.peerId, to: peerId, duration: duration))
var controllers = navigationController.viewControllers
controllers = controllers.filter { !($0 is PeerInfoScreen) && !($0 is PremiumGiftScreen) }
navigationController.setViewControllers(controllers, animated: true)
Queue.mainQueue().after(2.8, {
if let topController = navigationController.viewControllers.last {
topController.view.addSubview(ConfettiView(frame: topController.view.bounds))
}
})
}
}
}

View File

@ -650,21 +650,23 @@ final class ShareControllerNode: ViewControllerTracingNode, UIScrollViewDelegate
let doneImpl: (Bool) -> Void = { [weak self] shouldDelay in
let minDelay: Double = shouldDelay ? 0.9 : 0.6
let delay: Double
let hapticDelay: Double
if let strongSelf = self, let contentNode = strongSelf.contentNode as? ShareProlongedLoadingContainerNode {
delay = contentNode.completionDuration
if shouldDelay {
Queue.mainQueue().after(delay - 1.5, {
if strongSelf.hapticFeedback == nil {
strongSelf.hapticFeedback = HapticFeedback()
}
strongSelf.hapticFeedback?.success()
})
}
hapticDelay = shouldDelay ? delay - 1.5 : delay
} else {
delay = max(minDelay, (timestamp + minDelay) - CACurrentMediaTime())
hapticDelay = delay
}
Queue.mainQueue().after(hapticDelay, {
if self?.hapticFeedback == nil {
self?.hapticFeedback = HapticFeedback()
}
self?.hapticFeedback?.success()
})
Queue.mainQueue().after(delay, {
self?.animateOut(shared: true, completion: {
self?.dismiss?(true)