diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index f84328c..492df85 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -19,8 +19,6 @@ DCA9837627D693BB00D6EA30 /* BasicExample.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DCA9837527D693BB00D6EA30 /* BasicExample.storyboard */; }; DCA9837827D6951C00D6EA30 /* SafeAreaExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA9837727D6951C00D6EA30 /* SafeAreaExampleViewController.swift */; }; DCA9837A27D6958500D6EA30 /* SafeAreaExample.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DCA9837927D6958500D6EA30 /* SafeAreaExample.storyboard */; }; - DCA9837C27D69B5900D6EA30 /* InterfaceBuilderExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA9837B27D69B5900D6EA30 /* InterfaceBuilderExampleViewController.swift */; }; - DCA9837E27D69B8E00D6EA30 /* InterfaceBuilderExample.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DCA9837D27D69B8E00D6EA30 /* InterfaceBuilderExample.storyboard */; }; DCA9838027D69C9300D6EA30 /* AdvancedExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA9837F27D69C9300D6EA30 /* AdvancedExampleViewController.swift */; }; DCA9838227D69D3F00D6EA30 /* AdvancedExample.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DCA9838127D69D3F00D6EA30 /* AdvancedExample.storyboard */; }; DCA9838727D6A44700D6EA30 /* NavigationBarExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCA9838627D6A44700D6EA30 /* NavigationBarExampleViewController.swift */; }; @@ -74,8 +72,6 @@ DCA9837527D693BB00D6EA30 /* BasicExample.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = BasicExample.storyboard; sourceTree = ""; }; DCA9837727D6951C00D6EA30 /* SafeAreaExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafeAreaExampleViewController.swift; sourceTree = ""; }; DCA9837927D6958500D6EA30 /* SafeAreaExample.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = SafeAreaExample.storyboard; sourceTree = ""; }; - DCA9837B27D69B5900D6EA30 /* InterfaceBuilderExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterfaceBuilderExampleViewController.swift; sourceTree = ""; }; - DCA9837D27D69B8E00D6EA30 /* InterfaceBuilderExample.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = InterfaceBuilderExample.storyboard; sourceTree = ""; }; DCA9837F27D69C9300D6EA30 /* AdvancedExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedExampleViewController.swift; sourceTree = ""; }; DCA9838127D69D3F00D6EA30 /* AdvancedExample.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AdvancedExample.storyboard; sourceTree = ""; }; DCA9838627D6A44700D6EA30 /* NavigationBarExampleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationBarExampleViewController.swift; sourceTree = ""; }; @@ -209,7 +205,6 @@ children = ( DCA9836E27D6909A00D6EA30 /* AdvancedExample */, DCA9836D27D6908F00D6EA30 /* BasicExample */, - DCA9837327D691B600D6EA30 /* InterfaceBuilderExample */, DCA9837427D691C600D6EA30 /* NavigationBarExample */, DCA9837227D691A200D6EA30 /* SafeAreaExample */, DCA9836F27D690A400D6EA30 /* SwiftUIExample */, @@ -253,15 +248,6 @@ path = SafeAreaExample; sourceTree = ""; }; - DCA9837327D691B600D6EA30 /* InterfaceBuilderExample */ = { - isa = PBXGroup; - children = ( - DCA9837D27D69B8E00D6EA30 /* InterfaceBuilderExample.storyboard */, - DCA9837B27D69B5900D6EA30 /* InterfaceBuilderExampleViewController.swift */, - ); - path = InterfaceBuilderExample; - sourceTree = ""; - }; DCA9837427D691C600D6EA30 /* NavigationBarExample */ = { isa = PBXGroup; children = ( @@ -442,7 +428,6 @@ DCA9838227D69D3F00D6EA30 /* AdvancedExample.storyboard in Resources */, DCA9833E27D68AD600D6EA30 /* Assets.xcassets in Resources */, DCA9838927D6A55A00D6EA30 /* NavigationBarExample.storyboard in Resources */, - DCA9837E27D69B8E00D6EA30 /* InterfaceBuilderExample.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -615,7 +600,6 @@ DCA9837827D6951C00D6EA30 /* SafeAreaExampleViewController.swift in Sources */, DCA9838727D6A44700D6EA30 /* NavigationBarExampleViewController.swift in Sources */, DCA9838B27D6A74800D6EA30 /* SwiftUIExampleView.swift in Sources */, - DCA9837C27D69B5900D6EA30 /* InterfaceBuilderExampleViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Example/Example/Scenes/AdvancedExample/AdvancedExample.storyboard b/Example/Example/Scenes/AdvancedExample/AdvancedExample.storyboard index 263f868..8c834c2 100644 --- a/Example/Example/Scenes/AdvancedExample/AdvancedExample.storyboard +++ b/Example/Example/Scenes/AdvancedExample/AdvancedExample.storyboard @@ -17,23 +17,10 @@ - + - + + + + + + + + + @@ -59,6 +79,9 @@ + + + diff --git a/Example/Example/Scenes/AdvancedExample/AdvancedExampleViewController.swift b/Example/Example/Scenes/AdvancedExample/AdvancedExampleViewController.swift index f2c80bb..645f449 100644 --- a/Example/Example/Scenes/AdvancedExample/AdvancedExampleViewController.swift +++ b/Example/Example/Scenes/AdvancedExample/AdvancedExampleViewController.swift @@ -15,22 +15,31 @@ final class AdvancedExampleViewController: UIViewController { private enum Config { /// The programatically applied height of the `GradientActivityIndicatorView`. - static let height: CGFloat = 3.5 + static let height: CGFloat = 3 /// The custom gradient colors we use. /// Source: https://color.adobe.com/Pink-Flamingo-color-theme-10343714/ static let gradientColors = [ #colorLiteral(red: 0.9490196078, green: 0.3215686275, blue: 0.431372549, alpha: 1), #colorLiteral(red: 0.9450980392, green: 0.4784313725, blue: 0.5921568627, alpha: 1), #colorLiteral(red: 0.9529411765, green: 0.737254902, blue: 0.7843137255, alpha: 1), #colorLiteral(red: 0.4274509804, green: 0.8666666667, blue: 0.9490196078, alpha: 1), #colorLiteral(red: 0.7568627451, green: 0.9411764706, blue: 0.9568627451, alpha: 1), ] + + static let smallStackViewSpacing: CGFloat = 8 } // MARK: - Outlets - @IBOutlet private var customSuperviewButton: BorderedButton! + @IBOutlet private var stackView: UIStackView! + @IBOutlet private var customColorsButton: UIButton! + @IBOutlet private var gradientActivityIndicator: GradientActivityIndicatorView! + @IBOutlet private var interfaceBuilderSetupButton: UIButton! + + @IBOutlet private var customSuperviewButton: BorderedButton! + // MARK: - Private properties + // swiftlint:disable:next identifier_name private let customSuperviewGradientActivityIndicatorView = GradientActivityIndicatorView() private let customColorsGradientLoadingBar = GradientLoadingBar() @@ -39,20 +48,28 @@ final class AdvancedExampleViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - setupCustomSuperviewGradientActivityIndicatorView() + setupStackView() setupCustomColorsGradientLoadingBar() + setupCustomSuperviewGradientActivityIndicatorView() } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) // Reset any possible visible loading bar. - customSuperviewGradientActivityIndicatorView.fadeOut() customColorsGradientLoadingBar.fadeOut() } // MARK: - Private methods + private func setupStackView() { + stackView.setCustomSpacing(Config.smallStackViewSpacing, after: gradientActivityIndicator) + } + + private func setupCustomColorsGradientLoadingBar() { + customColorsGradientLoadingBar.gradientColors = Config.gradientColors + } + private func setupCustomSuperviewGradientActivityIndicatorView() { customSuperviewGradientActivityIndicatorView.isHidden = true customSuperviewGradientActivityIndicatorView.alpha = 0 @@ -69,18 +86,6 @@ final class AdvancedExampleViewController: UIViewController { ]) } - private func setupCustomColorsGradientLoadingBar() { - customColorsGradientLoadingBar.gradientColors = Config.gradientColors - } - - @IBAction private func toggleCustomSuperviewButtonTouchUpInside(_: Any) { - if customSuperviewGradientActivityIndicatorView.isHidden { - customSuperviewGradientActivityIndicatorView.fadeIn() - } else { - customSuperviewGradientActivityIndicatorView.fadeOut() - } - } - @IBAction private func toggleCustomColorsButtonTouchUpInside(_: Any) { // TODO: Add `isHidden` shortcut if customColorsGradientLoadingBar.gradientActivityIndicatorView.isHidden { @@ -89,6 +94,26 @@ final class AdvancedExampleViewController: UIViewController { customColorsGradientLoadingBar.fadeOut() } } + + @IBAction private func interfaceBuilderSetupButtonTouchUpInside(_: Any) { + // We explicitly "only" reduce the alpha here, as calling `fadeIn()` / `fadeOut()` would update the `isHidden` + // flag accordingly. This would then lead to a height-update of the parent stack view. + UIView.animate(withDuration: 1.0) { + if self.gradientActivityIndicator.alpha > 0 { + self.gradientActivityIndicator.alpha = 0 + } else { + self.gradientActivityIndicator.alpha = 1 + } + } + } + + @IBAction private func customSuperviewButtonTouchUpInside(_: Any) { + if customSuperviewGradientActivityIndicatorView.isHidden { + customSuperviewGradientActivityIndicatorView.fadeIn() + } else { + customSuperviewGradientActivityIndicatorView.fadeOut() + } + } } // MARK: - Helpers diff --git a/Example/Example/Scenes/EntryPointView.swift b/Example/Example/Scenes/EntryPointView.swift index 700bb13..6f7928b 100644 --- a/Example/Example/Scenes/EntryPointView.swift +++ b/Example/Example/Scenes/EntryPointView.swift @@ -30,11 +30,6 @@ struct EntryPointView: View { subtitle: "Loading bar ignoring the safe area.") } - NavigationLink(destination: InterfaceBuilderExampleView()) { - TitleSubtitleView(title: "🎨 Interface Builder Example", - subtitle: "Setup in a storyboard or xib.") - } - NavigationLink(destination: AdvancedExampleView()) { TitleSubtitleView(title: "🚀 Advanced Example", subtitle: "How to apply e.g. custom colors.") diff --git a/Example/Example/Scenes/InterfaceBuilderExample/InterfaceBuilderExample.storyboard b/Example/Example/Scenes/InterfaceBuilderExample/InterfaceBuilderExample.storyboard deleted file mode 100644 index 874a525..0000000 --- a/Example/Example/Scenes/InterfaceBuilderExample/InterfaceBuilderExample.storyboard +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Example/Example/Scenes/InterfaceBuilderExample/InterfaceBuilderExampleViewController.swift b/Example/Example/Scenes/InterfaceBuilderExample/InterfaceBuilderExampleViewController.swift deleted file mode 100644 index 5b4d82f..0000000 --- a/Example/Example/Scenes/InterfaceBuilderExample/InterfaceBuilderExampleViewController.swift +++ /dev/null @@ -1,45 +0,0 @@ -// -// InterfaceBuilderExampleViewController.swift -// Example -// -// Created by Felix Mau on 07.03.22. -// Copyright © 2022 Felix Mau. All rights reserved. -// - -import UIKit -import SwiftUI -import GradientLoadingBar - -final class InterfaceBuilderExampleViewController: UIViewController { - // MARK: - Outlets - - @IBOutlet private var gradientActivityIndicatorView: GradientActivityIndicatorView! - - // MARK: - Public methods - - override func viewWillDisappear(_ animated: Bool) { - super.viewWillDisappear(animated) - - // Reset any possible visible loading bar. - gradientActivityIndicatorView.fadeOut() - } - - // MARK: - Private methods - - @IBAction private func showButtonTouchUpInside(_: Any) { - gradientActivityIndicatorView.fadeIn() - } - - @IBAction private func hideButtonTouchUpInside(_: Any) { - gradientActivityIndicatorView.fadeOut() - } -} - -// MARK: - Helpers - -struct InterfaceBuilderExampleView: View { - var body: some View { - StoryboardView(name: "InterfaceBuilderExample") - .navigationTitle("🎨 Interface Builder Example") - } -} diff --git a/Example/Example/Scenes/NavigationBarExample/NavigationBarExampleViewController.swift b/Example/Example/Scenes/NavigationBarExample/NavigationBarExampleViewController.swift index 235a9de..200cbb4 100644 --- a/Example/Example/Scenes/NavigationBarExample/NavigationBarExampleViewController.swift +++ b/Example/Example/Scenes/NavigationBarExample/NavigationBarExampleViewController.swift @@ -45,8 +45,6 @@ final class NavigationBarExampleViewController: UIViewController { private func setupGradientProgressIndicatorView() { guard let navigationBar = navigationController?.navigationBar else { return } - gradientProgressIndicatorView.fadeOut(duration: 0) - gradientProgressIndicatorView.translatesAutoresizingMaskIntoConstraints = false navigationBar.addSubview(gradientProgressIndicatorView) diff --git a/Example/Example/Scenes/SwiftUIExample/SwiftUIExampleView.swift b/Example/Example/Scenes/SwiftUIExample/SwiftUIExampleView.swift index 244f8bf..6a0a2f4 100644 --- a/Example/Example/Scenes/SwiftUIExample/SwiftUIExampleView.swift +++ b/Example/Example/Scenes/SwiftUIExample/SwiftUIExampleView.swift @@ -14,7 +14,8 @@ struct SwiftUIExampleView: View { var body: some View { List { - // + // We need to apply a `Spacer()` as header to have a little space between the sections + // and the navigation bar. Section(header: Spacer()) { DefaultExampleView() } @@ -171,7 +172,7 @@ private struct CustomProgressDurationExampleView: View { private struct RoundedRectangleButtonStyle: ButtonStyle { func makeBody(configuration: Configuration) -> some View { configuration.label - .padding() + .padding(12) .frame(maxWidth: .infinity) .foregroundColor(.white) .background(Color.blue.cornerRadius(8))