mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2025-03-14 09:45:42 +00:00

* ios: new user picker (#4770) * current user picker progress * one hand picker * thin bullet icon * more user picker buttons * button clickable areas * divider padding * extra space after sun * send current user option to address view * add unread count badge * with anim for apperance close * edit current profile from picker * remove you section from settings * remove help and support * simplify * move settings and sun to same row * remove redundant vstack * long press on sun/moon switches to system setting * remove back button from migrate device * smooth profile transitions * close user picker on list profiles * fix dismiss on migrate from device * fix dismiss when deleting last visible user while having hidden users * picker visibility toggle tweaks * remove strange square from profile switcher click * dirty way to save auto accept settings on dismiss * Revert "dirty way to save auto accept settings on dismiss" This reverts commite7b19ee8aa
. * consistent animation on user picker toggle * change space between profiles * remove result * ignore result * unread badge * move to sheet * half sheet on one hand ui * fix dismiss on device migration * fix desktop connect * sun to meet other action icons * fill bullet list button * fix tap in settings to take full width * icon sizings and paddings * open settings in same sheet * apply same trick as other buttons for ligth toggle * layout * open profiles sheet large when +3 users * layout * layout * paddings * paddings * remove show progress * always small user picker * fixed height * open all actions as sheets * type, color * simpler and more effective way of avoid moving around on user select * dismiss user profiles sheet on user change * connect desktop back button remove * remove back buttons from user address view * remove porgress * header inside list * alert on auto accept unsaved changes * Cancel -> Discard * revert * fix connect to desktop * remove extra space * fix share inside multi sheet * user picker and options as separate sheet * revert showShareSheet * fix current profile and all profiles selection * change alert * update * cleanup user address * remove func * alert on unsaved changes in chat prefs * fix layout * cleanup --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> * ios: fix switching profiles (#4822) * ios: different user picker layout (#4826) * ios: different user picker layout * remove section * layout, color * color * remove activeUser * fix gradient * recursive sheets * gradient padding * share sheet * layout * dismiss sheets --------- Co-authored-by: Levitating Pineapple <noreply@levitatingpineapple.com> * ios: use the same way to share from all sheets (#4829) * ios: close user picker before opening other sheets * Revert "share sheet" This reverts commit0064155825
. * dismiss/show via callback * Revert "ios: close user picker before opening other sheets" This reverts commit19110398f8
. * ios: show alerts from sheets (#4839) * padding * remove gradient * cleanup * simplify settings * padding --------- Co-authored-by: Diogo <diogofncunha@gmail.com> Co-authored-by: Levitating Pineapple <noreply@levitatingpineapple.com> Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com>
236 lines
8.8 KiB
Swift
236 lines
8.8 KiB
Swift
//
|
|
// Created by Avently on 16.01.2023.
|
|
// Copyright (c) 2023 SimpleX Chat. All rights reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SimpleXChat
|
|
|
|
struct UserPicker: View {
|
|
@EnvironmentObject var m: ChatModel
|
|
@EnvironmentObject var theme: AppTheme
|
|
@Environment(\.dynamicTypeSize) private var userFont: DynamicTypeSize
|
|
@Environment(\.scenePhase) private var scenePhase: ScenePhase
|
|
@Environment(\.colorScheme) private var colorScheme: ColorScheme
|
|
@Environment(\.dismiss) private var dismiss: DismissAction
|
|
@Binding var activeSheet: UserPickerSheet?
|
|
@State private var switchingProfile = false
|
|
|
|
var body: some View {
|
|
if #available(iOS 16.0, *) {
|
|
let v = viewBody.presentationDetents([.height(420)])
|
|
if #available(iOS 16.4, *) {
|
|
v.scrollBounceBehavior(.basedOnSize)
|
|
} else {
|
|
v
|
|
}
|
|
} else {
|
|
viewBody
|
|
}
|
|
}
|
|
|
|
private var viewBody: some View {
|
|
let otherUsers = m.users.filter { u in !u.user.hidden && u.user.userId != m.currentUser?.userId }
|
|
return List {
|
|
Section(header: Text("You").foregroundColor(theme.colors.secondary)) {
|
|
if let user = m.currentUser {
|
|
openSheetOnTap(label: {
|
|
ZStack {
|
|
let v = ProfilePreview(profileOf: user)
|
|
.foregroundColor(.primary)
|
|
.padding(.leading, -8)
|
|
if #available(iOS 16.0, *) {
|
|
v
|
|
} else {
|
|
v.padding(.vertical, 4)
|
|
}
|
|
}
|
|
}) {
|
|
activeSheet = .currentProfile
|
|
}
|
|
|
|
openSheetOnTap(title: m.userAddress == nil ? "Create public address" : "Your public address", icon: "qrcode") {
|
|
activeSheet = .address
|
|
}
|
|
|
|
openSheetOnTap(title: "Chat preferences", icon: "switch.2") {
|
|
activeSheet = .chatPreferences
|
|
}
|
|
}
|
|
}
|
|
|
|
Section {
|
|
if otherUsers.isEmpty {
|
|
openSheetOnTap(title: "Your chat profiles", icon: "person.crop.rectangle.stack") {
|
|
activeSheet = .chatProfiles
|
|
}
|
|
} else {
|
|
let v = userPickerRow(otherUsers, size: 44)
|
|
.padding(.leading, -11)
|
|
if #available(iOS 16.0, *) {
|
|
v
|
|
} else {
|
|
v.padding(.vertical, 4)
|
|
}
|
|
}
|
|
|
|
openSheetOnTap(title: "Use from desktop", icon: "desktopcomputer") {
|
|
activeSheet = .useFromDesktop
|
|
}
|
|
|
|
ZStack(alignment: .trailing) {
|
|
openSheetOnTap(title: "Settings", icon: "gearshape") {
|
|
activeSheet = .settings
|
|
}
|
|
Label {} icon: {
|
|
Image(systemName: colorScheme == .light ? "sun.max" : "moon.fill")
|
|
.resizable()
|
|
.symbolRenderingMode(.monochrome)
|
|
.foregroundColor(theme.colors.secondary)
|
|
.frame(maxWidth: 20, maxHeight: 20)
|
|
}
|
|
.onTapGesture {
|
|
if (colorScheme == .light) {
|
|
ThemeManager.applyTheme(systemDarkThemeDefault.get())
|
|
} else {
|
|
ThemeManager.applyTheme(DefaultTheme.LIGHT.themeName)
|
|
}
|
|
}
|
|
.onLongPressGesture {
|
|
ThemeManager.applyTheme(DefaultTheme.SYSTEM_THEME_NAME)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
|
.onAppear {
|
|
// This check prevents the call of listUsers after the app is suspended, and the database is closed.
|
|
if case .active = scenePhase {
|
|
Task {
|
|
do {
|
|
let users = try await listUsersAsync()
|
|
await MainActor.run { m.users = users }
|
|
} catch {
|
|
logger.error("Error loading users \(responseError(error))")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.modifier(ThemedBackground(grouped: true))
|
|
.disabled(switchingProfile)
|
|
}
|
|
|
|
private func userPickerRow(_ users: [UserInfo], size: CGFloat) -> some View {
|
|
HStack(spacing: 6) {
|
|
let s = ScrollView(.horizontal) {
|
|
HStack(spacing: 27) {
|
|
ForEach(users) { u in
|
|
if !u.user.hidden && u.user.userId != m.currentUser?.userId {
|
|
userView(u, size: size)
|
|
}
|
|
}
|
|
}
|
|
.padding(.leading, 4)
|
|
.padding(.trailing, 22)
|
|
}
|
|
ZStack(alignment: .trailing) {
|
|
if #available(iOS 16.0, *) {
|
|
s.scrollIndicators(.hidden)
|
|
} else {
|
|
s
|
|
}
|
|
LinearGradient(
|
|
colors: [.clear, .black],
|
|
startPoint: .leading,
|
|
endPoint: .trailing
|
|
)
|
|
.frame(width: size, height: size + 3)
|
|
.blendMode(.destinationOut)
|
|
.allowsHitTesting(false)
|
|
}
|
|
.compositingGroup()
|
|
.padding(.top, -3) // to fit unread badge
|
|
Spacer()
|
|
Image(systemName: "chevron.right")
|
|
.foregroundColor(theme.colors.secondary)
|
|
.padding(.trailing, 4)
|
|
.onTapGesture {
|
|
activeSheet = .chatProfiles
|
|
}
|
|
}
|
|
}
|
|
|
|
private func userView(_ u: UserInfo, size: CGFloat) -> some View {
|
|
ZStack(alignment: .topTrailing) {
|
|
ProfileImage(imageStr: u.user.image, size: size, color: Color(uiColor: .tertiarySystemGroupedBackground))
|
|
.padding([.top, .trailing], 3)
|
|
if (u.unreadCount > 0) {
|
|
unreadBadge(u)
|
|
}
|
|
}
|
|
.frame(width: size)
|
|
.onTapGesture {
|
|
switchingProfile = true
|
|
Task {
|
|
do {
|
|
try await changeActiveUserAsync_(u.user.userId, viewPwd: nil)
|
|
await MainActor.run {
|
|
switchingProfile = false
|
|
dismiss()
|
|
}
|
|
} catch {
|
|
await MainActor.run {
|
|
switchingProfile = false
|
|
AlertManager.shared.showAlertMsg(
|
|
title: "Error switching profile!",
|
|
message: "Error: \(responseError(error))"
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private func openSheetOnTap(title: LocalizedStringKey, icon: String, action: @escaping () -> Void) -> some View {
|
|
openSheetOnTap(label: {
|
|
ZStack(alignment: .leading) {
|
|
Image(systemName: icon).frame(maxWidth: 24, maxHeight: 24, alignment: .center)
|
|
.symbolRenderingMode(.monochrome)
|
|
.foregroundColor(theme.colors.secondary)
|
|
Text(title)
|
|
.foregroundColor(.primary)
|
|
.padding(.leading, 36)
|
|
}
|
|
}, action: action)
|
|
}
|
|
|
|
private func openSheetOnTap<V: View>(label: () -> V, action: @escaping () -> Void) -> some View {
|
|
Button(action: action, label: label)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.contentShape(Rectangle())
|
|
}
|
|
|
|
private func unreadBadge(_ u: UserInfo) -> some View {
|
|
let size = dynamicSize(userFont).chatInfoSize
|
|
return unreadCountText(u.unreadCount)
|
|
.font(userFont <= .xxxLarge ? .caption : .caption2)
|
|
.foregroundColor(.white)
|
|
.padding(.horizontal, dynamicSize(userFont).unreadPadding)
|
|
.frame(minWidth: size, minHeight: size)
|
|
.background(u.user.showNtfs ? theme.colors.primary : theme.colors.secondary)
|
|
.cornerRadius(dynamicSize(userFont).unreadCorner)
|
|
}
|
|
}
|
|
|
|
struct UserPicker_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
@State var activeSheet: UserPickerSheet?
|
|
|
|
let m = ChatModel()
|
|
m.users = [UserInfo.sampleData, UserInfo.sampleData]
|
|
return UserPicker(
|
|
activeSheet: $activeSheet
|
|
)
|
|
.environmentObject(m)
|
|
}
|
|
}
|