@@ -346,7 +346,7 @@ import AutomatticTracks
346346 // the view being fully setup in viewDidLoad.
347347 // See: https://github.com/wordpress-mobile/WordPress-iOS/issues/4419
348348 if didSetupView {
349- refreshTableViewHeaderLayout ( )
349+ tableView . sizeToFitHeaderView ( )
350350 }
351351 }
352352
@@ -529,7 +529,6 @@ import AutomatticTracks
529529 configureStreamHeader ( )
530530 tableView. setContentOffset ( CGPoint . zero, animated: false )
531531 content. refresh ( )
532- refreshTableViewHeaderLayout ( )
533532
534533 if synchronize {
535534 syncIfAppropriate ( )
@@ -572,10 +571,7 @@ import AutomatticTracks
572571
573572 private func configureCloseButtonIfNeeded( ) {
574573 if isModal ( ) {
575- navigationItem. leftBarButtonItem = UIBarButtonItem ( image: . gridicon( . cross) ,
576- style: . plain,
577- target: self ,
578- action: #selector( closeButtonTapped) )
574+ navigationItem. leftBarButtonItem = UIBarButtonItem ( image: UIImage ( systemName: " xmark " ) , style: . plain, target: self , action: #selector( closeButtonTapped) )
579575 }
580576 }
581577
@@ -585,56 +581,6 @@ import AutomatticTracks
585581
586582 // MARK: - Instance Methods
587583
588- /// Retrieve an instance of the specified post from the main NSManagedObjectContext.
589- ///
590- /// - Parameters:
591- /// - post: The post to retrieve.
592- ///
593- /// - Returns: The post fetched from the main context or nil if the post does not exist in the context.
594- ///
595- private func postInMainContext( _ post: ReaderPost ) -> ReaderPost ? {
596- guard let post = ( try ? ContextManager . sharedInstance ( ) . mainContext. existingObject ( with: post. objectID) ) as? ReaderPost else {
597- DDLogError ( " Error retrieving an exsting post from the main context by its object ID. " )
598- return nil
599- }
600- return post
601- }
602-
603- /// Refreshes the layout of the header. Required for sizing the tableHeaderView according
604- /// to its intrinsic content layout, and after major layout changes on the viewcontroller itself.
605- ///
606- private func refreshTableViewHeaderLayout( ) {
607- guard let headerView = tableView. tableHeaderView else {
608- return
609- }
610-
611- // The tableView may need to layout, run this layout now, if needed.
612- // This ensures the proper margins, such as readable margins, are
613- // inherited and calculated by the headerView.
614- tableView. layoutIfNeeded ( )
615-
616- // Start with the provided UILayoutFittingCompressedSize to let iOS handle its own magic
617- // number for a "compressed" height, meaning we want our fitting size to be the minimal height.
618- var fittingSize = UIView . layoutFittingCompressedSize
619-
620- // Set the width to the tableView's width since this is a known width for the headerView.
621- // Otherwise, the layout will try and adopt 'any' width and may break based on the how
622- // the constraints are set up in the nib.
623- fittingSize. width = tableView. frame. size. width
624-
625- // Require horizontal fitting since our width is known.
626- // Use the lower fitting size priority as we want to minimize our height consumption
627- // according to the layout's contraints and intrinsic size.
628- let size = headerView. systemLayoutSizeFitting ( fittingSize,
629- withHorizontalFittingPriority: . required,
630- verticalFittingPriority: . fittingSizeLevel)
631- // Update the tableHeaderView itself. Classic.
632- var headerFrame = headerView. frame
633- headerFrame. size. height = size. height
634- headerView. frame = headerFrame
635- tableView. tableHeaderView = headerView
636- }
637-
638584 /// Scrolls to the top of the list of posts.
639585 @objc func scrollViewToTop( ) {
640586 guard tableView. numberOfRows ( inSection: . zero) > 0 else {
@@ -1481,35 +1427,31 @@ extension ReaderStreamViewController: WPTableViewHandlerDelegate {
14811427 }
14821428 return
14831429 }
1484-
1485- guard let apost = posts [ safe: indexPath. row] else {
1430+ guard let post = posts [ safe: indexPath. row] else {
14861431 wpAssertionFailure ( " invalid_index_path " )
14871432 return
14881433 }
1489-
1490- didSelectPost ( apost, at: indexPath)
1434+ didSelectPost ( post, at: indexPath)
14911435 }
14921436
1493- func didSelectPost( _ apost: ReaderPost , at indexPath: IndexPath ) {
1494- guard let post = postInMainContext ( apost) else {
1495- return
1496- }
1437+ func didSelectPost( _ post: ReaderPost , at indexPath: IndexPath ) {
1438+ wpAssert ( post. managedObjectContext == viewContext)
14971439
14981440 if post. isKind ( of: ReaderGapMarker . self) {
14991441 syncFillingGap ( indexPath)
15001442 return
15011443 }
15021444
1503- if recentlyBlockedSitePostObjectIDs. contains ( apost . objectID) {
1504- unblockSiteForPost ( apost )
1445+ if recentlyBlockedSitePostObjectIDs. contains ( post . objectID) {
1446+ unblockSiteForPost ( post )
15051447 return
15061448 }
15071449
15081450 if let topic = post. topic, ReaderHelpers . isTopicSearchTopic ( topic) {
15091451 WPAppAnalytics . track ( . readerSearchResultTapped)
15101452
15111453 // We can use `if let` when `ReaderPost` adopts nullability.
1512- let railcar = apost . railcarDictionary ( )
1454+ let railcar = post . railcarDictionary ( )
15131455 if railcar != nil {
15141456 WPAppAnalytics . trackTrainTracksInteraction ( . readerSearchResultTapped, withProperties: railcar)
15151457 }
0 commit comments