Home > Blockchain >  How to add another function after changing the app mode in RxSwift
How to add another function after changing the app mode in RxSwift

Time:03-18

I have a switcher that changes the app theme.

        switchButton.rx
            .controlEvent(.valueChanged)
            .withLatestFrom(themeService.typeStream)
            .map { $0 == .dark ? .light : .dark }
            .bind(to: themeService.switcher)
            .disposed(by: disposeBag)

I want to add another custom function when an app theme changes. Thanks

CodePudding user response:

You're allowed to subscribe to an Observable more than once.

let theme = switchButton.rx
    .controlEvent(.valueChanged)
    .withLatestFrom(themeService.typeStream)
    .map { $0 == .dark ? .light : .dark }
    .share()

theme
    .bind(to: themeService.switcher)
    .disposed(by: disposeBag)

theme
    .bind(to: anotherCustomFunction)
    .disposed(by: disposeBag)
  • Related