mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-04-27 02:14:45 +00:00
Add Select Status Text Action (#1731)
* add select text action * Fixes --------- Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
This commit is contained in:
parent
71f090552a
commit
81ba1e9bee
4 changed files with 186 additions and 3 deletions
|
@ -57843,6 +57843,125 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"status.action.select-text" : {
|
||||||
|
"extractionState" : "manual",
|
||||||
|
"localizations" : {
|
||||||
|
"be" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ca" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"de" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"en-GB" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"es" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"eu" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fr" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "translated",
|
||||||
|
"value" : "Sélectionner le texte"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"it" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ja" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ko" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nb" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nl" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pl" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pt-BR" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tr" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"uk" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hans" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zh-Hant" : {
|
||||||
|
"stringUnit" : {
|
||||||
|
"state" : "needs_review",
|
||||||
|
"value" : "Select Text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"status.action.share" : {
|
"status.action.share" : {
|
||||||
"extractionState" : "manual",
|
"extractionState" : "manual",
|
||||||
"localizations" : {
|
"localizations" : {
|
||||||
|
|
|
@ -22,13 +22,14 @@ public struct StatusRowView: View {
|
||||||
@Environment(Theme.self) private var theme
|
@Environment(Theme.self) private var theme
|
||||||
|
|
||||||
@State private var viewModel: StatusRowViewModel
|
@State private var viewModel: StatusRowViewModel
|
||||||
|
@State private var showSelectableText: Bool = false
|
||||||
|
|
||||||
public init(viewModel: StatusRowViewModel) {
|
public init(viewModel: StatusRowViewModel) {
|
||||||
_viewModel = .init(initialValue: viewModel)
|
_viewModel = .init(initialValue: viewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
var contextMenu: some View {
|
var contextMenu: some View {
|
||||||
StatusRowContextMenu(viewModel: viewModel)
|
StatusRowContextMenu(viewModel: viewModel, showTextForSelection: $showSelectableText)
|
||||||
}
|
}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
|
@ -196,6 +197,10 @@ public struct StatusRowView: View {
|
||||||
.alignmentGuide(.listRowSeparatorLeading) { _ in
|
.alignmentGuide(.listRowSeparatorLeading) { _ in
|
||||||
-100
|
-100
|
||||||
}
|
}
|
||||||
|
.sheet(isPresented: $showSelectableText) {
|
||||||
|
let content = viewModel.status.reblog?.content.asSafeMarkdownAttributedString ?? viewModel.status.content.asSafeMarkdownAttributedString
|
||||||
|
SelectTextView(content: content)
|
||||||
|
}
|
||||||
.environment(
|
.environment(
|
||||||
StatusDataControllerProvider.shared.dataController(for: viewModel.finalStatus,
|
StatusDataControllerProvider.shared.dataController(for: viewModel.finalStatus,
|
||||||
client: viewModel.client)
|
client: viewModel.client)
|
||||||
|
|
|
@ -18,6 +18,7 @@ struct StatusRowContextMenu: View {
|
||||||
@Environment(QuickLook.self) private var quickLook
|
@Environment(QuickLook.self) private var quickLook
|
||||||
|
|
||||||
var viewModel: StatusRowViewModel
|
var viewModel: StatusRowViewModel
|
||||||
|
@Binding var showTextForSelection: Bool
|
||||||
|
|
||||||
var boostLabel: some View {
|
var boostLabel: some View {
|
||||||
if viewModel.status.visibility == .priv, viewModel.status.account.id == account.account?.id {
|
if viewModel.status.visibility == .priv, viewModel.status.account.id == account.account?.id {
|
||||||
|
@ -132,6 +133,12 @@ struct StatusRowContextMenu: View {
|
||||||
Label("status.action.copy-text", systemImage: "doc.on.doc")
|
Label("status.action.copy-text", systemImage: "doc.on.doc")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
showTextForSelection = true
|
||||||
|
} label: {
|
||||||
|
Label("status.action.select-text", systemImage: "selection.pin.in.out")
|
||||||
|
}
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
UIPasteboard.general.string = viewModel.status.reblog?.url ?? viewModel.status.url
|
UIPasteboard.general.string = viewModel.status.reblog?.url ?? viewModel.status.url
|
||||||
} label: {
|
} label: {
|
||||||
|
@ -271,3 +278,50 @@ struct ActivityView: UIViewControllerRepresentable {
|
||||||
|
|
||||||
func updateUIViewController(_: UIActivityViewController, context _: UIViewControllerRepresentableContext<ActivityView>) {}
|
func updateUIViewController(_: UIActivityViewController, context _: UIViewControllerRepresentableContext<ActivityView>) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct SelectTextView: View {
|
||||||
|
@Environment(\.dismiss) private var dismiss
|
||||||
|
let content: AttributedString
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
NavigationStack {
|
||||||
|
SelectableText(content: content)
|
||||||
|
.padding()
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .navigationBarTrailing) {
|
||||||
|
Button {
|
||||||
|
dismiss()
|
||||||
|
} label: {
|
||||||
|
Text("action.done").bold()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.background(Color.primaryBackground)
|
||||||
|
.navigationTitle("status.action.select-text")
|
||||||
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SelectableText: UIViewRepresentable {
|
||||||
|
let content: AttributedString
|
||||||
|
|
||||||
|
func makeUIView(context: Context) -> UITextView {
|
||||||
|
let attributedText = NSMutableAttributedString(content)
|
||||||
|
attributedText.addAttribute(
|
||||||
|
.font,
|
||||||
|
value: Font.scaledBodyFont,
|
||||||
|
range: NSRange(location: 0, length: content.characters.count)
|
||||||
|
)
|
||||||
|
|
||||||
|
let textView = UITextView()
|
||||||
|
textView.isEditable = false
|
||||||
|
textView.attributedText = attributedText
|
||||||
|
textView.textColor = UIColor(Color.label)
|
||||||
|
textView.backgroundColor = UIColor(Color.primaryBackground)
|
||||||
|
return textView
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateUIView(_ uiView: UITextView, context: Context) {}
|
||||||
|
func makeCoordinator() -> Void {}
|
||||||
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ struct StatusRowHeaderView: View {
|
||||||
@Environment(Theme.self) private var theme
|
@Environment(Theme.self) private var theme
|
||||||
|
|
||||||
let viewModel: StatusRowViewModel
|
let viewModel: StatusRowViewModel
|
||||||
|
@State private var showTextForSelection: Bool = false
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack(alignment: .center) {
|
HStack(alignment: .center) {
|
||||||
|
@ -26,6 +27,10 @@ struct StatusRowHeaderView: View {
|
||||||
contextMenuButton
|
contextMenuButton
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.sheet(isPresented: $showTextForSelection) {
|
||||||
|
let content = viewModel.status.reblog?.content.asSafeMarkdownAttributedString ?? viewModel.status.content.asSafeMarkdownAttributedString
|
||||||
|
SelectTextView(content: content)
|
||||||
|
}
|
||||||
.accessibilityElement(children: .combine)
|
.accessibilityElement(children: .combine)
|
||||||
.accessibilityLabel(Text("\(viewModel.finalStatus.account.safeDisplayName)") + Text(", ") + Text(viewModel.finalStatus.createdAt.relativeFormatted))
|
.accessibilityLabel(Text("\(viewModel.finalStatus.account.safeDisplayName)") + Text(", ") + Text(viewModel.finalStatus.createdAt.relativeFormatted))
|
||||||
.accessibilityAction {
|
.accessibilityAction {
|
||||||
|
@ -33,7 +38,7 @@ struct StatusRowHeaderView: View {
|
||||||
}
|
}
|
||||||
.accessibilityActions {
|
.accessibilityActions {
|
||||||
if isFocused {
|
if isFocused {
|
||||||
StatusRowContextMenu(viewModel: viewModel)
|
StatusRowContextMenu(viewModel: viewModel, showTextForSelection: $showTextForSelection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +125,7 @@ struct StatusRowHeaderView: View {
|
||||||
|
|
||||||
private var contextMenuButton: some View {
|
private var contextMenuButton: some View {
|
||||||
Menu {
|
Menu {
|
||||||
StatusRowContextMenu(viewModel: viewModel)
|
StatusRowContextMenu(viewModel: viewModel, showTextForSelection: $showTextForSelection)
|
||||||
.onAppear {
|
.onAppear {
|
||||||
Task {
|
Task {
|
||||||
await viewModel.loadAuthorRelationship()
|
await viewModel.loadAuthorRelationship()
|
||||||
|
|
Loading…
Reference in a new issue