Skip to content

Commit

Permalink
Add emptyView V3 (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzarya authored Apr 23, 2023
1 parent 11004a7 commit bb074f6
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 0 deletions.
8 changes: 8 additions & 0 deletions SB-MDEditor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
5ACEB2AB29EFE90F008E80A2 /* UITableView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ACEB2AA29EFE90F008E80A2 /* UITableView+Extensions.swift */; };
5AFA77CE29F4B36A0010478E /* Di+ServiceFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AFA77CD29F4B36A0010478E /* Di+ServiceFactory.swift */; };
5AFA77D129F4B3D10010478E /* FilesStorageProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AFA77D029F4B3D10010478E /* FilesStorageProvider.swift */; };
6004CE2B29F564520074D9E5 /* EmptyInputData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6004CE2A29F564520074D9E5 /* EmptyInputData.swift */; };
6004CE2D29F5646C0074D9E5 /* EmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6004CE2C29F5646C0074D9E5 /* EmptyView.swift */; };
60D43BB729F1A61300C5AF4F /* MD_Bandle in Resources */ = {isa = PBXBuildFile; fileRef = 60D43BB629F1A61300C5AF4F /* MD_Bandle */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -125,6 +127,8 @@
5ACEB2AA29EFE90F008E80A2 /* UITableView+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UITableView+Extensions.swift"; sourceTree = "<group>"; };
5AFA77CD29F4B36A0010478E /* Di+ServiceFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Di+ServiceFactory.swift"; sourceTree = "<group>"; };
5AFA77D029F4B3D10010478E /* FilesStorageProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FilesStorageProvider.swift; sourceTree = "<group>"; };
6004CE2A29F564520074D9E5 /* EmptyInputData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyInputData.swift; sourceTree = "<group>"; };
6004CE2C29F5646C0074D9E5 /* EmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyView.swift; sourceTree = "<group>"; };
60D43BB629F1A61300C5AF4F /* MD_Bandle */ = {isa = PBXFileReference; lastKnownFileType = folder; path = MD_Bandle; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -342,6 +346,8 @@
children = (
5ACEB29329EEA690008E80A2 /* ErrorInputData.swift */,
5ACEB29129EEA64D008E80A2 /* ErrorView.swift */,
6004CE2A29F564520074D9E5 /* EmptyInputData.swift */,
6004CE2C29F5646C0074D9E5 /* EmptyView.swift */,
);
path = OptionalViews;
sourceTree = "<group>";
Expand Down Expand Up @@ -576,6 +582,7 @@
buildActionMask = 2147483647;
files = (
5ACEB29229EEA64D008E80A2 /* ErrorView.swift in Sources */,
6004CE2D29F5646C0074D9E5 /* EmptyView.swift in Sources */,
5ACEB27929EE64D9008E80A2 /* Di.swift in Sources */,
5ACEB28E29EE7AB5008E80A2 /* MainViewController.swift in Sources */,
5ACEB29E29EED6CA008E80A2 /* OpenDocViewController.swift in Sources */,
Expand All @@ -589,6 +596,7 @@
5A91DED829E0DF58001A23C3 /* UIView+Constraints.swift in Sources */,
5ACEB2A929EEED86008E80A2 /* CellViewModel.swift in Sources */,
5ACEB28329EE7829008E80A2 /* MainRouting.swift in Sources */,
6004CE2B29F564520074D9E5 /* EmptyInputData.swift in Sources */,
2545566829F0733200B9CFD0 /* Strings.swift in Sources */,
5ACEB28C29EE7AB5008E80A2 /* MainRouter.swift in Sources */,
5ACEB28A29EE7AB5008E80A2 /* MainPresenter.swift in Sources */,
Expand Down
31 changes: 31 additions & 0 deletions SB-MDEditor/Library/OptionalViews/EmptyInputData.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// EmptyInputData.swift
// SB-MDEditor
//
// Created by Антон Заричный on 20.04.2023.
//
import UIKit

struct EmptyInputData {
let image: UIImage
let message: String
}

extension EmptyInputData {
static let emptyFolder = EmptyInputData(
image: UIImage(asset: Asset.Placeholders.emptyPlaceholder),
message: Appearance.emptyFolderMessage
)

static let noResentFiles = EmptyInputData(
image: UIImage(asset: Asset.Placeholders.recentFilesPlaceholder),
message: Appearance.noResentFilesMessage
)
}

private extension EmptyInputData {
enum Appearance {
static let emptyFolderMessage = "Empty folder"
static let noResentFilesMessage = "No recent files"
}
}
107 changes: 107 additions & 0 deletions SB-MDEditor/Library/OptionalViews/EmptyView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// EmptyView.swift
// SB-MDEditor
//
// Created by Антон Заричный on 20.04.2023.
//
import UIKit

final class EmptyView: UIView {
// MARK: - UI Elements
private lazy var emptyImageView = makeEmptyImageView()
private lazy var emptyMessageLabel = makeEmptyMessageLabel()

// MARK: - Inits
override init(frame: CGRect) {
super.init(frame: frame)

setup()
}

required init?(coder: NSCoder) {
super.init(coder: coder)

setup()
}
}

// MARK: - Extensions
extension EmptyView {

/// Метод для обновления данных во View
@discardableResult
func update(with data: EmptyInputData) -> Self {
emptyImageView.image = data.image
emptyMessageLabel.text = data.message
return self
}
}

private extension EmptyView {
func setup() {
backgroundColor = .clear
setupContainer()
}

func makeEmptyImageView() -> UIImageView {
let image = UIImageView()
return image
}

func makeEmptyMessageLabel() -> UILabel {
let label = UILabel()
label.textColor = Theme.color(usage: .gray)
label.font = Theme.font(style: .title)
return label
}

func setupContainer() {
let backgroundView = UIView()
backgroundView.backgroundColor = Theme.color(usage: .white)
addSubview(backgroundView)
backgroundView.makeConstraints { make in
[
make.leadingAnchor.constraint(equalTo: leadingAnchor),
make.trailingAnchor.constraint(equalTo: trailingAnchor),
make.bottomAnchor.constraint(equalTo: bottomAnchor)
]
}

let stackContainer = UIStackView()
stackContainer.axis = .vertical
stackContainer.distribution = .fill
stackContainer.alignment = .center
stackContainer.spacing = Theme.spacing(usage: .standard2)

let insets = UIEdgeInsets(
top: Theme.spacing(usage: .standard),
left: Theme.spacing(usage: .standard2),
bottom: Theme.spacing(usage: .standard2),
right: Theme.spacing(usage: .standard2)
)

[
emptyImageView,
emptyMessageLabel
].forEach { stackContainer.addArrangedSubview($0) }

backgroundView.addSubview(stackContainer)
stackContainer.makeEqualToSuperview(insets: insets)
}
}

#if canImport(SwiftUI) && DEBUG
import SwiftUI
struct EmptyViewProvider: PreviewProvider {
static var previews: some View {
let emptyView = EmptyView()
emptyView.update(with: EmptyInputData.emptyFolder)
return Group {
VStack(spacing: 0) {
emptyView.preview().frame(height: 100).padding(.bottom, 20)
}
.preferredColorScheme(.light)
}
}
}
#endif
44 changes: 44 additions & 0 deletions SB-MDEditor/Resources/Autogenerated/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,55 @@ internal struct ColorAsset {

internal enum Asset {
internal static let accentColor = ColorAsset(name: "AccentColor")
internal enum Menu {
internal static let aboutMenuIcon = ImageAsset(name: "aboutMenuIcon")
internal static let newFileMenuIcon = ImageAsset(name: "newFileMenuIcon")
internal static let openMenuIcon = ImageAsset(name: "openMenuIcon")
}
internal enum Placeholders {
internal static let emptyPlaceholder = ImageAsset(name: "EmptyPlaceholder")
internal static let recentFilesPlaceholder = ImageAsset(name: "recentFilesPlaceholder")
}
internal static let icBack = ImageAsset(name: "ic_back")
internal static let icBook = ImageAsset(name: "ic_book")
internal static let icCompress = ImageAsset(name: "ic_compress")
internal static let icFile = ImageAsset(name: "ic_file")
internal static let icFileCode = ImageAsset(name: "ic_file_code")
internal static let icFolder = ImageAsset(name: "ic_folder")
internal static let icGrid = ImageAsset(name: "ic_grid")
internal static let icMemory = ImageAsset(name: "ic_memory")
internal static let icNext = ImageAsset(name: "ic_next")
internal static let icOcr = ImageAsset(name: "ic_ocr")
internal static let icPause = ImageAsset(name: "ic_pause")
internal static let icPlay = ImageAsset(name: "ic_play")
internal static let icResume = ImageAsset(name: "ic_resume")
internal static let icStop = ImageAsset(name: "ic_stop")
internal static let icTrash = ImageAsset(name: "ic_trash")

internal static let allColors: [ColorAsset] = [
accentColor,
]
internal static let allImages: [ImageAsset] = [
Menu.aboutMenuIcon,
Menu.newFileMenuIcon,
Menu.openMenuIcon,
Placeholders.emptyPlaceholder,
Placeholders.recentFilesPlaceholder,
icBack,
icBook,
icCompress,
icFile,
icFileCode,
icFolder,
icGrid,
icMemory,
icNext,
icOcr,
icPause,
icPlay,
icResume,
icStop,
icTrash,
]
@available(*, deprecated, renamed: "allImages")
internal static let allValues: [AssetType] = allImages
Expand Down

0 comments on commit bb074f6

Please sign in to comment.