Address comments, show unencrypted rooms,

retain viewModel and services in ScreenSates so you can interact with Previews after the first state.
This commit is contained in:
David Langley
2021-09-23 23:57:54 +01:00
parent bd4d9974a8
commit d560e513d4
16 changed files with 185 additions and 114 deletions
@@ -15,6 +15,7 @@
//
import SwiftUI
import Combine
@available(iOS 14.0, *)
struct TemplateRoomChat: View {
@@ -88,15 +89,15 @@ struct TemplateRoomChat: View {
.id(bubble.id)
}
}
.onAppear {
// Start at the bottom
reader.scrollTo(viewModel.viewState.bubbles.last?.id, anchor: .bottom)
.onAppear{
guard let lastBubbleId = viewModel.viewState.bubbles.last?.id
else { return }
reader.scrollTo(lastBubbleId, anchor: .bottom)
}
.onChange(of: itemCount) { _ in
// When new items are added animate to the new items
withAnimation {
reader.scrollTo(viewModel.viewState.bubbles.last?.id, anchor: .bottom)
}
guard let lastBubbleId = viewModel.viewState.bubbles.last?.id
else { return }
reader.scrollTo(lastBubbleId, anchor: .bottom)
}
// When the scroll content takes less than the screen space align at the top
.frame(maxHeight: .infinity, alignment: .top)
@@ -113,7 +114,6 @@ struct TemplateRoomChat: View {
}
}
private var itemCount: Int {
return viewModel.viewState
.bubbles
@@ -127,7 +127,8 @@ struct TemplateRoomChat: View {
@available(iOS 14.0, *)
struct TemplateRoomChat_Previews: PreviewProvider {
static let stateRenderer = MockTemplateRoomChatScreenState.stateRenderer
static var previews: some View {
MockTemplateRoomChatScreenState.screenGroup(addNavigation: true)
stateRenderer.screenGroup(addNavigation: true)
}
}