Skip to content

Commit

Permalink
allo temporary disable autoscroll on tap gesture
Browse files Browse the repository at this point in the history
  • Loading branch information
guinmoon committed Mar 20, 2024
1 parent 00c9831 commit 98cce53
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 12 additions & 3 deletions LLMFarm/Chats/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct ChatView: View {
@State private var toggleEditChat = false
@State private var clearChatAlert = false
@State private var is_mmodal = false

@State private var auto_scroll = true

@FocusState var focusedField: Field?

Expand All @@ -57,6 +59,9 @@ struct ChatView: View {
if scroll_bug {
return
}
if !auto_scroll {
return
}
let last_msg = aiChatModel.messages.last // try to fixscrolling and specialized Array._checkSubscript(_:wasNativeTypeChecked:)
if last_msg != nil && last_msg?.id != nil && scrollProxy != nil{
if with_animation{
Expand Down Expand Up @@ -97,8 +102,8 @@ struct ChatView: View {

Button {
Task{
scrollToBottom()

auto_scroll = true
scrollToBottom()
}
}

Expand Down Expand Up @@ -167,6 +172,7 @@ struct ChatView: View {
.onTapGesture { location in
print("Tapped at \(location)")
focusedField = nil
auto_scroll = false
}
.toolbar {
Button {
Expand Down Expand Up @@ -214,7 +220,10 @@ struct ChatView: View {
}
.navigationTitle(aiChatModel.Title)

LLMTextInput(messagePlaceholder: placeholderString,show_attachment_btn:self.is_mmodal,focusedField:$focusedField).environmentObject(aiChatModel)
LLMTextInput(messagePlaceholder: placeholderString,
show_attachment_btn:self.is_mmodal,
focusedField:$focusedField,
auto_scroll:$auto_scroll).environmentObject(aiChatModel)
.disabled(self.aiChatModel.chat_name == "")
// .focused($focusedField, equals: .firstName)

Expand Down
8 changes: 6 additions & 2 deletions LLMFarm/Chats/LLMTextInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public struct LLMTextInput: View {
@State private var selectedPhoto: PhotosPickerItem?
@State private var image: Image?
@State public var img_cahce_path: String?
@Binding private var auto_scroll:Bool

// @FocusState private var focusedField: Field?

Expand Down Expand Up @@ -216,12 +217,14 @@ public struct LLMTextInput: View {
// _ chat: Binding<Chat>,
messagePlaceholder: String? = nil,
show_attachment_btn: Bool,
focusedField: FocusState<Field?>.Binding
focusedField: FocusState<Field?>.Binding,
auto_scroll: Binding<Bool>
) {
// self._chat = chat
self.messagePlaceholder = messagePlaceholder ?? "Message"
self.show_attachment_btn = show_attachment_btn
self.focusedField = focusedField
self._auto_scroll = auto_scroll
}


Expand All @@ -235,7 +238,8 @@ public struct LLMTextInput: View {
img_cahce_path = nil
image = nil
selectedPhoto = nil
Task {
auto_scroll = true
Task {
await aiChatModel.send(message: input_text,img_path: img_path)
input_text = ""
}
Expand Down

0 comments on commit 98cce53

Please sign in to comment.