fix scroll down
This commit is contained in:
		
							parent
							
								
									5f03feba66
								
							
						
					
					
						commit
						91a3117595
					
				@ -22,33 +22,22 @@ struct PrivateChatView: View {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    var body: some View {
 | 
			
		||||
        ZStack(alignment: .bottomTrailing) {
 | 
			
		||||
        ScrollViewReader { proxy in
 | 
			
		||||
            ZStack(alignment: .bottomTrailing) {
 | 
			
		||||
                content
 | 
			
		||||
                    .onChange(of: viewModel.messages.count) { _ in
 | 
			
		||||
                        guard !viewModel.isLoadingMore else { return }
 | 
			
		||||
                        let targetId = viewModel.messages.last?.id ?? bottomAnchorId
 | 
			
		||||
                        DispatchQueue.main.async {
 | 
			
		||||
                            withAnimation(.easeInOut(duration: 0.2)) {
 | 
			
		||||
                                proxy.scrollTo(targetId, anchor: .bottom)
 | 
			
		||||
                            }
 | 
			
		||||
                            hasPositionedToBottom = true
 | 
			
		||||
                        }
 | 
			
		||||
                        scrollToBottom(proxy: proxy)
 | 
			
		||||
                    }
 | 
			
		||||
                    .onChange(of: scrollToBottomTrigger) { _ in
 | 
			
		||||
                        let targetId = viewModel.messages.last?.id ?? bottomAnchorId
 | 
			
		||||
                        DispatchQueue.main.async {
 | 
			
		||||
                            withAnimation(.easeInOut(duration: 0.2)) {
 | 
			
		||||
                                proxy.scrollTo(targetId, anchor: .bottom)
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                        scrollToBottom(proxy: proxy)
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                if !isBottomAnchorVisible {
 | 
			
		||||
                scrollToBottomButton
 | 
			
		||||
                    scrollToBottomButton(proxy: proxy)
 | 
			
		||||
                        .padding(.trailing, 20)
 | 
			
		||||
                    .padding(.bottom, 30)
 | 
			
		||||
                        .padding(.bottom, 56)
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        .navigationTitle(title)
 | 
			
		||||
@ -294,8 +283,10 @@ struct PrivateChatView: View {
 | 
			
		||||
        .background(.ultraThinMaterial)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private var scrollToBottomButton: some View {
 | 
			
		||||
        Button(action: scrollToBottom) {
 | 
			
		||||
    private func scrollToBottomButton(proxy: ScrollViewProxy) -> some View {
 | 
			
		||||
        Button {
 | 
			
		||||
            scrollToBottom(proxy: proxy)
 | 
			
		||||
        } label: {
 | 
			
		||||
            Image(systemName: "arrow.down")
 | 
			
		||||
                .font(.system(size: 18, weight: .semibold))
 | 
			
		||||
                .foregroundColor(.white)
 | 
			
		||||
@ -369,10 +360,16 @@ struct PrivateChatView: View {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private func scrollToBottom() {
 | 
			
		||||
        scrollToBottomTrigger = .init()
 | 
			
		||||
    private func scrollToBottom(proxy: ScrollViewProxy) {
 | 
			
		||||
        hasPositionedToBottom = true
 | 
			
		||||
        isBottomAnchorVisible = true
 | 
			
		||||
 | 
			
		||||
        let targetId = viewModel.messages.last?.id ?? bottomAnchorId
 | 
			
		||||
 | 
			
		||||
        DispatchQueue.main.async {
 | 
			
		||||
            withAnimation(.easeInOut(duration: 0.2)) {
 | 
			
		||||
                proxy.scrollTo(targetId, anchor: .bottom)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private struct ComposerIconButtonStyle: ButtonStyle {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user