Allow highlighting to be disabled on SelectableText
Changed the interface of SelectableText to allow highlighting to be disabled in places where it is not applicable (For example, on the AboutView). This prevents the need for adding dummy events in places where highlighting is not applicable, preventing the user from making bad highlights. Testing ------- PASS Device: iPhone 13 mini iOS: 17.5 Damus: This version Steps: 1. Go to a user profile and select some text in their bio. The "highlight" option should not be present. 2. Go to a note and select some text. The "highlight" option should be available
This commit is contained in:
@@ -10,7 +10,7 @@ import SwiftUI
|
||||
|
||||
struct SelectableText: View {
|
||||
let damus_state: DamusState
|
||||
let event: NostrEvent
|
||||
let event: NostrEvent?
|
||||
let attributedString: AttributedString
|
||||
let textAlignment: NSTextAlignment
|
||||
@State private var showHighlightPost = false
|
||||
@@ -20,7 +20,7 @@ struct SelectableText: View {
|
||||
|
||||
let size: EventViewKind
|
||||
|
||||
init(damus_state: DamusState, event: NostrEvent, attributedString: AttributedString, textAlignment: NSTextAlignment? = nil, size: EventViewKind) {
|
||||
init(damus_state: DamusState, event: NostrEvent?, attributedString: AttributedString, textAlignment: NSTextAlignment? = nil, size: EventViewKind) {
|
||||
self.damus_state = damus_state
|
||||
self.event = event
|
||||
self.attributedString = attributedString
|
||||
@@ -36,6 +36,7 @@ struct SelectableText: View {
|
||||
font: eventviewsize_to_uifont(size),
|
||||
fixedWidth: selectedTextWidth,
|
||||
textAlignment: self.textAlignment,
|
||||
enableHighlighting: self.enableHighlighting(),
|
||||
showHighlightPost: $showHighlightPost,
|
||||
selectedText: $selectedText,
|
||||
height: $selectedTextHeight
|
||||
@@ -53,12 +54,18 @@ struct SelectableText: View {
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showHighlightPost) {
|
||||
HighlightPostView(damus_state: damus_state, event: event, selectedText: $selectedText)
|
||||
.presentationDragIndicator(.visible)
|
||||
.presentationDetents([.height(selectedTextHeight + 150), .medium, .large])
|
||||
if let event {
|
||||
HighlightPostView(damus_state: damus_state, event: event, selectedText: $selectedText)
|
||||
.presentationDragIndicator(.visible)
|
||||
.presentationDetents([.height(selectedTextHeight + 150), .medium, .large])
|
||||
}
|
||||
}
|
||||
.frame(height: selectedTextHeight)
|
||||
}
|
||||
|
||||
func enableHighlighting() -> Bool {
|
||||
self.event != nil
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate class TextView: UITextView {
|
||||
@@ -97,6 +104,7 @@ fileprivate class TextView: UITextView {
|
||||
let font: UIFont
|
||||
let fixedWidth: CGFloat
|
||||
let textAlignment: NSTextAlignment
|
||||
let enableHighlighting: Bool
|
||||
@Binding var showHighlightPost: Bool
|
||||
@Binding var selectedText: String
|
||||
@Binding var height: CGFloat
|
||||
@@ -115,7 +123,7 @@ fileprivate class TextView: UITextView {
|
||||
|
||||
let menuController = UIMenuController.shared
|
||||
let highlightItem = UIMenuItem(title: "Highlight", action: #selector(view.highlightText(_:)))
|
||||
menuController.menuItems = [highlightItem]
|
||||
menuController.menuItems = self.enableHighlighting ? [highlightItem] : []
|
||||
|
||||
return view
|
||||
}
|
||||
|
||||
@@ -26,11 +26,7 @@ struct AboutView: View {
|
||||
Group {
|
||||
if let about_string {
|
||||
let truncated_about = show_full_about ? about_string : about_string.truncateOrNil(maxLength: max_about_length)
|
||||
SelectableText(damus_state: state, event: NostrEvent(
|
||||
content: "",
|
||||
keypair: jack_keypair,
|
||||
createdAt: UInt32(Date().timeIntervalSince1970 - 100)
|
||||
)!, attributedString: truncated_about ?? about_string, textAlignment: self.text_alignment, size: .subheadline)
|
||||
SelectableText(damus_state: state, event: nil, attributedString: truncated_about ?? about_string, textAlignment: self.text_alignment, size: .subheadline)
|
||||
|
||||
if truncated_about != nil {
|
||||
if show_full_about {
|
||||
|
||||
Reference in New Issue
Block a user