💄 Auto hide input on watchOS
This commit is contained in:
		| @@ -263,6 +263,8 @@ struct ChatRoomView: View { | |||||||
|     @State private var hasLoadedMessages = false // Track if messages have been loaded |     @State private var hasLoadedMessages = false // Track if messages have been loaded | ||||||
|     @State private var messageText = "" // Text input for sending messages |     @State private var messageText = "" // Text input for sending messages | ||||||
|     @State private var isSending = false // Track sending state |     @State private var isSending = false // Track sending state | ||||||
|  |     @State private var isInputHidden = false // Track if input should be hidden during scrolling | ||||||
|  |     @State private var scrollTimer: Timer? // Timer to show input after scrolling stops | ||||||
|  |  | ||||||
|     @State private var cancellables = Set<AnyCancellable>() // For managing subscriptions |     @State private var cancellables = Set<AnyCancellable>() // For managing subscriptions | ||||||
|  |  | ||||||
| @@ -311,6 +313,7 @@ struct ChatRoomView: View { | |||||||
|                         } |                         } | ||||||
|                         .padding(.horizontal) |                         .padding(.horizontal) | ||||||
|                         .padding(.vertical, 8) |                         .padding(.vertical, 8) | ||||||
|  |                         .padding(.bottom, 8) | ||||||
|                     } |                     } | ||||||
|                     .onAppear { |                     .onAppear { | ||||||
|                         // Scroll to bottom when messages load |                         // Scroll to bottom when messages load | ||||||
| @@ -326,10 +329,26 @@ struct ChatRoomView: View { | |||||||
|                             } |                             } | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|  |                     .onScrollPhaseChange { _, phase  in | ||||||
|  |                         switch phase { | ||||||
|  |                         case .interacting: | ||||||
|  |                             if !isInputHidden { | ||||||
|  |                                 withAnimation(.easeOut(duration: 0.2)) { | ||||||
|  |                                     isInputHidden = true | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|  |                         case .idle: | ||||||
|  |                             withAnimation(.easeIn(duration: 0.3)) { | ||||||
|  |                                 isInputHidden = false | ||||||
|  |                             } | ||||||
|  |                         default: break | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             // Message input area |             // Message input area | ||||||
|  |             if !isInputHidden { | ||||||
|                 HStack(spacing: 8) { |                 HStack(spacing: 8) { | ||||||
|                     TextField("Send message...", text: $messageText) |                     TextField("Send message...", text: $messageText) | ||||||
|                         .font(.system(size: 14)) |                         .font(.system(size: 14)) | ||||||
| @@ -357,6 +376,8 @@ struct ChatRoomView: View { | |||||||
|                 } |                 } | ||||||
|                 .padding(.horizontal) |                 .padding(.horizontal) | ||||||
|                 .padding(.top, 8) |                 .padding(.top, 8) | ||||||
|  |                 .transition(.move(edge: .bottom).combined(with: .opacity)) | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|         .navigationTitle(room.name ?? "Chat") |         .navigationTitle(room.name ?? "Chat") | ||||||
|         .task { |         .task { | ||||||
| @@ -368,6 +389,8 @@ struct ChatRoomView: View { | |||||||
|         .onDisappear { |         .onDisappear { | ||||||
|             cancellables.forEach { $0.cancel() } |             cancellables.forEach { $0.cancel() } | ||||||
|             cancellables.removeAll() |             cancellables.removeAll() | ||||||
|  |             scrollTimer?.invalidate() | ||||||
|  |             scrollTimer = nil | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user