Cache images for MenuPickers, minor perf optimization when opening compose screen
This commit is contained in:
parent
dc7eaf5ada
commit
c5cc959014
@ -118,6 +118,12 @@ private struct ContentWarningButton: View {
|
||||
}
|
||||
|
||||
private struct VisibilityButton: View {
|
||||
private static var allOptions: [MenuPicker<Pachyderm.Visibility>.Option] {
|
||||
Pachyderm.Visibility.allCases.map { vis in
|
||||
.init(value: vis, title: vis.displayName, subtitle: vis.subtitle, image: UIImage(systemName: vis.unfilledImageName), accessibilityLabel: "Visibility: \(vis.displayName)")
|
||||
}
|
||||
}
|
||||
|
||||
@ObservedObject var draft: Draft
|
||||
@ObservedObject var instanceFeatures: InstanceFeatures
|
||||
|
||||
@ -133,14 +139,10 @@ private struct VisibilityButton: View {
|
||||
}
|
||||
|
||||
private var visibilityOptions: [MenuPicker<Pachyderm.Visibility>.Option] {
|
||||
let visibilities: [Pachyderm.Visibility]
|
||||
if !instanceFeatures.composeDirectStatuses {
|
||||
visibilities = [.public, .unlisted, .private]
|
||||
Self.allOptions.filter { $0.value != .direct }
|
||||
} else {
|
||||
visibilities = Pachyderm.Visibility.allCases
|
||||
}
|
||||
return visibilities.map { vis in
|
||||
.init(value: vis, title: vis.displayName, subtitle: vis.subtitle, image: UIImage(systemName: vis.unfilledImageName), accessibilityLabel: "Visibility: \(vis.displayName)")
|
||||
Self.allOptions
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,6 +154,9 @@ private struct VisibilityButton: View {
|
||||
}
|
||||
|
||||
private struct LocalOnlyButton: View {
|
||||
private static let localOnlyImage = UIImage(named: "link.broken")!
|
||||
private static let federatedImage = UIImage(systemName: "link")!
|
||||
|
||||
@Binding var enabled: Bool
|
||||
var mastodonController: any ComposeMastodonContext
|
||||
@ObservedObject private var instanceFeatures: InstanceFeatures
|
||||
@ -165,8 +170,8 @@ private struct LocalOnlyButton: View {
|
||||
private var options: [MenuPicker<Bool>.Option] {
|
||||
let domain = mastodonController.accountInfo!.instanceURL.host!
|
||||
return [
|
||||
.init(value: true, title: "Local-only", subtitle: "Only \(domain)", image: UIImage(named: "link.broken")),
|
||||
.init(value: false, title: "Federated", image: UIImage(systemName: "link")),
|
||||
.init(value: true, title: "Local-only", subtitle: "Only \(domain)", image: Self.localOnlyImage),
|
||||
.init(value: false, title: "Federated", image: Self.federatedImage),
|
||||
]
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user