瀏覽代碼

LocalNetworkView: Corrected size and scrolling behavior of the tableview

The heigt of the remotetableView gets now calculated dynamically and both views can now scroll when they get too big for the screen
Carola Nitz 7 年之前
父節點
當前提交
6046d9e8ef

+ 0 - 2
Sources/LocalNetworkConnectivity/RemoteNetworkDataSource.swift

@@ -35,8 +35,6 @@ public class RemoteNetworkDataSource: NSObject, UITableViewDataSource, UITableVi
 
     @objc weak var delegate: RemoteNetworkDataSourceDelegate?
 
-    @objc public let height = RemoteNetworkCellType.count * 55
-
     // MARK: - DataSource
     public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
         return RemoteNetworkCellType.count

+ 30 - 11
Sources/LocalNetworkConnectivity/VLCServerListViewController.m

@@ -50,7 +50,9 @@
     UIActivityIndicatorView *_activityIndicator;
     UITableView *_localNetworkTableView;
     UITableView *_remoteNetworkTableView;
+    UIScrollView *_scrollView;
     VLCRemoteNetworkDataSourceAndDelegate *_remoteNetworkDataSourceAndDelegate;
+    NSLayoutConstraint* _localNetworkHeight;
 }
 
 @end
@@ -61,6 +63,17 @@
 {
     [super loadView];
 
+    _scrollView = [[UIScrollView alloc] init];
+    _scrollView.translatesAutoresizingMaskIntoConstraints = NO;
+    [self.view addSubview:_scrollView];
+
+    [NSLayoutConstraint activateConstraints:@[
+                                              [_scrollView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor],
+                                              [_scrollView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor],
+                                              [_scrollView.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor],
+                                              [_scrollView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
+                                              ]];
+
     _remoteNetworkDataSourceAndDelegate = [VLCRemoteNetworkDataSourceAndDelegate new];
     _remoteNetworkDataSourceAndDelegate.delegate = self;
 
@@ -71,12 +84,9 @@
     _localNetworkTableView.dataSource = self;
     _localNetworkTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
     _localNetworkTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
-    _localNetworkTableView.bounces = NO;
     _localNetworkTableView.rowHeight = [VLCNetworkListCell heightOfCell];
     _localNetworkTableView.separatorColor = PresentationTheme.current.colors.background;
 
-    //TODO: this is very much work in progress we need to accomodate the wificell for now
-    //When we know how many cells go above the the local servers we should create and move this into a headerview of the localNetworkTable
     _remoteNetworkTableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
     _remoteNetworkTableView.translatesAutoresizingMaskIntoConstraints = NO;
     _remoteNetworkTableView.backgroundColor = PresentationTheme.current.colors.background;
@@ -101,20 +111,25 @@
     _activityIndicator.hidesWhenStopped = YES;
     [_localNetworkTableView addSubview:_activityIndicator];
 
-    [self.view addSubview:_localNetworkTableView];
-    [self.view addSubview:_remoteNetworkTableView];
+    [_scrollView addSubview:_localNetworkTableView];
+    [_scrollView addSubview:_remoteNetworkTableView];
+
+    [_remoteNetworkTableView layoutIfNeeded];
+    CGSize contentSize = [_remoteNetworkTableView contentSize];
+    _localNetworkHeight = [_localNetworkTableView.heightAnchor constraintEqualToConstant:_localNetworkTableView.contentSize.height];
+
     [NSLayoutConstraint activateConstraints:@[
                                               [_remoteNetworkTableView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor],
                                               [_remoteNetworkTableView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor],
-                                              [_remoteNetworkTableView.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor],
-                                              //TODO: this should be rather be done dynamically with contenthugging of the tableview since the cellheights might vary
-                                              [_remoteNetworkTableView.heightAnchor constraintEqualToConstant:_remoteNetworkDataSourceAndDelegate.height],
+                                              [_remoteNetworkTableView.topAnchor constraintEqualToAnchor:_scrollView.topAnchor],
+                                              [_remoteNetworkTableView.heightAnchor constraintEqualToConstant:contentSize.height],
                                               [_localNetworkTableView.topAnchor constraintEqualToAnchor:_remoteNetworkTableView.bottomAnchor],
                                               [_localNetworkTableView.leftAnchor constraintEqualToAnchor:self.view.leftAnchor],
                                               [_localNetworkTableView.rightAnchor constraintEqualToAnchor:self.view.rightAnchor],
-                                              [_localNetworkTableView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
+                                              [_localNetworkTableView.bottomAnchor constraintEqualToAnchor:_scrollView.bottomAnchor],
+                                              _localNetworkHeight
                                               ]];
-    self.view.backgroundColor = PresentationTheme.current.colors.background;
+    _scrollView.backgroundColor = PresentationTheme.current.colors.background;
 }
 
 - (void)viewDidLoad
@@ -268,6 +283,8 @@
 - (void)themeDidChange
 {
     _localNetworkTableView.backgroundColor = PresentationTheme.current.colors.background;
+    _remoteNetworkTableView.backgroundColor = PresentationTheme.current.colors.background;
+    _scrollView.backgroundColor = PresentationTheme.current.colors.background;
     _localNetworkTableView.separatorColor = PresentationTheme.current.colors.background;
     _refreshControl.backgroundColor = PresentationTheme.current.colors.background;
 }
@@ -282,7 +299,7 @@
 
 #pragma mark - Refresh
 
--(void)handleRefresh
+- (void)handleRefresh
 {
     //set the title while refreshing
     _refreshControl.attributedTitle = [[NSAttributedString alloc]initWithString:NSLocalizedString(@"LOCAL_SERVER_REFRESH",nil)];
@@ -328,6 +345,8 @@
 - (void)discoveryFoundSomethingNew
 {
     [_localNetworkTableView reloadData];
+    [_localNetworkTableView layoutIfNeeded];
+    _localNetworkHeight.constant = _localNetworkTableView.contentSize.height;
 }
 
 #pragma mark - custom table view appearance

+ 0 - 1
Sources/VLCWiFiUploadTableViewCell.m

@@ -56,7 +56,6 @@
 
     self.textLabel.text = NSLocalizedString(@"WEBINTF_TITLE", nil);
     self.detailTextLabel.text = NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", nil);
-    self.detailTextLabel.translatesAutoresizingMaskIntoConstraints = NO;
     self.detailTextLabel.numberOfLines = 0;
 
     self.serverToggle = [[UISwitch alloc] init];