♻️ :: Combine scenes in example application

This commit is contained in:
Felix Mau
2022-03-11 13:42:30 +01:00
parent 76cd8c3ddf
commit 3e1c18818a
8 changed files with 82 additions and 184 deletions
@@ -17,23 +17,10 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="wBu-Jx-yJe">
<rect key="frame" x="16" y="400" width="382" height="96"/>
<rect key="frame" x="16" y="362.5" width="382" height="171"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cc6-eP-2iq" userLabel="Custom Superview Button" customClass="BorderedButton" customModule="Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="382" height="40"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="40" id="AkT-c3-A4M"/>
</constraints>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="Custom Superview">
<fontDescription key="titleFontDescription" style="UICTFontTextStyleBody"/>
</buttonConfiguration>
<connections>
<action selector="toggleCustomSuperviewButtonTouchUpInside:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="0Yr-Fe-Acm"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kEU-Kf-t9a" userLabel="Custom Colors Button">
<rect key="frame" x="0.0" y="56" width="382" height="40"/>
<rect key="frame" x="0.0" y="0.0" width="382" height="40"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="40" id="NJg-XX-Snw"/>
</constraints>
@@ -45,6 +32,39 @@
<action selector="toggleCustomColorsButtonTouchUpInside:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="loC-hh-CUH"/>
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="9g2-oL-JNk" customClass="GradientActivityIndicatorView" customModule="GradientLoadingBar">
<rect key="frame" x="0.0" y="56" width="382" height="3"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="3" id="gVZ-Gu-0d8"/>
</constraints>
</view>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="5x1-lr-GQw" userLabel="Interface Builder Setup Button">
<rect key="frame" x="0.0" y="75" width="382" height="40"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="40" id="e4a-f8-HBf"/>
</constraints>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="filled" title="Interface-Builder Setup">
<fontDescription key="titleFontDescription" style="UICTFontTextStyleBody"/>
</buttonConfiguration>
<connections>
<action selector="interfaceBuilderSetupButtonTouchUpInside:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="zRi-LD-twy"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="cc6-eP-2iq" userLabel="Custom Superview Button" customClass="BorderedButton" customModule="Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="131" width="382" height="40"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="40" id="AkT-c3-A4M"/>
</constraints>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="plain" title="Custom Superview">
<fontDescription key="titleFontDescription" style="UICTFontTextStyleBody"/>
</buttonConfiguration>
<connections>
<action selector="customSuperviewButtonTouchUpInside:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="ydP-3C-qZO"/>
</connections>
</button>
</subviews>
</stackView>
</subviews>
@@ -59,6 +79,9 @@
<connections>
<outlet property="customColorsButton" destination="kEU-Kf-t9a" id="cmO-oH-05r"/>
<outlet property="customSuperviewButton" destination="cc6-eP-2iq" id="fqL-8j-Z58"/>
<outlet property="gradientActivityIndicator" destination="9g2-oL-JNk" id="ge0-pf-6OJ"/>
<outlet property="interfaceBuilderSetupButton" destination="5x1-lr-GQw" id="1ja-dz-ejF"/>
<outlet property="stackView" destination="wBu-Jx-yJe" id="8j9-MR-DLr"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Ief-a0-LHa" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
@@ -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
@@ -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.")
@@ -1,83 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Y6W-OH-hqX">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Interface Builder Example View Controller-->
<scene sceneID="s0d-6b-0kx">
<objects>
<viewController id="Y6W-OH-hqX" customClass="InterfaceBuilderExampleViewController" customModule="Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="5EZ-qb-Rvc">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="JRZ-82-J3x" customClass="GradientActivityIndicatorView" customModule="GradientLoadingBar">
<rect key="frame" x="16" y="60" width="382" height="3"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="3" id="E7r-bo-9Xk"/>
</constraints>
</view>
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillEqually" alignment="center" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="L9o-al-XKN">
<rect key="frame" x="16" y="428" width="382" height="40"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="v1q-i7-LJ5" userLabel="ShowButton">
<rect key="frame" x="0.0" y="0.0" width="183" height="40"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="40" id="luJ-hF-vmw"/>
</constraints>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="filled" title="Show">
<fontDescription key="titleFontDescription" style="UICTFontTextStyleBody"/>
</buttonConfiguration>
<connections>
<action selector="showButtonTouchUpInside:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="q22-io-OL4"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kz6-Yl-S6N" userLabel="HideButton">
<rect key="frame" x="199" y="0.0" width="183" height="40"/>
<constraints>
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="40" id="r46-Ne-M0o"/>
</constraints>
<state key="normal" title="Button"/>
<buttonConfiguration key="configuration" style="filled" title="Hide">
<fontDescription key="titleFontDescription" style="UICTFontTextStyleBody"/>
</buttonConfiguration>
<connections>
<action selector="hideButtonTouchUpInside:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="7r8-ac-gXr"/>
</connections>
</button>
</subviews>
</stackView>
</subviews>
<viewLayoutGuide key="safeArea" id="vDu-zF-Fre"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="JRZ-82-J3x" firstAttribute="leading" secondItem="vDu-zF-Fre" secondAttribute="leading" constant="16" id="AHc-Eb-KZU"/>
<constraint firstItem="L9o-al-XKN" firstAttribute="centerY" secondItem="5EZ-qb-Rvc" secondAttribute="centerY" id="Med-CE-cP1"/>
<constraint firstItem="vDu-zF-Fre" firstAttribute="trailing" secondItem="L9o-al-XKN" secondAttribute="trailing" constant="16" id="RjT-rE-G7c"/>
<constraint firstItem="L9o-al-XKN" firstAttribute="leading" secondItem="5EZ-qb-Rvc" secondAttribute="leading" constant="16" id="XZ6-eE-acR"/>
<constraint firstItem="JRZ-82-J3x" firstAttribute="top" secondItem="vDu-zF-Fre" secondAttribute="top" constant="16" id="mr4-ZU-4jd"/>
<constraint firstItem="vDu-zF-Fre" firstAttribute="trailing" secondItem="JRZ-82-J3x" secondAttribute="trailing" constant="16" id="r2O-pX-Qka"/>
</constraints>
</view>
<connections>
<outlet property="gradientActivityIndicatorView" destination="JRZ-82-J3x" id="cdf-nh-RRH"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Ief-a0-LHa" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="132" y="81"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
@@ -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")
}
}
@@ -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)
@@ -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))