Skip to content

Commit

Permalink
#1899 (dashboard)
Browse files Browse the repository at this point in the history
- Adding Dashboard view controller to feed detail (WIP).
  • Loading branch information
Dejal committed Oct 30, 2024
1 parent c1b7fc3 commit cbc9be4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions clients/ios/Classes/BaseViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@property (nonatomic, readonly) BOOL isCompactWidth;
@property (nonatomic, readonly) BOOL isGrid;
@property (nonatomic, readonly) BOOL isGridView;
@property (nonatomic, readonly) BOOL isDashboard;
@property (nonatomic, readonly) BOOL isFeedShown;
@property (nonatomic, readonly) BOOL isStoryShown;

Expand Down
4 changes: 4 additions & 0 deletions clients/ios/Classes/BaseViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ - (BOOL)isGridView {
return self.appDelegate.detailViewController.storyTitlesInGridView;
}

- (BOOL)isDashboard {
return self.appDelegate.detailViewController.storyTitlesInDashboard;
}

- (BOOL)isFeedShown {
return appDelegate.storiesCollection.activeFeed != nil || appDelegate.storiesCollection.activeFolder != nil;
}
Expand Down
1 change: 1 addition & 0 deletions clients/ios/Classes/FeedDetailObjCViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
@property (nonatomic, readwrite) BOOL showImagePreview;
@property (nonatomic, readwrite) BOOL invalidateFontCache;
@property (nonatomic, readwrite) BOOL cameFromFeedsList;
@property (nonatomic, readwrite) NSInteger dashboardIndex;

//- (void)changedStoryHeight:(CGFloat)storyHeight;
- (void)loadingFeed;
Expand Down
6 changes: 4 additions & 2 deletions clients/ios/Classes/FeedDetailObjCViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ - (void)viewDidLoad {

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finishedLoadingFeedsNotification:) name:@"FinishedLoadingFeedsNotification" object:nil];

self.dashboardIndex = -1;

self.storyTitlesTable.backgroundColor = UIColorFromRGB(0xf4f4f4);
self.storyTitlesTable.separatorColor = UIColorFromRGB(0xE9E8E4);
if (@available(iOS 15.0, *)) {
Expand Down Expand Up @@ -1098,13 +1100,13 @@ - (void)fetchRiverPage:(int)page withCallback:(void(^)(void))callback {
if (self.pageFetching || self.pageFinished) return;
// NSLog(@"Fetching River in storiesCollection (pg. %ld): %@", (long)page, storiesCollection);

[self loadingFeed];

if ([storiesCollection.activeFolder isEqualToString:@"dashboard"]) {
NSLog(@"⚠️ Called fetchRiverPage with dashboard; this should never occur"); // log
return;
}

[self loadingFeed];

storiesCollection.feedPage = page;
self.pageFetching = YES;
NSInteger storyCount = storiesCollection.storyCount;
Expand Down
28 changes: 25 additions & 3 deletions clients/ios/Classes/FeedDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import SwiftUI
class FeedDetailViewController: FeedDetailObjCViewController {
lazy var gridViewController = makeGridViewController()

lazy var dashboardViewController = makeDashboardViewController()

lazy var storyCache = StoryCache()

enum SectionLayoutKind: Int, CaseIterable {
Expand All @@ -34,7 +36,7 @@ class FeedDetailViewController: FeedDetailObjCViewController {
}

var isExperimental: Bool {
return appDelegate.detailViewController.style == .experimental
return appDelegate.detailViewController.style == .experimental || isDashboard
}

var isSwiftUI: Bool {
Expand Down Expand Up @@ -76,6 +78,14 @@ class FeedDetailViewController: FeedDetailObjCViewController {
return gridViewController
}

private func makeDashboardViewController() -> UIHostingController<FeedDetailDashboardView> {
let dashboardView = FeedDetailDashboardView(feedDetailInteraction: self, cache: storyCache)
let dashboardViewController = UIHostingController(rootView: dashboardView)
dashboardViewController.view.translatesAutoresizingMaskIntoConstraints = false

return dashboardViewController
}

override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -90,6 +100,17 @@ class FeedDetailViewController: FeedDetailObjCViewController {
gridViewController.view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
])

addChild(dashboardViewController)
view.addSubview(dashboardViewController.view)
dashboardViewController.didMove(toParent: self)

NSLayoutConstraint.activate([
dashboardViewController.view.topAnchor.constraint(equalTo: view.topAnchor),
dashboardViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
dashboardViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
dashboardViewController.view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor)
])

changedLayout()
}

Expand Down Expand Up @@ -120,8 +141,9 @@ class FeedDetailViewController: FeedDetailObjCViewController {
// Make sure the view has loaded.
_ = view

storyTitlesTable.isHidden = !isLegacyTable
gridViewController.view.isHidden = isLegacyTable
storyTitlesTable.isHidden = !isLegacyTable || isDashboard
gridViewController.view.isHidden = isLegacyTable || isDashboard
dashboardViewController.view.isHidden = !isDashboard

print("🪿 changedLayout for \(isLegacyTable ? "legacy table" : "SwiftUI grid layout")")

Expand Down

0 comments on commit cbc9be4

Please sign in to comment.