Skip to content

Commit

Permalink
Merge pull request #531 from huihuisang/fix/AttributedText-layout-issue
Browse files Browse the repository at this point in the history
Replace AttributedText with Text and markdown to fix the layout issues
  • Loading branch information
MattKiazyk authored Mar 17, 2024
2 parents dbf3000 + b5e50c6 commit b17fbf5
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 118 deletions.
39 changes: 8 additions & 31 deletions Xcodes/Frontend/Preferences/DownloadPreferencePane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ struct DownloadPreferencePane: View {
.labelsHidden()
.fixedSize()

AttributedText(dataSourceFootnote)
Text("DataSourceDescription")
.font(.footnote)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
}

}
.groupBoxStyle(PreferencesGroupBoxStyle())

Expand All @@ -37,40 +39,15 @@ struct DownloadPreferencePane: View {
.labelsHidden()
.fixedSize()

AttributedText(downloaderFootnote)
Text("DownloaderDescription")
.font(.footnote)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
}

}
.groupBoxStyle(PreferencesGroupBoxStyle())

}
}

private var dataSourceFootnote: NSAttributedString {
let string = localizeString("DataSourceDescription")
let attributedString = NSMutableAttributedString(
string: string,
attributes: [
.font: NSFont.preferredFont(forTextStyle: .footnote, options: [:]),
.foregroundColor: NSColor.secondaryLabelColor
]
)
attributedString.addAttribute(.link, value: URL(string: "https://xcodereleases.com")!, range: NSRange(string.range(of: "Xcode Releases")!, in: string))
return attributedString
}

private var downloaderFootnote: NSAttributedString {
let string = localizeString("DownloaderDescription")
let attributedString = NSMutableAttributedString(
string: string,
attributes: [
.font: NSFont.preferredFont(forTextStyle: .footnote, options: [:]),
.foregroundColor: NSColor.secondaryLabelColor
]
)
attributedString.addAttribute(.link, value: URL(string: "https://github.com/aria2/aria2")!, range: NSRange(string.range(of: "aria2")!, in: string))
return attributedString
}
}

struct DownloadPreferencePane_Previews: PreviewProvider {
Expand Down
21 changes: 5 additions & 16 deletions Xcodes/Frontend/Preferences/ExperiementsPreferencePane.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AppleAPI
import SwiftUI
import Path
import SwiftUI

struct ExperimentsPreferencePane: View {
@EnvironmentObject var appState: AppState
Expand All @@ -13,27 +13,16 @@ struct ExperimentsPreferencePane: View {
"UseUnxipExperiment",
isOn: $appState.unxipExperiment
)
AttributedText(unxipFootnote)
Text("FasterUnxipDescription")
.font(.footnote)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
}
.fixedSize(horizontal: false, vertical: true)
}
.groupBoxStyle(PreferencesGroupBoxStyle())
}
}

private var unxipFootnote: NSAttributedString {
let string = localizeString("FasterUnxipDescription")
let attributedString = NSMutableAttributedString(
string: string,
attributes: [
.font: NSFont.preferredFont(forTextStyle: .footnote, options: [:]),
.foregroundColor: NSColor.secondaryLabelColor
]
)
attributedString.addAttribute(.link, value: URL(string: "https://twitter.com/_saagarjha")!, range: NSRange(string.range(of: "@_saagarjha")!, in: string))
attributedString.addAttribute(.link, value: URL(string: "https://github.com/saagarjha/unxip")!, range: NSRange(string.range(of: "https://github.com/saagarjha/unxip")!, in: string))
return attributedString
}
}

struct ExperimentsPreferencePane_Previews: PreviewProvider {
Expand Down
27 changes: 14 additions & 13 deletions Xcodes/Frontend/SignIn/SignInPhoneListView.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import SwiftUI
import AppleAPI
import SwiftUI

struct SignInPhoneListView: View {
@EnvironmentObject var appState: AppState
@Binding var isPresented: Bool
@State private var selectedPhoneNumberID: AuthOptionsResponse.TrustedPhoneNumber.ID?
let authOptions: AuthOptionsResponse
let sessionData: AppleSessionData

var body: some View {
VStack(alignment: .leading) {
if let phoneNumbers = authOptions.trustedPhoneNumbers, !phoneNumbers.isEmpty {
Text(String(format: localizeString("SelectTrustedPhone"), authOptions.securityCode.length))

List(phoneNumbers, selection: $selectedPhoneNumberID) {
Text($0.numberWithDialCode)
}
Expand All @@ -22,19 +22,18 @@ struct SignInPhoneListView: View {
}
}
} else {
AttributedText(
NSAttributedString(string: localizeString("NoTrustedPhones"))
.convertingURLsToLinkAttributes()
)
Text("NoTrustedPhones")
.font(.callout)
Spacer()
}

HStack {
Button("Cancel", action: { isPresented = false })
.keyboardShortcut(.cancelAction)
Spacer()
ProgressButton(isInProgress: appState.isProcessingAuthRequest,
action: { appState.requestSMS(to: authOptions.trustedPhoneNumbers!.first { $0.id == selectedPhoneNumberID }!, authOptions: authOptions, sessionData: sessionData) }) {
action: { appState.requestSMS(to: authOptions.trustedPhoneNumbers!.first { $0.id == selectedPhoneNumberID }!, authOptions: authOptions, sessionData: sessionData) })
{
Text("Continue")
}
.keyboardShortcut(.defaultAction)
Expand All @@ -54,19 +53,21 @@ struct SignInPhoneListView_Previews: PreviewProvider {
SignInPhoneListView(
isPresented: .constant(true),
authOptions: AuthOptionsResponse(
trustedPhoneNumbers: [.init(id: 0, numberWithDialCode: "(•••) •••-••90")],
trustedPhoneNumbers: [.init(id: 0, numberWithDialCode: "(•••) •••-••90")],
trustedDevices: nil,
securityCode: .init(length: 6)),
securityCode: .init(length: 6)
),
sessionData: AppleSessionData(serviceKey: "", sessionID: "", scnt: "")
)
.environmentObject(AppState())

SignInPhoneListView(
isPresented: .constant(true),
authOptions: AuthOptionsResponse(
trustedPhoneNumbers: [],
trustedPhoneNumbers: [],
trustedDevices: nil,
securityCode: .init(length: 6)),
securityCode: .init(length: 6)
),
sessionData: AppleSessionData(serviceKey: "", sessionID: "", scnt: "")
)
.environmentObject(AppState())
Expand Down
Loading

0 comments on commit b17fbf5

Please sign in to comment.