Skip to content

Commit

Permalink
一些视图优化
Browse files Browse the repository at this point in the history
  • Loading branch information
ming1016 committed Apr 18, 2024
1 parent dea9af2 commit e5f1933
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 62 deletions.
3 changes: 2 additions & 1 deletion SwiftPamphletApp/App/IntroView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ struct IntroView: View {
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 120, height: 120)
Text("戴铭的开发小册子").bold().font(.largeTitle)
Text("戴铭的开发小册子").bold()
Text("Swift Pamphlet App").gradientTitle(color: .mint)
HStack {
Text("一本活的开发手册")
Link("GitHub 地址", destination: URL(string: "https://github.com/ming1016/SwiftPamphletApp")!)
Expand Down
6 changes: 3 additions & 3 deletions SwiftPamphletApp/GitHubAPI/Developer/DeveloperListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ struct DeveloperListView: View {
VStack(alignment:.leading) {
Text(dev.repoOwner)
.font(.footnote)
.foregroundColor(light: .secondary, dark: .secondary)
.foregroundColor(.secondary)
Text(dev.repoName)
}
}

Spacer()
Text(howLongAgo(date: dev.updateDate))
.font(.footnote)
.foregroundColor(light: .secondary, dark: .secondary)
.foregroundColor(.secondary)
}
HStack {
Text(dev.des)
.font(.footnote)
.foregroundColor(light: .secondary, dark: .secondary)
.foregroundColor(.secondary)
Spacer()
}
Spacer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ struct EditCategoryView: View {
var body: some View {
VStack {
HStack {
TextField("请填写新增的分类名", text: $cate)
.tfRounded()
TextField("请填写新增的分类名", text: $cate).rounded()
.onSubmit {
add()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ struct EditCustomSearchView: View {
var body: some View {
VStack {
Text("自定检索,换行间隔,同行逗号间隔")
TextEditor(text: $term)
.te()
TextEditor(text: $term).border()
}
.padding(20)
}
Expand Down
51 changes: 30 additions & 21 deletions SwiftPamphletApp/InfoOrganizer/Info/EditInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ struct EditInfoView: View {
Form {
Section {
HStack {
TextField("标题:", text: $info.name)
.tfRounded()
TextField("标题:", text: $info.name).rounded()
Toggle(isOn: $info.star) {
Image(systemName: info.star ? "star.fill" : "star")
}
Expand All @@ -58,24 +57,19 @@ struct EditInfoView: View {
})
}
HStack {
TextField("地址:", text: $info.url, prompt: Text("输入或粘贴 url,例如 https://www.starming.com"))
.tfRounded()
TextField("地址:", text: $info.url, prompt: Text("输入或粘贴 url,例如 https://www.starming.com")).rounded()
.onSubmit {
Task {
// MARK: 获取 Web 内容
info.name = "获取标题中......"
let re = await fetchTitleFromUrl(urlString:info.url)
DispatchQueue.main.async {
if re.title.isEmpty == false {
info.name = re.title
if re.imageUrl.isEmpty == false {
IOInfo.updateCoverImage(info: info, img: IOImg(url: re.imageUrl))
}
info.imageUrls = re.imageUrls
}
}
} // end Task
await urlSubmit()
}
}
Button {
Task {
await urlSubmit()
}
} label: {
Text("解析")
}
if info.url.isEmpty == false {
Button {
gotoWebBrowser(urlStr: info.url)
Expand Down Expand Up @@ -158,8 +152,7 @@ struct EditInfoView: View {
Section(footer: Text("文本支持 markdown 格式")) {
// TODO: markdown 获取图片链接,并能显示
TabView(selection: $selectedTab) {
TextEditor(text: $info.des)
.te()
TextEditor(text: $info.des).border()
.padding(10)
.tabItem { Label("文本", systemImage: "circle") }
.tag(1)
Expand Down Expand Up @@ -188,8 +181,7 @@ struct EditInfoView: View {
.onChange(of: selectedPhotos) { oldValue, newValue in
convertDataToImage()
}
TextField("添加图片 url:", text: $addWebImageUrl)
.tfRounded()
TextField("添加图片 url:", text: $addWebImageUrl).rounded()
.onSubmit {
if let webImageUrl = URL(string: addWebImageUrl) {
info.imgs?.append(IOImg(url: webImageUrl.absoluteString))
Expand Down Expand Up @@ -330,6 +322,23 @@ struct EditInfoView: View {
} // end VStack
}

// MARK: 地址提交
func urlSubmit() async {

// MARK: 获取 Web 内容
info.name = "获取标题中......"
let re = await fetchTitleFromUrl(urlString:info.url)
DispatchQueue.main.async {
if re.title.isEmpty == false {
info.name = re.title
if re.imageUrl.isEmpty == false {
IOInfo.updateCoverImage(info: info, img: IOImg(url: re.imageUrl))
}
info.imageUrls = re.imageUrls
}
}
}

// MARK: 自定检索
@AppStorage(SPC.customSearchTerm) var term = ""
@State private var searchTerms: [[String]] = [[String]]()
Expand Down
14 changes: 10 additions & 4 deletions SwiftPamphletApp/InfoOrganizer/Info/InfoRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@ struct InfoRowView: View {
Text(shortDes())
.fixedSize(horizontal: false, vertical: true)
.font(.footnote)
.foregroundColor(light: .secondary, dark: .secondary)
.foregroundColor(.secondary)

HStack(alignment: .center) {
if info.category != nil {
Text(info.category?.name ?? "")
.padding(4)
// .background(.tertiary)
// .clipShape(.rect(cornerRadius: 4))
// .foregroundColor(.white)
.overlay {
RoundedRectangle(cornerRadius: 4)
.stroke(lineWidth: 1)
}
}

Spacer()
Expand All @@ -64,10 +72,8 @@ struct InfoRowView: View {
Image(systemName: "square.and.arrow.down.fill")
}
Text(howLongAgo(date: info.updateDate))
// Text(info.updateDate, style: .relative)

.foregroundColor(.secondary)
}
.foregroundColor(light: .secondary, dark: .secondary)
.font(.footnote)
.padding(EdgeInsets(top: 0, leading: 0, bottom: 10, trailing: 0))
}
Expand Down
2 changes: 1 addition & 1 deletion SwiftPamphletApp/Resource/Play/Guide/PlayWeatherKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct PDayDetailsCell: View {
Image(systemName: day.symbolName)
HStack {
Text("\(Int(day.lowTemperature.value))")
.foregroundColor(light: .secondary, dark: .secondary)
.foregroundColor(.secondary)
Text("\(Int(day.highTemperature.value))°")
.bold()
}
Expand Down
12 changes: 6 additions & 6 deletions SwiftPamphletApp/Resource/Play/SwiftUI/Vision/PlayColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct PlayColor: View {

VStack(spacing: 10) {
Text("这是一个适配了暗黑的文字颜色")
.foregroundColor(light: .purple, dark: .pink)
// .foregroundColor(light: .purple, dark: .pink)
.background(Color(nsColor: .quaternaryLabelColor)) // 使用以前 NSColor

Text("自定义颜色")
Expand Down Expand Up @@ -48,8 +48,8 @@ struct PCColorModifier: ViewModifier {
}
}

extension View {
func foregroundColor(light: Color, dark: Color) -> some View {
modifier(PCColorModifier(light: light, dark: dark))
}
}
//extension View {
// func foregroundColor(light: Color, dark: Color) -> some View {
// modifier(PCColorModifier(light: light, dark: dark))
// }
//}
2 changes: 1 addition & 1 deletion SwiftPamphletApp/ViewComponet/ViewComponentImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct NukeImage: View {
Color.gray.opacity(0.2) // Placeholder
Text(url.prefix(100))
.font(.footnote)
.foregroundColor(light: .secondary, dark: .secondary)
.foregroundColor(.secondary)
}
} else {
ProgressView()
Expand Down
39 changes: 18 additions & 21 deletions SwiftPamphletApp/ViewComponet/ViewStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,29 @@

import SwiftUI

struct TEModifier: ViewModifier {
func body(content: Content) -> some View {
content
.overlay(
Rectangle()
.stroke(.secondary, lineWidth: 1)
.opacity(0.5)
)
.disableAutocorrection(true)
}
}
extension View {
func te() -> some View {
modifier(TEModifier())
extension Text {
func gradientTitle(color: Color = .primary) -> some View {
font(.largeTitle)
.fontWeight(.bold)
.foregroundStyle(color.gradient)
.fontDesign(.rounded)
}
}

struct TFRoundedModifier: ViewModifier {
func body(content: Content) -> some View {
content
.textFieldStyle(RoundedBorderTextFieldStyle())
extension TextEditor {
func border() -> some View {
overlay(
Rectangle()
.stroke(.secondary, lineWidth: 1)
.opacity(0.5)
)
.disableAutocorrection(true)
}
}
extension View {
func tfRounded() -> some View {
modifier(TFRoundedModifier())

extension TextField {
func rounded() -> some View {
textFieldStyle(RoundedBorderTextFieldStyle())
}
}

Expand Down

0 comments on commit e5f1933

Please sign in to comment.