Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: MVP dismiss Snackbars on user navigation #1376

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions .package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire",
"state" : {
"revision" : "723fa5a6c65812aec4a0d7cc432ee198883b6e00",
"version" : "5.9.0"
"revision" : "f455c2975872ccd2d9c81594c658af65716e9b9a",
"version" : "5.9.1"
}
},
{
Expand Down Expand Up @@ -50,8 +50,7 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/ios-core-ui",
"state" : {
"revision" : "6d069462017491b74cd1eec6a87e6333a41c15ac",
"version" : "7.0.0"
"revision" : "78fc0f85a4b32051ab3de6bb492a3690c1fc363b"
}
},
{
Expand Down Expand Up @@ -131,17 +130,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matomo-org/matomo-sdk-ios",
"state" : {
"revision" : "15a645e11eaa8053f93749d73ced03da1e56fd01",
"version" : "7.5.2"
"revision" : "a8800d8725fb84bad6b7dea555075f961952bc0a",
"version" : "7.6.0"
}
},
{
"identity" : "navigationbackport",
"kind" : "remoteSourceControl",
"location" : "https://github.com/johnpatrickmorgan/NavigationBackport",
"state" : {
"revision" : "b002991691b54fd7b952e1e780de252620f8ac77",
"version" : "0.9.1"
"revision" : "add71ebc3cf71e43c662c69c4d7c1f2dc5dc3588",
"version" : "0.9.2"
}
},
{
Expand Down Expand Up @@ -239,8 +238,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Infomaniak/swift-concurrency",
"state" : {
"revision" : "1c2e7ee0bb93203c865904494b0aa2aedbc57713",
"version" : "0.0.4"
"revision" : "02960fd5d2cf57c7ba38d13bbbf580d7f6ac7102",
"version" : "0.0.5"
}
},
{
Expand Down
8 changes: 7 additions & 1 deletion Mail/Components/Buttons/Custom Buttons/AccountButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

import InfomaniakCore
import InfomaniakDI
import MailCore
import MailResources
import SwiftModalPresentation
Expand All @@ -25,7 +26,12 @@ import SwiftUI
struct AccountButton: View {
@EnvironmentObject private var mailboxManager: MailboxManager

@ModalState private var presentedCurrentAccount: Account?
@ModalState private var presentedCurrentAccount: Account? {
didSet {
@InjectService var snackbarPresenter: SnackBarPresentable
snackbarPresenter.dismissAll()
}
}

var body: some View {
Button {
Expand Down
6 changes: 6 additions & 0 deletions Mail/RootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import InfomaniakDI
import MailCore
import SwiftUI

struct RootView: View {
@LazyInjectService private var snackbarPresenter: SnackBarPresentable

@EnvironmentObject private var rootViewState: RootViewState

var body: some View {
Expand All @@ -44,5 +47,8 @@ struct RootView: View {
PreloadingView(currentAccount: currentAccount)
}
}
.onChange(of: rootViewState.state) { _ in
snackbarPresenter.dismissAll()
}
}
}
3 changes: 3 additions & 0 deletions Mail/Views/Menu Drawer/MenuDrawerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class NavigationDrawerState: ObservableObject {
}

struct NavigationDrawer: View {
@LazyInjectService private var snackbarPresenter: SnackBarPresentable

@EnvironmentObject private var navigationDrawerState: NavigationDrawerState

@GestureState private var isDragGestureActive = false
Expand Down Expand Up @@ -79,6 +81,7 @@ struct NavigationDrawer: View {
.gesture(dragGestureForRootViewSize(rootViewSizeProxy.size))
.statusBarHidden(navigationDrawerState.isOpen)
.onChange(of: navigationDrawerState.isOpen) { isOpen in
snackbarPresenter.dismissAll()
if !isOpen {
offsetWidth = 0
}
Expand Down
34 changes: 30 additions & 4 deletions MailCore/Cache/MainViewState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,56 @@
*/

import Foundation
import InfomaniakCoreUI
import InfomaniakDI
import SwiftModalPresentation

public protocol SelectedThreadOwnable {
var selectedThread: Thread? { get set }
}

public class MainViewState: ObservableObject, SelectedThreadOwnable {
@ModalPublished public var composeMessageIntent: ComposeMessageIntent?
@ModalPublished public var composeMessageIntent: ComposeMessageIntent? {
Copy link
Contributor

@adrien-coye adrien-coye Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go beyond just a MVP maybe we should have a robust mechanism to observe changes on all ModalPublished. To be discussed with @PhilippeWeidmann

didSet {
@InjectService var snackbarPresenter: SnackBarPresentable
snackbarPresenter.dismissAll()
}
}

@ModalPublished public var settingsViewConfig: SettingsViewConfig?

@ModalPublished public var isShowingSyncProfile = false
@ModalPublished public var isShowingSyncDiscovery = false
@Published public var isShowingSearch = false
@Published public var isShowingSearch = false {
didSet {
@InjectService var snackbarPresenter: SnackBarPresentable
snackbarPresenter.dismissAll()
}
}

@ModalPublished public var isShowingReviewAlert = false
@ModalPublished public var isShowingSafariView: IdentifiableURL?
@ModalPublished public var isShowingSafariView: IdentifiableURL? {
didSet {
@InjectService var snackbarPresenter: SnackBarPresentable
snackbarPresenter.dismissAll()
}
}

@ModalPublished public var isShowingUpdateAvailable = false
@ModalPublished public var isShowingSetAppAsDefaultDiscovery = false
@Published public var isShowingChristmasEasterEgg = false

@LazyInjectService private var snackbarPresenter: SnackBarPresentable

/// Represents the state of navigation
///
/// The selected thread is the last in collection, by convention.
@Published public var threadPath = [Thread]()
@Published public var threadPath = [Thread]() {
didSet {
snackbarPresenter.dismissAll()
}
}

@Published public var selectedFolder: Folder {
didSet {
SentryDebug.switchFolderBreadcrumb(uid: selectedFolder.remoteId, name: selectedFolder.name)
Expand Down
6 changes: 6 additions & 0 deletions MailCore/Utils/SnackBar/SnackBarPresentable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public protocol SnackBarPresentable {
anchor: CGFloat,
contextView: UIView?
)
/// Dismiss all currently presented snackBars
func dismissAll()
}

public final class SnackBarPresenter: SnackBarPresentable {
Expand Down Expand Up @@ -67,4 +69,8 @@ public final class SnackBarPresenter: SnackBarPresentable {
)
}
}

public func dismissAll() {
NotificationCenter.default.post(name: IKSnackBar.dismissSnackbarNotificationName, object: nil, userInfo: nil)
}
}
5 changes: 4 additions & 1 deletion Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ let project = Project(name: "Mail",
url: "https://github.com/Infomaniak/ios-core",
.revision("7388c5ccc5ab177bf640968a711be2ab2f24200c")
),
.package(url: "https://github.com/Infomaniak/ios-core-ui", .upToNextMajor(from: "7.0.0")),
.package(
url: "https://github.com/Infomaniak/ios-core-ui",
.revision("78fc0f85a4b32051ab3de6bb492a3690c1fc363b")
),
.package(url: "https://github.com/Infomaniak/ios-notifications", .upToNextMajor(from: "5.0.0")),
.package(url: "https://github.com/Infomaniak/ios-create-account", .upToNextMajor(from: "6.0.0")),
.package(url: "https://github.com/Infomaniak/ios-bug-tracker", .upToNextMajor(from: "4.0.0")),
Expand Down
Loading