Skip to content

Commit

Permalink
Merge pull request #566 from adevinta/fix/switch-interaction
Browse files Browse the repository at this point in the history
[Fix-563] Switch: UserInteraction bug
  • Loading branch information
robergro authored Oct 24, 2023
2 parents 5e4048c + 3ebd6e6 commit 7ce02a5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions core/Sources/Components/Switch/View/UIKit/SwitchUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -772,23 +772,23 @@ public final class SwitchUIView: UIView {

// **
// Show spaces
self.viewModel.$showToggleLeftSpace.subscribe(in: &self.subscriptions) { [weak self] showSpace in
guard let self, let showSpace else { return }
self.viewModel.$showToggleLeftSpace.subscribe(in: &self.subscriptions) { [weak self] showLeftSpace in
guard let self, let showLeftSpace else { return }

// showSpace MUST be different to continue
// showLeftSpace MUST be different to continue
// Or if the both space have the same isHidden (default state)
guard self.toggleLeftSpaceView.isHidden == showSpace ||
guard self.toggleLeftSpaceView.isHidden == showLeftSpace ||
self.toggleRightSpaceView.isHidden == self.toggleLeftSpaceView.isHidden else {
return
}

// Lock interaction before animation
let currentUserInteraction = self.toggleView.isUserInteractionEnabled
let currentUserInteraction = self.viewModel.isToggleInteractionEnabled ?? true
self.toggleView.isUserInteractionEnabled = false

UIView.animate(withDuration: Constants.animationDuration) { [weak self] in
self?.toggleLeftSpaceView.isHidden = !showSpace
self?.toggleRightSpaceView.isHidden = showSpace
self?.toggleLeftSpaceView.isHidden = !showLeftSpace
self?.toggleRightSpaceView.isHidden = showLeftSpace
} completion: { [weak self] _ in
// Unlock interaction after animation
self?.toggleView.isUserInteractionEnabled = currentUserInteraction
Expand Down

0 comments on commit 7ce02a5

Please sign in to comment.