Skip to content

Commit

Permalink
Prevent updating layout while presenting/dismissing
Browse files Browse the repository at this point in the history
  • Loading branch information
kennic committed Dec 3, 2020
1 parent 2b03950 commit 38499ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion NKModalPresenter.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'NKModalPresenter'
s.version = '1.5.5'
s.version = '1.5.6'
s.summary = 'Present UIViewController modally'
s.description = <<-DESC
Present UIViewController modally easily and beautifully with animation.
Expand Down
19 changes: 17 additions & 2 deletions NKModalPresenter/NKModalController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,32 @@ public class NKModalController: NKModalContainerViewController {
}

public func updatePosition(_ position: NKModalPresentPosition, duration: TimeInterval? = nil, completion: (() -> Void)? = nil) {
guard targetPosition != position else { return }
targetPosition = position
updateLayout(duration: duration, completion: completion)

contentSize = getContentSize()
layoutView(duration: duration, completion: completion)
}

public func updateLayout(duration: TimeInterval? = nil, completion: (() -> Void)? = nil) {
contentSize = getContentSize()
guard !isDismissing else { return }

let newContentSize = getContentSize()
guard contentSize != newContentSize else { return }
guard !isPresenting else {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.updateLayout(duration: duration, completion: completion)
}
return
}

contentSize = newContentSize
layoutView(duration: duration, completion: completion)
}

private func layoutView(duration: TimeInterval? = nil, completion: (() -> Void)? = nil) {
guard contentViewController != nil else { return }
guard !isDismissing else { return }

let cornerRadius = delegate?.cornerRadius(modalController: self) ?? self.cornerRadius
containerView.clipsToBounds = cornerRadius > 0
Expand Down

0 comments on commit 38499ce

Please sign in to comment.