Skip to content

Commit e12bd7d

Browse files
authored
[Predecessor] [DoNotUse] Add some predecessor modules and support them temporarily! (#32)
[Predecessor] [DoNotUse] Add some predecessor modules and support them temporarily!
2 parents cdace34 + 30ffc5f commit e12bd7d

30 files changed

Lines changed: 1615 additions & 0 deletions
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//
2+
// CoverView.swift
3+
// CyberCurrency
4+
//
5+
// Created by Lingxi Li on 12/17/20.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
/// DefinedCover - 封面组件 @ DefinedElements
12+
///
13+
/// - TODO: Style
14+
@available(iOS 14.0, macOS 11.0, *)
15+
public struct DefinedCover : DefinedView {
16+
///
17+
var content: AnyView
18+
19+
///
20+
@ObservedObject var obs = CoverObserver()
21+
22+
///
23+
public init(title: String, subtitle: String? = nil) {
24+
var cont: some View {
25+
DefinedText(title)
26+
.preset(.title)
27+
}
28+
self.content = AnyView(cont)
29+
}
30+
31+
///
32+
public init<Content>(@ViewBuilder _ cont: @escaping () -> Content) where Content : View {
33+
self.content = AnyView(cont())
34+
}
35+
36+
///
37+
public func touchBackground<TouchBackground>(_ content: TouchBackground) -> Self where TouchBackground : View {
38+
self.obs.touchBackground = AnyView(content)
39+
return self
40+
}
41+
42+
///
43+
public func touchBackground<TouchBackground>(@ViewBuilder content: @escaping () -> TouchBackground) -> Self where TouchBackground : View {
44+
self.obs.touchBackground = AnyView(content())
45+
return self
46+
}
47+
48+
///
49+
public func background<Background>(_ content: Background) -> Self where Background : View {
50+
self.obs.background = AnyView(content)
51+
return self
52+
}
53+
54+
///
55+
public func background<Background>(@ViewBuilder content: @escaping () -> Background) -> Self where Background : View {
56+
self.obs.background = AnyView(content())
57+
return self
58+
}
59+
60+
/// - Warning: 暂未投入使用!
61+
public func foreground<Foreground>(_ content: Foreground) -> Self where Foreground : View {
62+
self.obs.foreground = AnyView(content)
63+
return self
64+
}
65+
66+
/// - Warning: 暂未投入使用!
67+
public func foreground<Foreground>(@ViewBuilder content: @escaping () -> Foreground) -> Self where Foreground : View {
68+
self.obs.foreground = AnyView(content())
69+
return self
70+
}
71+
72+
///
73+
public func position(_ position: CoverPosition) -> Self {
74+
self.obs.position = position
75+
return self
76+
}
77+
78+
///
79+
public func showDivider(_ showDivider: Bool) -> Self {
80+
self.obs.divider = showDivider
81+
return self
82+
}
83+
84+
// TODO: 直接传入文字信息的构造器
85+
86+
///
87+
public var body: some View {
88+
ZStack(alignment: .center) {
89+
content
90+
}
91+
.frame(maxWidth: .infinity, alignment: .center)
92+
.frame(height: self.obs.height)
93+
}
94+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Lingxi Li on 4/29/21.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
///
12+
public enum CoverPosition {
13+
case center
14+
15+
case top
16+
17+
case bottom
18+
}
19+
20+
public extension CoverPosition {
21+
func get() -> Alignment {
22+
switch self {
23+
case .center:
24+
return .center
25+
case .top:
26+
return .top
27+
case .bottom:
28+
return .bottom
29+
}
30+
}
31+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Lingxi Li on 5/5/21.
6+
//
7+
8+
import Foundation
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Lingxi Li on 4/7/21.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
class CoverObserver : ObservableObject {
12+
///
13+
@Published var touchBackground: AnyView = AnyView(EmptyView())
14+
15+
///
16+
@Published var background: AnyView = AnyView(DEColor.bg.light_3)
17+
18+
///
19+
@Published var foreground: AnyView = AnyView(EmptyView())
20+
21+
///
22+
@Published var height: CGFloat = 260
23+
24+
///
25+
@Published var position: CoverPosition = .center
26+
27+
///
28+
@Published var divider: Bool = false
29+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Lingxi Li on 4/17/21.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
/// DefinedCoverHeader - 封面顶栏 @ DefinedElements
12+
///
13+
/// - Important: `CoverHeader`组件是专为`ScrollView`开发的,非滚动页面的头部不应使用该组件
14+
///
15+
/// - TODO: 开发
16+
/// - TODO: 将Namespace尝试传入不同组件,在不同组件内增加对应init
17+
public struct DefinedCoverHeader {
18+
19+
///
20+
@ObservedObject var obs: CoverHeaderObserver = CoverHeaderObserver()
21+
22+
///
23+
@Namespace var coverHeaderSpace
24+
25+
///
26+
var style: CoverHeaderStyle = .magazine
27+
28+
///
29+
var icon: Image? = nil
30+
31+
///
32+
var title: String
33+
34+
///
35+
var subtitle: String? = nil
36+
37+
///
38+
var backButtonType: _BackButtonConfiguration = .arrow
39+
40+
///
41+
public init(title: String,
42+
subtitle: String? = nil,
43+
icon: Image? = nil,
44+
back: _BackButtonConfiguration = .arrow,
45+
style: CoverHeaderStyle = .magazine) {
46+
self.title = title
47+
self.subtitle = subtitle
48+
self.icon = icon
49+
self.backButtonType = back
50+
}
51+
52+
///
53+
func getCover() -> DefinedCover {
54+
// TODO: 未来支持自定义背景与触摸背景
55+
let cover = DefinedCover(buildCover)
56+
cover.obs.position = getCoverPosition()
57+
return cover
58+
}
59+
60+
///
61+
func getHeader() -> DefinedHeader {
62+
let header = DefinedHeader(back: self.backButtonType, buildHeader)
63+
self.obs.headerObs = header.obs
64+
return header
65+
}
66+
67+
///
68+
@ViewBuilder func buildCover() -> some View {
69+
// 杂志封面
70+
// TODO: 动效
71+
if self.style == .magazine {
72+
DefinedContent(.overlay, alignment: .leading) {
73+
DefinedContent(.vertical, alignment: .leading) {
74+
DefinedText(self.title)
75+
.preset(.title)
76+
.padding(.bottom, 2)
77+
78+
// TODO: 问题在于此处调用obs并不会进行实时更新
79+
80+
if self.subtitle != nil {
81+
DefinedText(self.subtitle!)
82+
.preset(.subtitle)
83+
.contentColor(DEColor.text.dark_4)
84+
.padding(.top, 12)
85+
}
86+
}
87+
.padding(.horizontal, 30)
88+
.padding(.vertical, 33)
89+
.definedSize(width: .full)
90+
}
91+
.definedSize(width: .full, height: .full, alignment: .bottom)
92+
}
93+
94+
//
95+
if self.style == .center {
96+
EmptyView()
97+
}
98+
99+
//
100+
if self.style == .center_side {
101+
EmptyView()
102+
}
103+
}
104+
105+
///
106+
@ViewBuilder func buildHeader() -> some View {
107+
DefinedText(self.title)
108+
.preset(.header_title)
109+
// .matchedGeometryEffect(id: "title", in: coverHeaderSpace)
110+
}
111+
112+
///
113+
func getCoverPosition() -> CoverPosition {
114+
switch self.style {
115+
case .magazine:
116+
return .bottom
117+
default:
118+
return .center
119+
}
120+
}
121+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Lingxi Li on 4/20/21.
6+
//
7+
8+
import Foundation
9+
import SwiftUI
10+
11+
///
12+
public enum CoverHeaderStyle {
13+
///
14+
case center
15+
16+
///
17+
case center_side
18+
19+
///
20+
case magazine
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Lingxi Li on 4/21/21.
6+
//
7+
8+
import Foundation
9+
10+
///
11+
class CoverHeaderObserver : ObservableObject {
12+
///
13+
@Published var coverObs: CoverObserver? = nil
14+
15+
///
16+
@Published var headerObs: HeaderObserver? = nil
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import SwiftUI
2+
3+
///
4+
public enum DefinedSafeAreaConfiguration {
5+
///
6+
case none
7+
8+
///
9+
case vertical
10+
11+
///
12+
case top
13+
14+
///
15+
case bottom
16+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import SwiftUI
2+
3+
/// 安全区域豁免 - 视图修改器 @ DefinedElements
4+
struct DefinedSafeAreaModifier: ViewModifier {
5+
/// 豁免方向
6+
var area: DefinedSafeAreaConfiguration
7+
8+
/// 构造器 < 内部构造器 >
9+
///
10+
/// - Parameters:
11+
/// - area: 豁免方向
12+
init(area: DefinedSafeAreaConfiguration = .vertical) {
13+
self.area = area
14+
}
15+
16+
///
17+
@ViewBuilder func body(content: Content) -> some View {
18+
if (area == .top) {
19+
content
20+
.edgesIgnoringSafeArea(.top)
21+
} else if (area == .bottom) {
22+
content
23+
.edgesIgnoringSafeArea(.bottom)
24+
} else if (area == .vertical) {
25+
content
26+
.edgesIgnoringSafeArea(.vertical)
27+
} else {
28+
content
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)