From 86dce0921e91e65c86f4164518d78230d9a3c85d Mon Sep 17 00:00:00 2001 From: Levitating Pineapple Date: Thu, 26 Sep 2024 20:43:59 +0300 Subject: [PATCH] fix layout loop; add upper animation speed constraint --- .../Views/Helpers/SheetRepresentable.swift | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/apps/ios/Shared/Views/Helpers/SheetRepresentable.swift b/apps/ios/Shared/Views/Helpers/SheetRepresentable.swift index a40f4a687a..45639090ec 100644 --- a/apps/ios/Shared/Views/Helpers/SheetRepresentable.swift +++ b/apps/ios/Shared/Views/Helpers/SheetRepresentable.swift @@ -70,6 +70,7 @@ struct SheetRepresentable: UIViewControllerRepresentable { addChild(hostingController) hostingController.didMove(toParent: self) if let sheet = hostingController.view { + sheet.isHidden = true sheet.clipsToBounds = true sheet.layer.cornerRadius = 10 sheet.layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMinYCorner] @@ -77,20 +78,21 @@ struct SheetRepresentable: UIViewControllerRepresentable { sheet.translatesAutoresizingMaskIntoConstraints = false view.addSubview(sheet) NSLayoutConstraint.activate([ - hostingController.view.topAnchor.constraint(equalTo: view.bottomAnchor), hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor), - hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor) + hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor), + hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor), ]) animator.pausesOnCompletion = true animator.scrubsLinearly = true - DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [weak self] in - if let self { - self.animator.addAnimations { - sheet.transform = CGAffineTransform(translationX: 0, y: -self.sheetHeight) - self.view.backgroundColor = .black.withAlphaComponent(0.3) - } - } - } + } + } + + override func viewDidAppear(_ animated: Bool) { + hostingController.view.transform = CGAffineTransform(translationX: 0, y: self.sheetHeight) + hostingController.view.isHidden = false + self.animator.addAnimations { + self.hostingController.view.transform = .identity + self.view.backgroundColor = .black.withAlphaComponent(0.3) } } @@ -108,7 +110,7 @@ struct SheetRepresentable: UIViewControllerRepresentable { animator.isReversed = (velocity - (animator.fractionComplete - 0.5) * 100).sign == .plus let defaultVelocity = sheetHeight / sheetAnimationDuration let fractionRemaining = 1 - animator.fractionComplete - let durationFactor = min(fractionRemaining / (abs(velocity) / defaultVelocity), 1) + let durationFactor = min(max(fractionRemaining / (abs(velocity) / defaultVelocity), 0.2), 1) animator.continueAnimation(withTimingParameters: nil, durationFactor: durationFactor) DispatchQueue.main.asyncAfter(deadline: .now() + sheetAnimationDuration) { self.representer.isPresented = !self.animator.isReversed