Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in UserProfileSheetViewController #23833

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting rid of one more incorrect use of WPDeviceIdentification.isiPad() 🥳

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
}

}