瀏覽代碼

NCPopupViewController coding

marinofaggiana 4 年之前
父節點
當前提交
b97b52ac6d

+ 5 - 13
Nextcloud.xcodeproj/project.pbxproj

@@ -282,7 +282,7 @@
 		F7CB689A2541676B0050EC94 /* NCMore.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7CB68992541676B0050EC94 /* NCMore.storyboard */; };
 		F7CB68A0254169530050EC94 /* NCSettings.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7CB689F254169530050EC94 /* NCSettings.storyboard */; };
 		F7CBC31C24F78E79004D3812 /* NCSortMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CBC31B24F78E79004D3812 /* NCSortMenu.swift */; };
-		F7CC51A125EA3AA100BAA38C /* PopupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CC519F25EA3AA100BAA38C /* PopupViewController.swift */; };
+		F7CC51A125EA3AA100BAA38C /* NCPopupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7CC519F25EA3AA100BAA38C /* NCPopupViewController.swift */; };
 		F7D1612023CF19E30039EBBF /* NCViewerRichWorkspace.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7D1611F23CF19E30039EBBF /* NCViewerRichWorkspace.storyboard */; };
 		F7D96FCC246ED7E200536D73 /* NCNetworkingCheckRemoteUser.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7D96FCB246ED7E100536D73 /* NCNetworkingCheckRemoteUser.swift */; };
 		F7DBC37C23325E02001A85BA /* NCAppConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7DBC37B23325E01001A85BA /* NCAppConfigView.swift */; };
@@ -657,7 +657,7 @@
 		F7CB689F254169530050EC94 /* NCSettings.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCSettings.storyboard; sourceTree = "<group>"; };
 		F7CBC31B24F78E79004D3812 /* NCSortMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCSortMenu.swift; sourceTree = "<group>"; };
 		F7CC04E61F5AD50D00378CEF /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; };
-		F7CC519F25EA3AA100BAA38C /* PopupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopupViewController.swift; sourceTree = "<group>"; };
+		F7CC519F25EA3AA100BAA38C /* NCPopupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCPopupViewController.swift; sourceTree = "<group>"; };
 		F7CE8AFA1DC1F8D8009CAE48 /* Nextcloud.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Nextcloud.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		F7CE8AFB1DC1F8D8009CAE48 /* Share.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = Share.appex; sourceTree = BUILT_PRODUCTS_DIR; };
 		F7D154271E2392A300202FD9 /* Nextcloud-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Nextcloud-Bridging-Header.h"; sourceTree = "<group>"; };
@@ -1240,8 +1240,6 @@
 		F7BFFA991A24D7BB0044ED85 /* Utility */ = {
 			isa = PBXGroup;
 			children = (
-				F7B2DEEB1F976785007CF4D2 /* NYMnemonic */,
-				F7CC519D25EA3AA100BAA38C /* EzPopup */,
 				F7514EDA1C7B1336008F3338 /* CCHud.h */,
 				F7514EDB1C7B1336008F3338 /* CCHud.m */,
 				F7053E3C1C639DF500741EA5 /* CCUtility.h */,
@@ -1250,9 +1248,11 @@
 				F78E7064219F096B006F23E4 /* NCAvatar.swift */,
 				F765608E23BF813500765969 /* NCContentPresenter.swift */,
 				F70968A324212C4E00ED60E5 /* NCLivePhoto.swift */,
+				F7CC519F25EA3AA100BAA38C /* NCPopupViewController.swift */,
 				F707C26421A2DC5200F6181E /* NCStoreReview.swift */,
 				F70BFC7320E0FA7C00C67599 /* NCUtility.swift */,
 				F74AF3A3247FB6AE00AC767B /* NCUtilityFileSystem.swift */,
+				F7B2DEEB1F976785007CF4D2 /* NYMnemonic */,
 			);
 			path = Utility;
 			sourceTree = "<group>";
@@ -1336,14 +1336,6 @@
 			path = More;
 			sourceTree = "<group>";
 		};
-		F7CC519D25EA3AA100BAA38C /* EzPopup */ = {
-			isa = PBXGroup;
-			children = (
-				F7CC519F25EA3AA100BAA38C /* PopupViewController.swift */,
-			);
-			path = EzPopup;
-			sourceTree = "<group>";
-		};
 		F7DFB7E9219C5A0500680748 /* Create cloud */ = {
 			isa = PBXGroup;
 			children = (
@@ -2111,7 +2103,7 @@
 				F7E0E1DC22327885006B0911 /* NCAudioRecorderViewController.swift in Sources */,
 				F70CAE3A1F8CF31A008125FD /* NCEndToEndEncryption.m in Sources */,
 				F70753EB2542A99800972D44 /* NCViewerImage.swift in Sources */,
-				F7CC51A125EA3AA100BAA38C /* PopupViewController.swift in Sources */,
+				F7CC51A125EA3AA100BAA38C /* NCPopupViewController.swift in Sources */,
 				F74C0436253F1CDC009762AB /* NCShares.swift in Sources */,
 				F7AE00F5230D5F9E007ACF8A /* NCLoginWeb.swift in Sources */,
 				F7B2DEF01F976854007CF4D2 /* NYMnemonic.m in Sources */,

+ 1 - 1
iOSClient/Main/Menu/NCCollectionViewCommon+Menu.swift

@@ -228,7 +228,7 @@ extension NCCollectionViewCommon {
                             
                             viewController.metadata = metadata
 
-                            let popupVC = PopupViewController(contentController: viewController, position: .top(50), popupWidth: 300, popupHeight: 400)
+                            let popupVC = NCPopupViewController(contentController: viewController, popupWidth: 300, popupHeight: 400)
                             
                             popupVC.backgroundAlpha = 0.3
                             popupVC.backgroundColor = .black

+ 61 - 9
iOSClient/Utility/EzPopup/PopupViewController.swift → iOSClient/Utility/NCPopupViewController.swift

@@ -1,24 +1,41 @@
 //
-//  PopupViewController.swift
+//  NCPopupViewController.swift
 //  EzPopup
 //
 //  Created by Huy Nguyen on 6/4/18.
 //
-
+//  Modified by Marino Faggiana for Nextcloud progect.
+//
+//  Author Huy Nguyen
+//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
 import UIKit
 
-public protocol PopupViewControllerDelegate: class {
+public protocol NCPopupViewControllerDelegate: class {
     
     /// It is called when pop up is dismissed by tap outside
-    func popupViewControllerDidDismissByTapGesture(_ sender: PopupViewController)
+    func popupViewControllerDidDismissByTapGesture(_ sender: NCPopupViewController)
 }
 
 // optional func
-public extension PopupViewControllerDelegate {
-    func popupViewControllerDidDismissByTapGesture(_ sender: PopupViewController) {}
+public extension NCPopupViewControllerDelegate {
+    func popupViewControllerDidDismissByTapGesture(_ sender: NCPopupViewController) {}
 }
 
-public class PopupViewController: UIViewController {
+public class NCPopupViewController: UIViewController {
     
     public enum PopupPosition {
         /// Align center X, center Y with offset param
@@ -80,7 +97,7 @@ public class PopupViewController: UIViewController {
     private(set) public var contentView: UIView?
     
     /// The delegate to receive pop up event
-    public weak var delegate: PopupViewControllerDelegate?
+    public weak var delegate: NCPopupViewControllerDelegate?
     
     private var containerView = UIView()
     
@@ -139,6 +156,41 @@ public class PopupViewController: UIViewController {
         setupUI()
         setupViews()
         addDismissGesture()
+        
+        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIResponder.keyboardWillHideNotification, object: nil);
+    }
+    
+    // MARK: -
+    
+    @objc internal func keyboardWillShow(_ notification : Notification?) {
+        
+        var keyboardSize: CGSize!
+                
+        if let info = notification?.userInfo {
+
+            let frameEndUserInfoKey = UIResponder.keyboardFrameEndUserInfoKey
+                    
+            //  Getting UIKeyboardSize.
+            if let keyboardFrame = info[frameEndUserInfoKey] as? CGRect {
+                        
+                let screenSize = UIScreen.main.bounds
+                        
+                //Calculating actual keyboard displayed size, keyboard frame may be different when hardware keyboard is attached (Bug ID: #469) (Bug ID: #381)
+                let intersectRect = keyboardFrame.intersection(screenSize)
+                        
+                if intersectRect.isNull {
+                    keyboardSize = CGSize(width: screenSize.size.width, height: 0)
+                } else {
+                    keyboardSize = intersectRect.size
+                }
+            }
+        }
+    }
+    
+    @objc func keyboardWillHide(_ notification: Notification) {
+        
+        print("")
     }
     
     // MARK: - Setup
@@ -301,7 +353,7 @@ public class PopupViewController: UIViewController {
 }
 
 // MARK: - UIGestureRecognizerDelegate
-extension PopupViewController: UIGestureRecognizerDelegate {
+extension NCPopupViewController: UIGestureRecognizerDelegate {
     public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
         guard let touchView = touch.view, canTapOutsideToDismiss else {
             return false