Skip to content
Merged
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
14 changes: 14 additions & 0 deletions V2er/General/Extentions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import SwiftUI
import SafariServices

extension String {
static let `default`: String = ""
Expand Down Expand Up @@ -116,7 +117,7 @@
// })
// }

subscript<K, V>(_ key: K) -> Binding<V> where Value == [K:V], K: Hashable {

Check failure on line 120 in V2er/General/Extentions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Colon Spacing Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals (colon)
.init(get: {
self.wrappedValue[key]!
},
Expand Down Expand Up @@ -200,7 +201,7 @@


extension UIFont {
static func prfered(_ font: Font) -> UIFont {

Check failure on line 204 in V2er/General/Extentions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Cyclomatic Complexity Violation: Function should have complexity 10 or less; currently complexity is 11 (cyclomatic_complexity)
let uiFont: UIFont

switch font {
Expand Down Expand Up @@ -256,8 +257,8 @@


extension URL {
func params() -> [String : String] {

Check failure on line 260 in V2er/General/Extentions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Colon Spacing Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals (colon)
var dict = [String : String]()

Check failure on line 261 in V2er/General/Extentions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Colon Spacing Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals (colon)

if let components = URLComponents(url: self, resolvingAgainstBaseURL: false) {
if let queryItems = components.queryItems {
Expand All @@ -267,7 +268,20 @@
}
return dict
} else {
return [ : ]

Check failure on line 271 in V2er/General/Extentions.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Colon Spacing Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals (colon)
}
}
}


// MARK: - Safari View
struct SafariView: UIViewControllerRepresentable {
let url: URL

func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController {
return SFSafariViewController(url: url)
}

func updateUIViewController(_ uiViewController: SFSafariViewController, context: UIViewControllerRepresentableContext<SafariView>) {
}
}
21 changes: 20 additions & 1 deletion V2er/View/FeedDetail/FeedDetailPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
//

import SwiftUI
import SafariServices

struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable {
@Environment(\.isPresented) private var isPresented
@Environment(\.dismiss) var dismiss
@EnvironmentObject private var store: Store
@State var rendered: Bool = false
@State private var showingSafari = false
@State private var safariURL: URL?

var bindingState: Binding<FeedDetailState> {
if store.appState.feedDetailStates[instanceId] == nil {
Expand Down Expand Up @@ -57,6 +60,11 @@ struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable {
var body: some View {
contentView
.navigatable()
.sheet(isPresented: $showingSafari) {
if let url = safariURL {
SafariView(url: url)
}
}
}

@ViewBuilder
Expand Down Expand Up @@ -134,7 +142,7 @@ struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable {
} label: {
Image(systemName: "arrow.up.circle.fill")
.font(.title.weight(.regular))
.foregroundColor(Color.bodyText.opacity(hasReplyContent ? 1.0 : 0.6))
.foregroundColor(Color.tintColor.opacity(hasReplyContent ? 1.0 : 0.6))
.padding(.trailing, 6)
.padding(.vertical, 3)
}
Expand Down Expand Up @@ -231,6 +239,17 @@ struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable {
Label(reported ? "已举报" : "举报", systemImage: "person.crop.circle.badge.exclamationmark")
}
.disabled(reported)

Divider()

Button {
if let url = URL(string: APIService.baseUrlString + "/t/\(id)") {
safariURL = url
showingSafari = true
}
} label: {
Label("使用浏览器打开", systemImage: "safari")
}
} label: {
Image(systemName: "ellipsis")
.padding(8)
Expand Down
2 changes: 2 additions & 0 deletions V2er/View/FeedDetail/ReplyItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ struct ReplyItemView: View {
HStack {
VStack (alignment: .leading, spacing: 4) {
Text(info.userName)
.foregroundColor(.primaryText)
Text(info.time)
.font(.caption2)
.foregroundColor(.secondaryText)
}
Spacer()
// Image(systemName: "heart")
Expand Down
4 changes: 3 additions & 1 deletion V2er/View/Me/UserDetailPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,13 @@ struct UserDetailPage: StateView {
struct ReplyItemView: View {
var data: UserDetailInfo.ReplyInfo.Item
let quoteFont = Style.font(UIFont.prfered(.footnote))
.foregroundColor(Color.bodyText.uiColor)
.foregroundColor(Color.primaryText.uiColor)

var body: some View {
VStack(spacing: 0) {
Text(data.title)
.font(.footnote)
.foregroundColor(.primaryText)
.greedyWidth(.leading)
RichText {
data.content
Expand All @@ -272,6 +273,7 @@ struct UserDetailPage: StateView {
.padding(.vertical, 6)
Text(data.time)
.font(.footnote)
.foregroundColor(.secondaryText)
.greedyWidth(.trailing)
}
.padding(12)
Expand Down
5 changes: 4 additions & 1 deletion V2er/View/Me/UserFeedPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct UserFeedPage: StateView, InstanceIdentifiable {
HStack(alignment: .top) {
VStack(alignment: .leading, spacing: 5) {
Text(data.userName)
.foregroundColor(.primaryText)
.lineLimit(1)
Text(data.replyUpdate)
.lineLimit(1)
Expand All @@ -67,19 +68,21 @@ struct UserFeedPage: StateView, InstanceIdentifiable {
NavigationLink(destination: TagDetailPage()) {
Text(data.tag)
.font(.footnote)
.foregroundColor(.black)
.foregroundColor(.primaryText)
.lineLimit(1)
.padding(.horizontal, 14)
.padding(.vertical, 8)
.background(Color.lightGray)
}
}
Text(data.title)
.foregroundColor(.primaryText)
.greedyWidth(.leading)
.lineLimit(2)
Text("评论\(data.replyNum)")
.lineLimit(1)
.font(.footnote)
.foregroundColor(.secondaryText)
.greedyWidth(.trailing)
}
.padding(12)
Expand Down
2 changes: 1 addition & 1 deletion V2er/View/Settings/OtherSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct OtherSettingsView: View {
.foregroundColor(Color.tintColor)
Image(systemName: "chevron.right")
.font(.body.weight(.regular))
.foregroundColor(.gray)
.foregroundColor(.secondaryText)
.padding(.trailing, 16)
}
}
Expand Down
26 changes: 25 additions & 1 deletion V2er/View/Settings/SettingsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import SwiftUI
import SafariServices

struct SettingsPage: View {
@Environment(\.dismiss) var dismiss
Expand All @@ -29,8 +30,12 @@ struct SettingsPage: View {
SectionItemView("通用设置")
.to { OtherSettingsView() }

SectionItemView("帮助与反馈")
SectionItemView("问题反馈")
.padding(.top, 8)
.to {
SafariWebView(url: "https://github.com/v2er-app/iOS/issues")
}
SectionItemView("V2EX帮助")
.to {
WebBrowserView(url: "https://www.v2ex.com/help")
}
Expand Down Expand Up @@ -103,6 +108,25 @@ struct SettingsPage: View {
}
}

struct SafariWebView: View {
let url: String
@State private var showingSafari = false

var body: some View {
Color.clear
.onAppear {
if let url = URL(string: url) {
showingSafari = true
}
}
.sheet(isPresented: $showingSafari) {
if let url = URL(string: url) {
SafariView(url: url)
}
}
}
}

struct SettingsPage_Previews: PreviewProvider {
static var previews: some View {
SettingsPage()
Expand Down
9 changes: 7 additions & 2 deletions V2er/View/Widget/MultilineTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fileprivate struct UITextViewWrapper: UIViewRepresentable {
textField.isUserInteractionEnabled = true
textField.isScrollEnabled = false
textField.backgroundColor = UIColor.clear
textField.textColor = Color.bodyText.uiColor
textField.textColor = Color.primaryText.uiColor

// textField.textContainer.maximumNumberOfLines = 5

Expand All @@ -42,6 +42,11 @@ fileprivate struct UITextViewWrapper: UIViewRepresentable {
if uiView.text != self.text {
uiView.text = self.text
}
// Update text color to ensure it responds to theme changes
let desiredColor = Color.primaryText.uiColor
if uiView.textColor != desiredColor {
uiView.textColor = desiredColor
}
if uiView.window != nil, !uiView.isFirstResponder {
// uiView.becomeFirstResponder()
}
Expand Down Expand Up @@ -127,7 +132,7 @@ struct MultilineTextField: View {
Group {
if showingPlaceholder {
Text(placeholder)
.foregroundColor(.gray)
.foregroundColor(.secondaryText)
.padding(.leading, 4)
}
}
Expand Down
2 changes: 1 addition & 1 deletion V2er/View/Widget/RichText/RichText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct RichText: View {

struct Styles {
public static let base = Style.font(UIFont.prfered(.body))
.foregroundColor(Color.bodyText.uiColor)
.foregroundColor(Color.primaryText.uiColor)
public static let link = Style("a")
.font(.boldSystemFont(ofSize: 16))
.foregroundColor(Color.url.uiColor, .normal)
Expand Down
Loading