Browse Source

Fix display of older iOS versions

Signed-off-by: Philippe Weidmann <philippe.weidmann@infomaniak.com>
Philippe Weidmann 4 years ago
parent
commit
ae422015b8

+ 19 - 2
iOSClient/Main/CCMain+Swift.swift

@@ -10,8 +10,25 @@ import Foundation
 
 extension CCMain {
 
-    @objc func updateNavBarShadow(_ hide: Bool) {
-        if hide {
+    @objc func updateNavBarShadow(_ scrollView: UIScrollView) {
+        print(scrollView.contentOffset.y)
+        if(self.searchController.isActive && scrollView.contentOffset.y > 44) {
+            let searchBar = self.searchController.searchBar
+            if(searchBar.layer.sublayers!.count < 2) {
+                let border = CALayer()
+
+                border.backgroundColor = UIColor.lightGray.withAlphaComponent(0.6).cgColor
+                border.frame = CGRect(x: 0, y: searchBar.frame.height - 1, width: searchBar.frame.size.width, height: 1)
+                searchBar.layer.addSublayer(border)
+            }
+        } else {
+            let searchBar = self.searchController.searchBar
+            if(searchBar.layer.sublayers!.count > 1) {
+                searchBar.layer.sublayers?.removeLast()
+            }
+        }
+
+        if (scrollView.contentOffset.y > self.viewRichWorkspace.topView.frame.size.height) {
             if #available(iOS 13.0, *) {
                 let navBarAppearance = UINavigationBarAppearance()
                 navBarAppearance.configureWithOpaqueBackground()

+ 0 - 1
iOSClient/Main/CCMain.h

@@ -52,7 +52,6 @@
 @property (nonatomic, strong) tableMetadata *metadataForPushDetail;
 @property (nonatomic, strong) NSString *selectorForPushDetail;
 
-@property (nonatomic, strong) UIView *headerView;
 @property (nonatomic, strong) UIButton *sortButton;
 
 @property (nonatomic, strong) NSString *serverUrl;

+ 13 - 23
iOSClient/Main/CCMain.m

@@ -141,8 +141,6 @@
     self.searchController.searchResultsUpdater = self;
     self.searchController.dimsBackgroundDuringPresentation = NO;
     self.searchController.searchBar.translucent = NO;
-    self.automaticallyAdjustsScrollViewInsets = false;
-    [self.searchController.searchBar sizeToFit];
     self.searchController.searchBar.backgroundColor = NCBrandColor.sharedInstance.backgroundView;
     self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
     UIButton *searchButton = self.searchController.searchBar.subviews.firstObject.subviews.lastObject;
@@ -154,7 +152,6 @@
         searchTextView.textColor = NCBrandColor.sharedInstance.textView;
     }
     
-    self.headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, self.searchController.searchBar.frame.size.height + 40)];
             
     // Load Rich Workspace
     self.viewRichWorkspace = [[[NSBundle mainBundle] loadNibNamed:@"NCRichWorkspace" owner:self options:nil] firstObject];
@@ -175,6 +172,7 @@
     heightRichWorkspace = UIScreen.mainScreen.bounds.size.height / 4 + heightSearchBar;
     [self.viewRichWorkspace setFrame:CGRectMake(0, 0, self.tableView.frame.size.width, heightRichWorkspace)];
     [self.viewRichWorkspace.searchViewHolder addSubview:self.searchController.searchBar];
+    [self.searchController.searchBar sizeToFit];
     // Table Header View
     [self.tableView setTableHeaderView:self.viewRichWorkspace];
 
@@ -206,10 +204,16 @@
     [self changeTheming];
 }
 
+- (void)willDismissSearchController:(UISearchController *)searchController
+{
+    [self.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
+}
+
 - (void)viewWillAppear:(BOOL)animated
 {
     [super viewWillAppear:animated];
-    
+    [self updateNavBarShadow:self.tableView];
+
     // test
     if (appDelegate.activeAccount.length == 0)
         return;
@@ -282,20 +286,9 @@
 - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
 {
     [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
-
-    [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
-        
-        if (self.view.frame.size.width == ([[UIScreen mainScreen] bounds].size.width*([[UIScreen mainScreen] bounds].size.width<[[UIScreen mainScreen] bounds].size.height))+([[UIScreen mainScreen] bounds].size.height*([[UIScreen mainScreen] bounds].size.width>[[UIScreen mainScreen] bounds].size.height))) {
-            
-            // Portrait
-            
-        } else {
-            
-            // Landscape
-        }
-        
+    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
         [self setTableViewHeader];
-    }];
+    } completion:nil];
 }
 
 - (void)presentationControllerWillDismiss:(UIPresentationController *)presentationController
@@ -318,7 +311,7 @@
 }
 
 - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
-    [self updateNavBarShadow:scrollView.contentOffset.y > 0];
+    [self updateNavBarShadow:scrollView];
 }
 
 - (void)changeTheming
@@ -1473,10 +1466,7 @@
         
         [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:self.serverUrl ocId:nil action:k_action_NULL];
     }
-    
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
-        [self setTableViewHeader];
-    });
+
 }
 
 #pragma mark -
@@ -2899,7 +2889,7 @@
         [self.viewRichWorkspace setFrame:CGRectMake(self.tableView.tableHeaderView.frame.origin.x, self.tableView.tableHeaderView.frame.origin.y, self.tableView.frame.size.width, heightRichWorkspace)];
     }
     
-    self.searchController.searchBar.frame = self.viewRichWorkspace.searchViewHolder.frame;
+    [self.searchController.searchBar sizeToFit];
     [self.viewRichWorkspace loadWithRichWorkspaceText:self.richWorkspaceText];
     [self.tableView reloadData];
 }

+ 2 - 2
iOSClient/Main/Main.storyboard

@@ -434,7 +434,7 @@
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="dC6-NQ-0Td">
-                                <rect key="frame" x="0.0" y="0.0" width="414" height="813"/>
+                                <rect key="frame" x="0.0" y="140" width="414" height="673"/>
                                 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                 <connections>
                                     <outlet property="dataSource" destination="Qyv-Eo-LeA" id="8v3-Et-JVZ"/>
@@ -444,9 +444,9 @@
                         </subviews>
                         <constraints>
                             <constraint firstItem="dC6-NQ-0Td" firstAttribute="leading" secondItem="Sqy-z1-MI5" secondAttribute="leading" id="AAp-Xf-P1c"/>
+                            <constraint firstItem="dC6-NQ-0Td" firstAttribute="top" secondItem="Sqy-z1-MI5" secondAttribute="top" id="BrC-GS-MSF"/>
                             <constraint firstItem="Sqy-z1-MI5" firstAttribute="trailing" secondItem="dC6-NQ-0Td" secondAttribute="trailing" id="DBL-Bo-AUz"/>
                             <constraint firstItem="Sqy-z1-MI5" firstAttribute="bottom" secondItem="dC6-NQ-0Td" secondAttribute="bottom" id="d6p-eB-e8X"/>
-                            <constraint firstItem="dC6-NQ-0Td" firstAttribute="top" secondItem="QRE-ju-M4I" secondAttribute="top" id="vqZ-BZ-kL8"/>
                         </constraints>
                         <viewLayoutGuide key="safeArea" id="Sqy-z1-MI5"/>
                     </view>

+ 1 - 1
iOSClient/RichWorkspace/NCRichWorkspace.swift

@@ -31,7 +31,7 @@ import MarkdownKit
     @IBOutlet weak var sortButton: UIButton!
     @IBOutlet weak var searchViewHolder: UIView!
     @objc @IBOutlet weak var textView: UITextView!
-
+    
     private var markdownParser = MarkdownParser()
     private var richWorkspaceText: String?
     private var textViewColor: UIColor?

+ 2 - 2
iOSClient/RichWorkspace/NCRichWorkspace.xib

@@ -18,10 +18,10 @@
                     <rect key="frame" x="0.0" y="0.0" width="320" height="97"/>
                     <subviews>
                         <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="uNy-ff-uKP">
-                            <rect key="frame" x="0.0" y="4" width="320" height="44"/>
+                            <rect key="frame" x="0.0" y="-2" width="320" height="50"/>
                             <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                             <constraints>
-                                <constraint firstAttribute="height" constant="44" id="66u-iM-EEA"/>
+                                <constraint firstAttribute="height" constant="50" id="66u-iM-EEA"/>
                             </constraints>
                         </view>
                         <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="whP-vX-7tm">