mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Switch callbacks to combine (#1710)
* #750 - Convert the SoftLogoutScreen to combine * #750 - Convert the UserSessionFlowCoordinator to Combine * #750 - Convert the AnalyticsPromptScreen to Combine * #750 - Convert the LoginScreen to Combine * #750 - Convert the ServerSelectionScreen to Combine * #750 - Convert the EmojiPickerScreen to Combine * #750 - Convert the HomeScreen to Combine * #750 - Convert the MediaUploadPreviewScreen to Combine * #750 - Convert the OnboardingScreen to Combine * Rename `Onboarding` to `OnboardingScreen` * #750 - Convert the ReportContentScreen to Combine * #750 - Convert the RoomDetailsSscreen to Combine * #750 - Convert the RoomMemberDetailsScreen to Combine * #750 - Convert the RoomMembersListScreen to Combine * #750 - Convert the SessionVerificationScreen to Combine * #750 - Convert the SettingsScreen to Combine * #750 - Convert the AdvancedSettingsScreen to Combine * #750 - Convert the DeveloperOptionsScreen to Combine * Fix the unit tests * Use .sink action and the same cancellables constructor everywhere * Cleanup cancellables when setting up tests
This commit is contained in:
+27
-16
@@ -14,13 +14,22 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
enum AnalyticsPromptScreenCoordinatorAction {
|
||||
case done
|
||||
}
|
||||
|
||||
final class AnalyticsPromptScreenCoordinator: CoordinatorProtocol {
|
||||
private let analytics: AnalyticsService
|
||||
private var viewModel: AnalyticsPromptScreenViewModel
|
||||
|
||||
var callback: (@MainActor () -> Void)?
|
||||
private var viewModel: AnalyticsPromptScreenViewModelProtocol
|
||||
private let actionsSubject: PassthroughSubject<AnalyticsPromptScreenCoordinatorAction, Never> = .init()
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
var actions: AnyPublisher<AnalyticsPromptScreenCoordinatorAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init(analytics: AnalyticsService, termsURL: URL) {
|
||||
self.analytics = analytics
|
||||
@@ -30,20 +39,22 @@ final class AnalyticsPromptScreenCoordinator: CoordinatorProtocol {
|
||||
// MARK: - Public
|
||||
|
||||
func start() {
|
||||
viewModel.callback = { [weak self] result in
|
||||
guard let self else { return }
|
||||
|
||||
switch result {
|
||||
case .enable:
|
||||
MXLog.info("Enable Analytics")
|
||||
analytics.optIn()
|
||||
self.callback?()
|
||||
case .disable:
|
||||
MXLog.info("Disable Analytics")
|
||||
analytics.optOut()
|
||||
self.callback?()
|
||||
viewModel.actions
|
||||
.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
|
||||
switch action {
|
||||
case .enable:
|
||||
MXLog.info("Enable Analytics")
|
||||
analytics.optIn()
|
||||
actionsSubject.send(.done)
|
||||
case .disable:
|
||||
MXLog.info("Disable Analytics")
|
||||
analytics.optOut()
|
||||
actionsSubject.send(.done)
|
||||
}
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func toPresentable() -> AnyView {
|
||||
|
||||
Reference in New Issue
Block a user