dynamically set .isScrollEnabled in TextViewWrapper (true if UserSearch is present)
This commit is contained in:
committed by
William Casarin
parent
0f805d7ea7
commit
f9a572faa2
@@ -45,6 +45,7 @@ struct PostView: View {
|
|||||||
@State var references: [ReferencedId] = []
|
@State var references: [ReferencedId] = []
|
||||||
@State var focusWordAttributes: (String?, NSRange?) = (nil, nil)
|
@State var focusWordAttributes: (String?, NSRange?) = (nil, nil)
|
||||||
@State var newCursorIndex: Int?
|
@State var newCursorIndex: Int?
|
||||||
|
@State var postTextViewCanScroll: Bool = true
|
||||||
|
|
||||||
@State var mediaToUpload: MediaUpload? = nil
|
@State var mediaToUpload: MediaUpload? = nil
|
||||||
|
|
||||||
@@ -203,7 +204,7 @@ struct PostView: View {
|
|||||||
|
|
||||||
var TextEntry: some View {
|
var TextEntry: some View {
|
||||||
ZStack(alignment: .topLeading) {
|
ZStack(alignment: .topLeading) {
|
||||||
TextViewWrapper(attributedText: $post, cursorIndex: newCursorIndex, getFocusWordForMention: { word, range in
|
TextViewWrapper(attributedText: $post, postTextViewCanScroll: $postTextViewCanScroll, cursorIndex: newCursorIndex, getFocusWordForMention: { word, range in
|
||||||
focusWordAttributes = (word, range)
|
focusWordAttributes = (word, range)
|
||||||
self.newCursorIndex = nil
|
self.newCursorIndex = nil
|
||||||
})
|
})
|
||||||
@@ -335,7 +336,7 @@ struct PostView: View {
|
|||||||
|
|
||||||
// This if-block observes @ for tagging
|
// This if-block observes @ for tagging
|
||||||
if let searching {
|
if let searching {
|
||||||
UserSearch(damus_state: damus_state, search: searching, focusWordAttributes: $focusWordAttributes, newCursorIndex: $newCursorIndex, post: $post)
|
UserSearch(damus_state: damus_state, search: searching, focusWordAttributes: $focusWordAttributes, newCursorIndex: $newCursorIndex, postTextViewCanScroll: $postTextViewCanScroll, post: $post)
|
||||||
.frame(maxHeight: .infinity)
|
.frame(maxHeight: .infinity)
|
||||||
} else {
|
} else {
|
||||||
Divider()
|
Divider()
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ struct UserSearch: View {
|
|||||||
let search: String
|
let search: String
|
||||||
@Binding var focusWordAttributes: (String?, NSRange?)
|
@Binding var focusWordAttributes: (String?, NSRange?)
|
||||||
@Binding var newCursorIndex: Int?
|
@Binding var newCursorIndex: Int?
|
||||||
|
@Binding var postTextViewCanScroll: Bool
|
||||||
|
|
||||||
@Binding var post: NSMutableAttributedString
|
@Binding var post: NSMutableAttributedString
|
||||||
|
|
||||||
@@ -92,7 +93,14 @@ struct UserSearch: View {
|
|||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onAppear() {
|
||||||
|
postTextViewCanScroll = false
|
||||||
|
}
|
||||||
|
.onDisappear() {
|
||||||
|
postTextViewCanScroll = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UserSearch_Previews: PreviewProvider {
|
struct UserSearch_Previews: PreviewProvider {
|
||||||
@@ -100,9 +108,10 @@ struct UserSearch_Previews: PreviewProvider {
|
|||||||
@State static var post: NSMutableAttributedString = NSMutableAttributedString(string: "some @jb55")
|
@State static var post: NSMutableAttributedString = NSMutableAttributedString(string: "some @jb55")
|
||||||
@State static var word: (String?, NSRange?) = (nil, nil)
|
@State static var word: (String?, NSRange?) = (nil, nil)
|
||||||
@State static var newCursorIndex: Int?
|
@State static var newCursorIndex: Int?
|
||||||
|
@State static var postTextViewCanScroll: Bool = false
|
||||||
|
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
UserSearch(damus_state: test_damus_state(), search: search, focusWordAttributes: $word, newCursorIndex: $newCursorIndex, post: $post)
|
UserSearch(damus_state: test_damus_state(), search: search, focusWordAttributes: $word, newCursorIndex: $newCursorIndex, postTextViewCanScroll: $postTextViewCanScroll, post: $post)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,13 +9,14 @@ import SwiftUI
|
|||||||
|
|
||||||
struct TextViewWrapper: UIViewRepresentable {
|
struct TextViewWrapper: UIViewRepresentable {
|
||||||
@Binding var attributedText: NSMutableAttributedString
|
@Binding var attributedText: NSMutableAttributedString
|
||||||
|
@Binding var postTextViewCanScroll: Bool
|
||||||
let cursorIndex: Int?
|
let cursorIndex: Int?
|
||||||
var getFocusWordForMention: ((String?, NSRange?) -> Void)? = nil
|
var getFocusWordForMention: ((String?, NSRange?) -> Void)? = nil
|
||||||
|
|
||||||
func makeUIView(context: Context) -> UITextView {
|
func makeUIView(context: Context) -> UITextView {
|
||||||
let textView = UITextView()
|
let textView = UITextView()
|
||||||
textView.delegate = context.coordinator
|
textView.delegate = context.coordinator
|
||||||
textView.isScrollEnabled = false
|
textView.isScrollEnabled = postTextViewCanScroll
|
||||||
textView.showsVerticalScrollIndicator = false
|
textView.showsVerticalScrollIndicator = false
|
||||||
TextViewWrapper.setTextProperties(textView)
|
TextViewWrapper.setTextProperties(textView)
|
||||||
return textView
|
return textView
|
||||||
@@ -30,6 +31,7 @@ struct TextViewWrapper: UIViewRepresentable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func updateUIView(_ uiView: UITextView, context: Context) {
|
func updateUIView(_ uiView: UITextView, context: Context) {
|
||||||
|
uiView.isScrollEnabled = postTextViewCanScroll
|
||||||
uiView.attributedText = attributedText
|
uiView.attributedText = attributedText
|
||||||
TextViewWrapper.setTextProperties(uiView)
|
TextViewWrapper.setTextProperties(uiView)
|
||||||
setCursorPosition(textView: uiView)
|
setCursorPosition(textView: uiView)
|
||||||
|
|||||||
Reference in New Issue
Block a user