Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EmptyView #18

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions SB-MDEditor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
5ACEB2A129EED8A7008E80A2 /* CreateDocViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ACEB2A029EED8A7008E80A2 /* CreateDocViewController.swift */; };
5ACEB2A929EEED86008E80A2 /* CellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ACEB2A629EEED86008E80A2 /* CellViewModel.swift */; };
5ACEB2AB29EFE90F008E80A2 /* UITableView+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5ACEB2AA29EFE90F008E80A2 /* UITableView+Extensions.swift */; };
601BEFF529F16C1E00E88D83 /* EmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 601BEFF429F16C1E00E88D83 /* EmptyView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -113,6 +114,7 @@
5ACEB2A029EED8A7008E80A2 /* CreateDocViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateDocViewController.swift; sourceTree = "<group>"; };
5ACEB2A629EEED86008E80A2 /* CellViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellViewModel.swift; sourceTree = "<group>"; };
5ACEB2AA29EFE90F008E80A2 /* UITableView+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UITableView+Extensions.swift"; sourceTree = "<group>"; };
601BEFF429F16C1E00E88D83 /* EmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -227,6 +229,7 @@
5A65415529DE1A1F0042503D /* Modules */ = {
isa = PBXGroup;
children = (
601BEFF429F16C1E00E88D83 /* EmptyView.swift */,
5ACEB29C29EECCA6008E80A2 /* About */,
5ACEB29029EE7B7D008E80A2 /* Main */,
5ACEB29F29EED863008E80A2 /* OpenDoc */,
Expand Down Expand Up @@ -531,6 +534,7 @@
5ACEB29929EEAAB0008E80A2 /* UIView+hide.swift in Sources */,
5A48061F29DBA73B0096B7D8 /* SceneDelegate.swift in Sources */,
5ACEB2A129EED8A7008E80A2 /* CreateDocViewController.swift in Sources */,
601BEFF529F16C1E00E88D83 /* EmptyView.swift in Sources */,
5ACEB27F29EE65A8008E80A2 /* UIColor+Dynamic.swift in Sources */,
5ACEB27A29EE64D9008E80A2 /* Di+AppFactory.swift in Sources */,
5ACEB28B29EE7AB5008E80A2 /* MainWorker.swift in Sources */,
Expand Down
96 changes: 96 additions & 0 deletions SB-MDEditor/Modules/EmptyView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//
// EmptyView.swift
// SB-MDEditor
//
// Created by Антон Заричный on 20.04.2023.
//

import UIKit

final class EmptyView: UIView {
private lazy var emptyPictureLabel = makeEmptyPictureLabel()
private lazy var emptyTextLabel = makeEmptyTextLabel()
Comment on lines +11 to +12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по структуре все гуд, как я хочу ленивый элемент = функция make из расширения

  • наименование можно проще - опционал
  • нужна картинка!


override init(frame: CGRect) {
super.init(frame: frame)

setup()
}

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

setup()
}
}

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

func makeEmptyPictureLabel() -> UILabel {
let label = UILabel()
label.text = "📂"
label.font = Theme.font(style: .largeTitle)
return label
}

func makeEmptyTextLabel() -> UILabel {
let label = UILabel()
label.textColor = Theme.color(usage: .gray)
label.text = "Empty folder"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

если используешь внутренний текст (объявлен внутри класса), то используй такой вариант:

// MARK: - Appearance
private extension AboutViewController {
	enum Appearance {
		static let welcomeText = "Welcome to About"
		static let title = "About"
	}
}

и используй как label.text = Appearance.welcomeText

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Но этого тебе здесь не надо, нам нужна вьюха, которая принимает картинку и текст.

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 = 16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing надо использовать из Theme
stackContainer.spacing = Theme.spacing(usage: .standard2)
мой косяк дал пример, а сам в нем не избавился от магический цифр


let insets = UIEdgeInsets(
top: 0,
left: 16,
bottom: 16,
right: 16
Comment on lines +67 to +70
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь тоже из темы

)

[
emptyPictureLabel,
emptyTextLabel
].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()
return Group {
VStack(spacing: 0) {
emptyView.preview().frame(height: 100).padding(.bottom, 20)
}
.preferredColorScheme(.light)
}
}
}
#endif