From e510e9d992bc2cde3a7f5fabd0ceb2e4789c08ca Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Thu, 12 Sep 2019 12:49:19 -0700 Subject: [PATCH] Fixes crash when displaying new updates --- AltStore/Components/CollapsingTextView.swift | 17 ++++++++++------- AltStore/My Apps/MyAppsViewController.swift | 9 ++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/AltStore/Components/CollapsingTextView.swift b/AltStore/Components/CollapsingTextView.swift index b5b73378..8deb38cb 100644 --- a/AltStore/Components/CollapsingTextView.swift +++ b/AltStore/Components/CollapsingTextView.swift @@ -58,30 +58,33 @@ class CollapsingTextView: UITextView let buttonFont = UIFont.systemFont(ofSize: font.pointSize, weight: .medium) self.moreButton.titleLabel?.font = buttonFont + let buttonY = (font.lineHeight + self.lineSpacing) * CGFloat(self.maximumNumberOfLines - 1) let size = self.moreButton.sizeThatFits(CGSize(width: 1000, height: 1000)) let moreButtonFrame = CGRect(x: self.bounds.width - self.moreButton.bounds.width, - y: self.bounds.height - self.moreButton.bounds.height - self.lineSpacing, + y: buttonY, width: size.width, height: font.lineHeight) self.moreButton.frame = moreButtonFrame if self.isCollapsed { - var exclusionFrame = moreButtonFrame - exclusionFrame.origin.y += self.moreButton.bounds.midY - exclusionFrame.size.width = self.bounds.width // Extra wide to make sure it wraps to next line. - self.textContainer.maximumNumberOfLines = self.maximumNumberOfLines - self.textContainer.exclusionPaths = [UIBezierPath(rect: exclusionFrame)] let maximumCollapsedHeight = font.lineHeight * CGFloat(self.maximumNumberOfLines) - if self.bounds.height > maximumCollapsedHeight + if self.intrinsicContentSize.height > maximumCollapsedHeight { + var exclusionFrame = moreButtonFrame + exclusionFrame.origin.y += self.moreButton.bounds.midY + exclusionFrame.size.width = self.bounds.width // Extra wide to make sure it wraps to next line. + self.textContainer.exclusionPaths = [UIBezierPath(rect: exclusionFrame)] + self.moreButton.isHidden = false } else { + self.textContainer.exclusionPaths = [] + self.moreButton.isHidden = true } } diff --git a/AltStore/My Apps/MyAppsViewController.swift b/AltStore/My Apps/MyAppsViewController.swift index fbdcf08f..affe6de3 100644 --- a/AltStore/My Apps/MyAppsViewController.swift +++ b/AltStore/My Apps/MyAppsViewController.swift @@ -333,9 +333,12 @@ private extension MyAppsViewController UIApplication.shared.applicationIconBadgeNumber = 0 } - UIView.performWithoutAnimation { - self.collectionView.reloadSections(IndexSet(integer: Section.updates.rawValue)) - } + if self.isViewLoaded + { + UIView.performWithoutAnimation { + self.collectionView.reloadSections(IndexSet(integer: Section.updates.rawValue)) + } + } } func refresh(_ installedApps: [InstalledApp], completionHandler: @escaping (Result<[String : Result], Error>) -> Void)