mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Refactored alert info to not use the soon to be deprecated API (#1084)
* refactored alert info to not use the soon to be deprecated API * missing files and changelog * updated some tests * Update ElementX/Sources/Screens/RoomMemberDetailsScreen/View/RoomMemberDetailsScreen.swift Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com> --------- Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
This commit is contained in:
@@ -46,7 +46,7 @@ struct LoginScreen: View {
|
||||
.padding(.bottom, 16)
|
||||
}
|
||||
.background(Color.element.background.ignoresSafeArea())
|
||||
.alert(item: $context.alertInfo) { $0.alert }
|
||||
.alert(item: $context.alertInfo)
|
||||
}
|
||||
|
||||
/// The header containing the title and icon.
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ struct ServerSelectionScreen: View {
|
||||
}
|
||||
.background(Color.element.background.ignoresSafeArea())
|
||||
.toolbar { toolbar }
|
||||
.alert(item: $context.alertInfo) { $0.alert }
|
||||
.alert(item: $context.alertInfo)
|
||||
.interactiveDismissDisabled()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ struct SoftLogoutScreen: View {
|
||||
.padding(.bottom, 16)
|
||||
}
|
||||
.background(Color.element.background.ignoresSafeArea())
|
||||
.alert(item: $context.alertInfo) { $0.alert }
|
||||
.alert(item: $context.alertInfo)
|
||||
.introspectViewController { viewController in
|
||||
guard let window = viewController.view.window else { return }
|
||||
context.send(viewAction: .updateWindow(window))
|
||||
|
||||
@@ -41,7 +41,7 @@ struct CreateRoomScreen: View {
|
||||
}
|
||||
}
|
||||
.background(ViewFrameReader(frame: $frame))
|
||||
.alert(item: $context.alertInfo) { $0.alert }
|
||||
.alert(item: $context.alertInfo)
|
||||
}
|
||||
|
||||
@ScaledMetric private var roomIconSize: CGFloat = 70
|
||||
|
||||
@@ -116,7 +116,7 @@ struct HomeScreen: View {
|
||||
.animation(.elementDefault, value: context.viewState.showSessionVerificationBanner)
|
||||
.animation(.elementDefault, value: context.viewState.roomListMode)
|
||||
.animation(.none, value: context.viewState.visibleRooms)
|
||||
.alert(item: $context.alertInfo) { $0.alert }
|
||||
.alert(item: $context.alertInfo)
|
||||
.alert(item: $context.leaveRoomAlertItem,
|
||||
actions: leaveRoomAlertActions,
|
||||
message: leaveRoomAlertMessage)
|
||||
|
||||
@@ -38,7 +38,7 @@ struct InviteUsersScreen: View {
|
||||
searchViewController.hidesNavigationBarDuringPresentation = false
|
||||
}
|
||||
.compoundSearchField()
|
||||
.alert(item: $context.alertInfo) { $0.alert }
|
||||
.alert(item: $context.alertInfo)
|
||||
.background(ViewFrameReader(frame: $frame))
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ struct InvitesScreen: View {
|
||||
}
|
||||
.background(Color.element.background.ignoresSafeArea())
|
||||
.navigationTitle(L10n.actionInvitesList)
|
||||
.alert(item: $context.alertInfo) { $0.alert }
|
||||
.alert(item: $context.alertInfo)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
enum LocationSharingViewError: Error {
|
||||
enum LocationSharingViewError: Error, Hashable {
|
||||
case failedSharingLocation
|
||||
case mapError(MapLibreError)
|
||||
}
|
||||
@@ -31,15 +31,18 @@ struct StaticLocationScreenBindings {
|
||||
/// Information describing the currently displayed alert.
|
||||
var mapError: MapLibreError? {
|
||||
get {
|
||||
errorAlert?.error as? MapLibreError
|
||||
if case let .mapError(error) = alertInfo?.id {
|
||||
return error
|
||||
}
|
||||
return nil
|
||||
}
|
||||
set {
|
||||
errorAlert = newValue.map { ErrorAlertItem(error: $0) }
|
||||
alertInfo = newValue.map { AlertInfo(id: .mapError($0)) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Information describing the currently displayed alert.
|
||||
var errorAlert: ErrorAlertItem?
|
||||
var alertInfo: AlertInfo<LocationSharingViewError>?
|
||||
}
|
||||
|
||||
enum StaticLocationScreenViewAction { }
|
||||
|
||||
@@ -26,7 +26,7 @@ struct StaticLocationScreen: View {
|
||||
mapView
|
||||
.ignoresSafeArea(.all, edges: [.bottom])
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.errorAlert(item: $context.errorAlert)
|
||||
.alert(item: $context.alertInfo)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ struct RoomDetailsScreenViewState: BindableState {
|
||||
}
|
||||
|
||||
struct RoomDetailsScreenViewStateBindings {
|
||||
struct IgnoreUserAlertItem: AlertItem, Equatable {
|
||||
struct IgnoreUserAlertItem: AlertProtocol, Equatable {
|
||||
enum Action {
|
||||
case ignore
|
||||
case unignore
|
||||
@@ -105,7 +105,7 @@ struct RoomDetailsScreenViewStateBindings {
|
||||
var ignoreUserRoomAlertItem: IgnoreUserAlertItem?
|
||||
}
|
||||
|
||||
struct LeaveRoomAlertItem: AlertItem {
|
||||
struct LeaveRoomAlertItem: AlertProtocol {
|
||||
enum RoomState {
|
||||
case empty
|
||||
case `public`
|
||||
|
||||
@@ -42,7 +42,7 @@ struct RoomDetailsScreen: View {
|
||||
}
|
||||
}
|
||||
.elementFormStyle()
|
||||
.alert(item: $context.alertInfo) { $0.alert }
|
||||
.alert(item: $context.alertInfo)
|
||||
.alert(item: $context.leaveRoomAlertItem,
|
||||
actions: leaveRoomAlertActions,
|
||||
message: leaveRoomAlertMessage)
|
||||
|
||||
+7
-2
@@ -26,7 +26,7 @@ struct RoomMemberDetailsScreenViewState: BindableState {
|
||||
}
|
||||
|
||||
struct RoomMemberDetailsScreenViewStateBindings {
|
||||
struct IgnoreUserAlertItem: AlertItem, Equatable {
|
||||
struct IgnoreUserAlertItem: AlertProtocol, Equatable {
|
||||
enum Action {
|
||||
case ignore
|
||||
case unignore
|
||||
@@ -65,7 +65,7 @@ struct RoomMemberDetailsScreenViewStateBindings {
|
||||
}
|
||||
|
||||
var ignoreUserAlert: IgnoreUserAlertItem?
|
||||
var errorAlert: ErrorAlertItem?
|
||||
var alertInfo: AlertInfo<RoomMemberDetailsScreenError>?
|
||||
}
|
||||
|
||||
enum RoomMemberDetailsScreenViewAction {
|
||||
@@ -74,3 +74,8 @@ enum RoomMemberDetailsScreenViewAction {
|
||||
case ignoreConfirmed
|
||||
case unignoreConfirmed
|
||||
}
|
||||
|
||||
enum RoomMemberDetailsScreenError: Hashable {
|
||||
case alert(String)
|
||||
case unknown
|
||||
}
|
||||
|
||||
+4
-4
@@ -55,8 +55,8 @@ class RoomMemberDetailsScreenViewModel: RoomMemberDetailsScreenViewModelType, Ro
|
||||
switch result {
|
||||
case .success:
|
||||
state.details.isIgnored = true
|
||||
case .failure(let error):
|
||||
state.bindings.errorAlert = .init(error: error)
|
||||
case .failure:
|
||||
state.bindings.alertInfo = .init(id: .unknown)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ class RoomMemberDetailsScreenViewModel: RoomMemberDetailsScreenViewModelType, Ro
|
||||
switch result {
|
||||
case .success:
|
||||
state.details.isIgnored = false
|
||||
case .failure(let error):
|
||||
state.bindings.errorAlert = .init(error: error)
|
||||
case .failure:
|
||||
state.bindings.alertInfo = .init(id: .unknown)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ struct RoomMemberDetailsScreen: View {
|
||||
}
|
||||
.elementFormStyle()
|
||||
.alert(item: $context.ignoreUserAlert, actions: blockUserAlertActions, message: blockUserAlertMessage)
|
||||
.errorAlert(item: $context.errorAlert)
|
||||
.alert(item: $context.alertInfo)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
@@ -33,7 +33,7 @@ struct RoomMembersListScreen: View {
|
||||
.compoundSearchField()
|
||||
.background(Color.element.background.ignoresSafeArea())
|
||||
.navigationTitle(L10n.commonPeople)
|
||||
.alert(item: $context.alertInfo) { $0.alert }
|
||||
.alert(item: $context.alertInfo)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
inviteButton
|
||||
|
||||
@@ -37,7 +37,7 @@ struct RoomScreen: View {
|
||||
.toolbar { toolbar }
|
||||
.toolbarBackground(.visible, for: .navigationBar) // Fix the toolbar's background.
|
||||
.overlay { loadingIndicator }
|
||||
.alert(item: $context.alertInfo) { $0.alert }
|
||||
.alert(item: $context.alertInfo)
|
||||
.sheet(item: $context.debugInfo) { TimelineItemDebugView(info: $0) }
|
||||
.sheet(item: $context.actionMenuInfo) { info in
|
||||
context.viewState.timelineItemMenuActionProvider?(info.item.id).map { actions in
|
||||
|
||||
@@ -41,7 +41,7 @@ struct StartChatScreen: View {
|
||||
.dismissSearchOnDisappear()
|
||||
.searchable(text: $context.searchQuery, placement: .navigationBarDrawer(displayMode: .always), prompt: L10n.commonSearchForSomeone)
|
||||
.compoundSearchField()
|
||||
.alert(item: $context.alertInfo) { $0.alert }
|
||||
.alert(item: $context.alertInfo)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
Reference in New Issue
Block a user