Add Select Status Text Action (#1731)

* add select text action

* Fixes

---------

Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
This commit is contained in:
Thai D. V 2023-12-14 12:46:16 +07:00 committed by GitHub
parent 71f090552a
commit 81ba1e9bee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 186 additions and 3 deletions

View File

@ -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" : {
"extractionState" : "manual",
"localizations" : {

View File

@ -22,13 +22,14 @@ public struct StatusRowView: View {
@Environment(Theme.self) private var theme
@State private var viewModel: StatusRowViewModel
@State private var showSelectableText: Bool = false
public init(viewModel: StatusRowViewModel) {
_viewModel = .init(initialValue: viewModel)
}
var contextMenu: some View {
StatusRowContextMenu(viewModel: viewModel)
StatusRowContextMenu(viewModel: viewModel, showTextForSelection: $showSelectableText)
}
public var body: some View {
@ -196,6 +197,10 @@ public struct StatusRowView: View {
.alignmentGuide(.listRowSeparatorLeading) { _ in
-100
}
.sheet(isPresented: $showSelectableText) {
let content = viewModel.status.reblog?.content.asSafeMarkdownAttributedString ?? viewModel.status.content.asSafeMarkdownAttributedString
SelectTextView(content: content)
}
.environment(
StatusDataControllerProvider.shared.dataController(for: viewModel.finalStatus,
client: viewModel.client)

View File

@ -18,6 +18,7 @@ struct StatusRowContextMenu: View {
@Environment(QuickLook.self) private var quickLook
var viewModel: StatusRowViewModel
@Binding var showTextForSelection: Bool
var boostLabel: some View {
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")
}
Button {
showTextForSelection = true
} label: {
Label("status.action.select-text", systemImage: "selection.pin.in.out")
}
Button {
UIPasteboard.general.string = viewModel.status.reblog?.url ?? viewModel.status.url
} label: {
@ -271,3 +278,50 @@ struct ActivityView: UIViewControllerRepresentable {
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 {}
}

View File

@ -11,6 +11,7 @@ struct StatusRowHeaderView: View {
@Environment(Theme.self) private var theme
let viewModel: StatusRowViewModel
@State private var showTextForSelection: Bool = false
var body: some View {
HStack(alignment: .center) {
@ -26,6 +27,10 @@ struct StatusRowHeaderView: View {
contextMenuButton
}
}
.sheet(isPresented: $showTextForSelection) {
let content = viewModel.status.reblog?.content.asSafeMarkdownAttributedString ?? viewModel.status.content.asSafeMarkdownAttributedString
SelectTextView(content: content)
}
.accessibilityElement(children: .combine)
.accessibilityLabel(Text("\(viewModel.finalStatus.account.safeDisplayName)") + Text(", ") + Text(viewModel.finalStatus.createdAt.relativeFormatted))
.accessibilityAction {
@ -33,7 +38,7 @@ struct StatusRowHeaderView: View {
}
.accessibilityActions {
if isFocused {
StatusRowContextMenu(viewModel: viewModel)
StatusRowContextMenu(viewModel: viewModel, showTextForSelection: $showTextForSelection)
}
}
}
@ -120,7 +125,7 @@ struct StatusRowHeaderView: View {
private var contextMenuButton: some View {
Menu {
StatusRowContextMenu(viewModel: viewModel)
StatusRowContextMenu(viewModel: viewModel, showTextForSelection: $showTextForSelection)
.onAppear {
Task {
await viewModel.loadAuthorRelationship()