Browse Source

new button design

Michael Kirk 1 month ago
parent
commit
d25361cd6e

+ 4 - 0
Signal.xcodeproj/project.pbxproj

@@ -486,6 +486,7 @@
 		4C4AE6A1224AF35700D4AF6F /* SendMediaNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C4AE69F224AF21900D4AF6F /* SendMediaNavigationController.swift */; };
 		4C4AEC4520EC343B0020E72B /* DismissableTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C4AEC4420EC343B0020E72B /* DismissableTextField.swift */; };
 		4C4BC6C32102D697004040C9 /* ContactDiscoveryOperationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C4BC6C22102D697004040C9 /* ContactDiscoveryOperationTest.swift */; };
+		4C4F5EBC22711EEB00F3DD01 /* SendMediaBottomButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C4F5EBB22711EEB00F3DD01 /* SendMediaBottomButton.swift */; };
 		4C5250D221E7BD7D00CE3D95 /* PhoneNumberValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C5250D121E7BD7D00CE3D95 /* PhoneNumberValidator.swift */; };
 		4C5250D421E7C51900CE3D95 /* PhoneNumberValidatorTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C5250D321E7C51900CE3D95 /* PhoneNumberValidatorTest.swift */; };
 		4C586926224FAB83003FD070 /* AVAudioSession+OWS.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C586925224FAB83003FD070 /* AVAudioSession+OWS.m */; };
@@ -1238,6 +1239,7 @@
 		4C4AE69F224AF21900D4AF6F /* SendMediaNavigationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendMediaNavigationController.swift; sourceTree = "<group>"; };
 		4C4AEC4420EC343B0020E72B /* DismissableTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DismissableTextField.swift; sourceTree = "<group>"; };
 		4C4BC6C22102D697004040C9 /* ContactDiscoveryOperationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = ContactDiscoveryOperationTest.swift; path = contact/ContactDiscoveryOperationTest.swift; sourceTree = "<group>"; };
+		4C4F5EBB22711EEB00F3DD01 /* SendMediaBottomButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendMediaBottomButton.swift; sourceTree = "<group>"; };
 		4C5250D121E7BD7D00CE3D95 /* PhoneNumberValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneNumberValidator.swift; sourceTree = "<group>"; };
 		4C5250D321E7C51900CE3D95 /* PhoneNumberValidatorTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneNumberValidatorTest.swift; sourceTree = "<group>"; };
 		4C586924224FAB83003FD070 /* AVAudioSession+OWS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "AVAudioSession+OWS.h"; path = "util/UI Categories/AVAudioSession+OWS.h"; sourceTree = "<group>"; };
@@ -1868,6 +1870,7 @@
 				3496955B219B605E00DCFE74 /* PhotoLibrary.swift */,
 				4CA485BA2232339F004B9E7D /* PhotoCaptureViewController.swift */,
 				4C21D5D7223AC60F00EF8A77 /* PhotoCapture.swift */,
+				4C4F5EBB22711EEB00F3DD01 /* SendMediaBottomButton.swift */,
 			);
 			path = Photos;
 			sourceTree = "<group>";
@@ -3582,6 +3585,7 @@
 				34A4C62022175C5C0042EF2E /* OnboardingProfileViewController.swift in Sources */,
 				4505C2BF1E648EA300CEBF41 /* ExperienceUpgrade.swift in Sources */,
 				EF764C351DB67CC5000D9A87 /* UIViewController+Permissions.m in Sources */,
+				4C4F5EBC22711EEB00F3DD01 /* SendMediaBottomButton.swift in Sources */,
 				45CD81EF1DC030E7004C9430 /* SyncPushTokensJob.swift in Sources */,
 				34D2CCE0206939B400CB1A14 /* DebugUIMessagesAssetLoader.m in Sources */,
 				4CEB78C92178EBAB00F315D2 /* OWSSessionResetJobRecord.m in Sources */,

+ 61 - 0
Signal/src/ViewControllers/Photos/SendMediaBottomButton.swift

@@ -0,0 +1,61 @@
+//
+//  Copyright (c) 2019 Open Whisper Systems. All rights reserved.
+//
+
+import UIKit
+
+class SendMediaBottomButton: UIView {
+    let button: OWSButton
+    let blurView: UIVisualEffectView
+
+    init(imageName: String, tintColor: UIColor, diameter: CGFloat, block: @escaping () -> Void) {
+        self.button = OWSButton(imageName: imageName, tintColor: tintColor, block: block)
+        button.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
+
+        let blurEffect = UIBlurEffect(style: .dark)
+        self.blurView = UIVisualEffectView(effect: blurEffect)
+
+        super.init(frame: .zero)
+
+        layer.cornerRadius = diameter / 2
+        blurView.layer.cornerRadius = diameter / 2
+        blurView.clipsToBounds = true
+
+        addSubview(blurView)
+        blurView.autoPinEdgesToSuperviewEdges()
+
+        let vibrancyEffect = UIVibrancyEffect(blurEffect: blurEffect)
+        let vibrancyView = UIVisualEffectView(effect: vibrancyEffect)
+        blurView.contentView.addSubview(vibrancyView)
+        vibrancyView.autoPinEdgesToSuperviewEdges()
+
+        addSubview(button)
+        button.autoSetDimensions(to: CGSize(width: diameter, height: diameter))
+        button.autoPinEdgesToSuperviewEdges()
+        updateViewState()
+    }
+
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    var isSelected: Bool = false {
+        didSet {
+            updateViewState()
+        }
+    }
+
+    func updateViewState() {
+        if isSelected {
+            button.tintColor = .ows_black
+            blurView.isHidden = true
+            backgroundColor = .ows_white
+            setShadow()
+        } else {
+            button.tintColor = .ows_white
+            blurView.isHidden = false
+            backgroundColor = .clear
+            layer.shadowRadius = 0
+        }
+    }
+}

+ 33 - 48
Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift

@@ -85,9 +85,16 @@ class SendMediaNavigationController: OWSNavigationController {
         return navController
     }
 
-    var isInBatchSelectMode = false {
-        didSet {
-            if oldValue != isInBatchSelectMode {
+    var isInBatchSelectMode: Bool {
+        get {
+            return self.batchModeButton.isSelected
+        }
+
+        set {
+            let didChange = newValue != isInBatchSelectMode
+            self.batchModeButton.isSelected = newValue
+
+            if didChange {
                 mediaLibraryViewController.batchSelectModeDidChange()
                 guard let topViewController = viewControllers.last else {
                     return
@@ -105,13 +112,15 @@ class SendMediaNavigationController: OWSNavigationController {
             cameraModeButton.isHidden = true
             mediaLibraryModeButton.isHidden = true
         case is ImagePickerGridController:
-            batchModeButton.isHidden = isInBatchSelectMode
-            doneButton.isHidden = !isInBatchSelectMode || (attachmentDraftCollection.count == 0 && mediaLibrarySelections.count == 0)
+            let showDoneButton = isInBatchSelectMode && attachmentCount > 0
+            batchModeButton.isHidden = showDoneButton
+            doneButton.isHidden = !showDoneButton
             cameraModeButton.isHidden = false
             mediaLibraryModeButton.isHidden = true
         case is PhotoCaptureViewController:
-            batchModeButton.isHidden = isInBatchSelectMode
-            doneButton.isHidden = !isInBatchSelectMode || (attachmentDraftCollection.count == 0 && mediaLibrarySelections.count == 0)
+            let showDoneButton = isInBatchSelectMode && attachmentCount > 0
+            batchModeButton.isHidden = showDoneButton
+            doneButton.isHidden = !showDoneButton
             cameraModeButton.isHidden = true
             mediaLibraryModeButton.isHidden = false
         default:
@@ -132,8 +141,8 @@ class SendMediaNavigationController: OWSNavigationController {
     // MARK: - Events
 
     private func didTapBatchModeButton() {
-        // There's no way to _disable_ batch mode.
-        isInBatchSelectMode = true
+        isInBatchSelectMode = !isInBatchSelectMode
+        assert(isInBatchSelectMode || attachmentCount <= 1)
     }
 
     private func didTapCameraModeButton() {
@@ -155,49 +164,25 @@ class SendMediaNavigationController: OWSNavigationController {
         return button
     }()
 
-    private lazy var batchModeButton: UIButton = {
-        let button = OWSButton(imageName: "media_send_batch_mode_disabled",
-                               tintColor: .ows_gray60,
-                               block: { [weak self] in self?.didTapBatchModeButton() })
-
-        let width: CGFloat = type(of: self).bottomButtonWidth
-        button.autoSetDimensions(to: CGSize(width: width, height: width))
-        button.layer.cornerRadius = width / 2
-        button.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
-        button.backgroundColor = .ows_white
-        button.setShadow()
-
-        return button
+    private lazy var batchModeButton: SendMediaBottomButton = {
+        return SendMediaBottomButton(imageName: "media_send_batch_mode_disabled",
+                                     tintColor: .ows_white,
+                                     diameter: type(of: self).bottomButtonWidth,
+                                     block: { [weak self] in self?.didTapBatchModeButton() })
     }()
 
-    private lazy var cameraModeButton: UIButton = {
-        let button = OWSButton(imageName: "settings-avatar-camera-2",
-                               tintColor: .ows_gray60,
-                               block: { [weak self] in self?.didTapCameraModeButton() })
-
-        let width: CGFloat = type(of: self).bottomButtonWidth
-        button.autoSetDimensions(to: CGSize(width: width, height: width))
-        button.layer.cornerRadius = width / 2
-        button.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
-        button.backgroundColor = .ows_white
-        button.setShadow()
-
-        return button
+    private lazy var cameraModeButton: UIView = {
+        return SendMediaBottomButton(imageName: "settings-avatar-camera-2",
+                                     tintColor: .ows_white,
+                                     diameter: type(of: self).bottomButtonWidth,
+                                     block: { [weak self] in self?.didTapCameraModeButton() })
     }()
 
-    private lazy var mediaLibraryModeButton: UIButton = {
-        let button = OWSButton(imageName: "actionsheet_camera_roll_black",
-                               tintColor: .ows_gray60,
-                               block: { [weak self] in self?.didTapMediaLibraryModeButton() })
-
-        let width: CGFloat = type(of: self).bottomButtonWidth
-        button.autoSetDimensions(to: CGSize(width: width, height: width))
-        button.layer.cornerRadius = width / 2
-        button.imageEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
-        button.backgroundColor = .ows_white
-        button.setShadow()
-
-        return button
+    private lazy var mediaLibraryModeButton: UIView = {
+        return SendMediaBottomButton(imageName: "actionsheet_camera_roll_black",
+                                     tintColor: .ows_white,
+                                     diameter: type(of: self).bottomButtonWidth,
+                                     block: { [weak self] in self?.didTapMediaLibraryModeButton() })
     }()
 
     // MARK: State