Skip to content

Commit

Permalink
Fix crash in UserProfileSheetViewController
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Nov 19, 2024
1 parent d29cf66 commit 48a31aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -919,10 +919,11 @@ private extension NotificationDetailsViewController {
func displayUserProfile(_ user: LikeUser, from indexPath: IndexPath) {
let userProfileVC = UserProfileSheetViewController(user: user)
userProfileVC.blogUrlPreviewedSource = "notif_like_list_user_profile"
let bottomSheet = BottomSheetViewController(childViewController: userProfileVC)

let sourceView = tableView.cellForRow(at: indexPath) ?? view
bottomSheet.show(from: self, sourceView: sourceView)
userProfileVC.modalPresentationStyle = .popover
userProfileVC.popoverPresentationController?.sourceView = tableView.cellForRow(at: indexPath) ?? view
userProfileVC.popoverPresentationController?.adaptiveSheetPresentationController.prefersGrabberVisible = true
userProfileVC.popoverPresentationController?.adaptiveSheetPresentationController.detents = [.medium()]
present(userProfileVC, animated: true)

WPAnalytics.track(.userProfileSheetShown, properties: ["source": "like_notification_list"])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ private extension ReaderDetailLikesListController {
func displayUserProfile(_ user: LikeUser, from indexPath: IndexPath) {
let userProfileVC = UserProfileSheetViewController(user: user)
userProfileVC.blogUrlPreviewedSource = "reader_like_list_user_profile"
let bottomSheet = BottomSheetViewController(childViewController: userProfileVC)
let sourceView = tableView.cellForRow(at: indexPath) ?? view
bottomSheet.show(from: self, sourceView: sourceView)
userProfileVC.modalPresentationStyle = .popover
userProfileVC.popoverPresentationController?.sourceView = tableView.cellForRow(at: indexPath) ?? view
userProfileVC.popoverPresentationController?.adaptiveSheetPresentationController.prefersGrabberVisible = true
userProfileVC.popoverPresentationController?.adaptiveSheetPresentationController.detents = [.medium()]
present(userProfileVC, animated: true)

WPAnalytics.track(.userProfileSheetShown, properties: ["source": "like_reader_list"])
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,22 @@ class UserProfileSheetViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()

configureTable()
registerTableCells()

tableView.contentInset.top = 24 // For grabber and extra inset in popover
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

var size = tableView.contentSize

// Apply a slight padding to the bottom of the view to give it some space to breathe
// when being presented in a popover or bottom sheet
let bottomPadding = WPDeviceIdentification.isiPad() ? Constants.iPadBottomPadding : Constants.iPhoneBottomPadding
size.height += bottomPadding

size.height += tableView.contentInset.top
preferredContentSize = size
}
}

// MARK: - DrawerPresentable Extension

extension UserProfileSheetViewController: DrawerPresentable {

var collapsedHeight: DrawerHeight {
if traitCollection.verticalSizeClass == .compact {
return .maxHeight
}

// Force the table layout to update so the Bottom Sheet gets the right height.
tableView.layoutIfNeeded()
return .intrinsicHeight
}

var scrollableView: UIScrollView? {
return tableView
}

var allowsUserTransition: Bool {
false
}

}

// MARK: - UITableViewDataSource methods

extension UserProfileSheetViewController {
Expand Down Expand Up @@ -212,8 +186,5 @@ private extension UserProfileSheetViewController {
enum Constants {
static let userInfoSection = 0
static let siteSectionTitle = NSLocalizedString("Site", comment: "Header for a single site, shown in Notification user profile.").localizedUppercase
static let iPadBottomPadding: CGFloat = 10
static let iPhoneBottomPadding: CGFloat = 40
}

}

0 comments on commit 48a31aa

Please sign in to comment.