mirror of
https://github.com/element-hq/element-x-ios.git
synced 2025-03-10 21:39:12 +00:00
Flatten room list (#121)
* #121 Flatten the room list * #121 Add changelog * #121 UI tweaks for avatar and display name and preview * #121 Make avatar and label one button
This commit is contained in:
parent
baeffd2121
commit
83a25d5501
@ -36,20 +36,12 @@ struct HomeScreenViewState: BindableState {
|
||||
|
||||
var isLoadingRooms: Bool = false
|
||||
|
||||
var unencryptedDMs: [HomeScreenRoom] {
|
||||
searchFilteredRooms.filter { $0.isDirect && !$0.isEncrypted }
|
||||
var visibleDMs: [HomeScreenRoom] {
|
||||
searchFilteredRooms.filter { $0.isDirect }
|
||||
}
|
||||
|
||||
var encryptedDMs: [HomeScreenRoom] {
|
||||
searchFilteredRooms.filter { $0.isDirect && $0.isEncrypted}
|
||||
}
|
||||
|
||||
var unencryptedRooms: [HomeScreenRoom] {
|
||||
searchFilteredRooms.filter { !$0.isDirect && !$0.isEncrypted }
|
||||
}
|
||||
|
||||
var encryptedRooms: [HomeScreenRoom] {
|
||||
searchFilteredRooms.filter { !$0.isDirect && $0.isEncrypted }
|
||||
var visibleRooms: [HomeScreenRoom] {
|
||||
searchFilteredRooms.filter { !$0.isDirect }
|
||||
}
|
||||
|
||||
private var searchFilteredRooms: LazyFilterSequence<LazySequence<[HomeScreenRoom]>.Elements> {
|
||||
|
@ -26,42 +26,21 @@ struct HomeScreen: View {
|
||||
VStack(spacing: 16.0) {
|
||||
if context.viewState.isLoadingRooms {
|
||||
VStack {
|
||||
Text("Loading rooms")
|
||||
Text(ElementL10n.loading)
|
||||
ProgressView()
|
||||
}
|
||||
} else {
|
||||
List {
|
||||
Section("Rooms") {
|
||||
ForEach(context.viewState.unencryptedRooms) { room in
|
||||
Section(ElementL10n.rooms) {
|
||||
ForEach(context.viewState.visibleRooms) { room in
|
||||
RoomCell(room: room, context: context)
|
||||
.listRowBackground(Color.clear)
|
||||
}
|
||||
}
|
||||
|
||||
let other = context.viewState.encryptedRooms
|
||||
|
||||
if other.count > 0 {
|
||||
DisclosureGroup("Encrypted") {
|
||||
ForEach(other) { room in
|
||||
Section(ElementL10n.bottomActionPeople) {
|
||||
ForEach(context.viewState.visibleDMs) { room in
|
||||
RoomCell(room: room, context: context)
|
||||
}
|
||||
}
|
||||
.listRowBackground(Color.clear)
|
||||
}
|
||||
}
|
||||
|
||||
Section("People") {
|
||||
ForEach(context.viewState.unencryptedDMs) { room in
|
||||
RoomCell(room: room, context: context)
|
||||
}
|
||||
|
||||
let other = context.viewState.encryptedDMs
|
||||
|
||||
if other.count > 0 {
|
||||
DisclosureGroup("Encrypted") {
|
||||
ForEach(other) { room in
|
||||
RoomCell(room: room, context: context)
|
||||
}
|
||||
}
|
||||
.listRowBackground(Color.clear)
|
||||
}
|
||||
}
|
||||
@ -77,35 +56,13 @@ struct HomeScreen: View {
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
HStack {
|
||||
ZStack {
|
||||
if let avatar = context.viewState.userAvatar {
|
||||
Button { context.send(viewAction: .tapUserAvatar) } label: {
|
||||
Image(uiImage: avatar)
|
||||
.resizable()
|
||||
.scaledToFill()
|
||||
.frame(width: 40, height: 40, alignment: .center)
|
||||
.mask(Circle())
|
||||
}
|
||||
} else {
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
userAvatarImage
|
||||
.animation(.default, value: context.viewState.userAvatar)
|
||||
.transition(.opacity)
|
||||
|
||||
ZStack {
|
||||
if let displayName = context.viewState.userDisplayName {
|
||||
Button { context.send(viewAction: .tapUserAvatar) } label: {
|
||||
Text("Hello, \(displayName)!")
|
||||
.font(.subheadline)
|
||||
.fontWeight(.bold)
|
||||
.foregroundColor(.primary)
|
||||
}
|
||||
} else {
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
userDisplayNameView
|
||||
.animation(.default, value: context.viewState.userDisplayName)
|
||||
.transition(.opacity)
|
||||
}
|
||||
@ -114,6 +71,33 @@ struct HomeScreen: View {
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var userAvatarImage: some View {
|
||||
if let avatar = context.viewState.userAvatar {
|
||||
Image(uiImage: avatar)
|
||||
.resizable()
|
||||
.scaledToFill()
|
||||
.frame(width: 32, height: 32, alignment: .center)
|
||||
.clipShape(Circle())
|
||||
.accessibilityIdentifier("userAvatarImage")
|
||||
} else {
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var userDisplayNameView: some View {
|
||||
if let displayName = context.viewState.userDisplayName {
|
||||
Text(displayName)
|
||||
.font(.headline)
|
||||
.fontWeight(.bold)
|
||||
.foregroundColor(.primary)
|
||||
} else {
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct RoomCell: View {
|
||||
|
||||
let room: HomeScreenRoom
|
||||
@ -129,7 +113,7 @@ struct RoomCell: View {
|
||||
.resizable()
|
||||
.scaledToFill()
|
||||
.frame(width: 40, height: 40)
|
||||
.mask(Circle())
|
||||
.clipShape(Circle())
|
||||
} else {
|
||||
PlaceholderAvatarImage(text: room.displayName ?? room.id)
|
||||
.clipShape(Circle())
|
||||
@ -192,11 +176,14 @@ struct HomeScreen_Previews: PreviewProvider {
|
||||
MockRoomSummary(displayName: "Omega", lastMessage: eventBrief)]
|
||||
|
||||
viewModel.updateWithRoomSummaries(roomSummaries)
|
||||
viewModel.updateWithUserDisplayName("username")
|
||||
|
||||
if let avatarImage = UIImage(systemName: "person.fill.questionmark") {
|
||||
if let avatarImage = UIImage(systemName: "person.fill") {
|
||||
viewModel.updateWithUserAvatar(avatarImage)
|
||||
}
|
||||
|
||||
return HomeScreen(context: viewModel.context)
|
||||
return NavigationView {
|
||||
HomeScreen(context: viewModel.context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
changelog.d/pr-121.change
Normal file
1
changelog.d/pr-121.change
Normal file
@ -0,0 +1 @@
|
||||
Flatten the room list by removing the encrypted groups.
|
Loading…
x
Reference in New Issue
Block a user