-
Notifications
You must be signed in to change notification settings - Fork 0
Fix modal dismiss table truncation #40
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ class TransitionTableViewController: TransitionBaseViewController, Fluidable { | |
|
|
||
| /** Dummy value to prevent UIViewPropertyAnimator from finishing immediately. */ | ||
| @objc dynamic var transitionProgress: CGFloat = 0 | ||
| private var dismissCellContentWidth: CGFloat? | ||
|
|
||
| /** Views */ | ||
| @IBOutlet weak var tableView: TableView! | ||
|
|
@@ -148,6 +149,7 @@ extension TransitionTableViewController: FluidTransitionDestinationConfiguration | |
| "navigation: " + String(describing: navigation), | ||
| ]) | ||
| guard transitionStyle.isFluid else { return nil } | ||
| self.dismissCellContentWidth = initialDimension.frame().width | ||
| var animators: [FluidAnimatorCompatible] = [FluidAnimatorCompatible]() | ||
| /* NOTE: Hide button in 30% of duration without delay (Core Animation) */ | ||
| // if let buttonAnimator: FluidCoreAnimator = FluidCoreAnimator(for: self.closeButton.layer, id: "buttonAnimator (Dismiss)", | ||
|
|
@@ -208,6 +210,14 @@ extension TransitionTableViewController: FluidTransitionDestinationConfiguration | |
| self.view.layoutIfNeeded() | ||
| }) | ||
| animators.append(constraintAnimator) | ||
| /* NOTE: Table cell layout (UIViewPropertyAnimator) */ | ||
| let cellLayoutAnimator: FluidPropertyAnimator = .init(duration: duration, easing: easing, id: "cellLayoutAnimator (Dismiss)") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line Length Violation: Line should be 120 characters or less: currently 133 characters (line_length) |
||
| cellLayoutAnimator.add({ [weak self] in | ||
| guard let `self`: TransitionTableViewController = self else { return } | ||
| self.layoutVisibleCellsForDismiss() | ||
| }) | ||
| animators.append(cellLayoutAnimator) | ||
| self.layoutVisibleCellsForDismiss() | ||
| return animators | ||
| } | ||
| } | ||
|
|
@@ -238,6 +248,16 @@ extension TransitionTableViewController: FluidTransitionDestinationActionDelegat | |
| "state:".lpad() + String(describing: state), | ||
| "progress:".lpad() + String(describing: progress), | ||
| ]) | ||
| switch state { | ||
| case .begin, .update: | ||
| if transitionStyle.isFluid { | ||
| self.layoutVisibleCellsForDismiss() | ||
| } | ||
| case .cancel: | ||
| self.resetVisibleCellsAfterDismissCancel() | ||
| case .end: | ||
| self.dismissCellContentWidth = nil | ||
| } | ||
| } | ||
|
|
||
| func transitionPresentInteractionDidProgress(from source: FluidSourceViewController, to destination: FluidDestinationViewController, | ||
|
|
@@ -264,17 +284,33 @@ extension TransitionTableViewController: FluidTransitionDestinationActionDelegat | |
| case .update: | ||
| if transitionStyle.isFluid { | ||
| self.closeButton.alpha = 1 - progress | ||
| self.layoutVisibleCellsForDismiss() | ||
| } else { | ||
| self.closeButton.alpha = (1 - progress * 3).clamped(0, 1) | ||
| } | ||
| case .cancel: | ||
| self.resetVisibleCellsAfterDismissCancel() | ||
| let animator: UIViewPropertyAnimator = UIViewPropertyAnimator(duration: 0.1, easing: .linear) | ||
| animator.addAnimations({ [weak self] in | ||
| self?.closeButton.alpha = 1 | ||
| }) | ||
| animator.startAnimation() | ||
| case .end: | ||
| break | ||
| self.dismissCellContentWidth = nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private extension TransitionTableViewController { | ||
| func layoutVisibleCellsForDismiss() { | ||
| guard self.tableView.window != nil else { return } | ||
| self.view.layoutIfNeeded() | ||
| self.tableView.layoutVisibleCellsImmediately(constrainingTextTo: self.dismissCellContentWidth) | ||
| } | ||
|
|
||
| func resetVisibleCellsAfterDismissCancel() { | ||
| self.dismissCellContentWidth = nil | ||
| guard self.tableView.window != nil else { return } | ||
| self.tableView.layoutVisibleCellsImmediately() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,3 +150,86 @@ final class MainSpec: QuickSpec { | |
| } | ||
|
|
||
| } | ||
|
|
||
| final class FluidModalTableDismissalLayoutTests: XCTestCase { | ||
| class TestFluidSourceViewController: UIViewController, Fluidable {} | ||
|
|
||
| func testConstrainsTableCellLabelsToDismissTargetWidth() { | ||
| let bundle = Bundle(for: FluidModalTableDismissalLayoutTests.self) | ||
| let cell = UINib(nibName: "TableCell", bundle: bundle) | ||
| .instantiate(withOwner: nil, options: nil).first as! TableCell | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Force Cast Violation: Force casts should be avoided. (force_cast) |
||
| cell.frame = CGRect(x: 0, y: 0, width: 430, height: 64) | ||
| cell.contentView.frame = cell.bounds | ||
| cell.configure(row: 0) | ||
| cell.layoutIfNeeded() | ||
|
|
||
| cell.layoutTextLabels(forContentWidth: 390) | ||
|
|
||
| XCTAssertEqual(cell.titleLabel.lineBreakMode, .byTruncatingTail) | ||
| XCTAssertEqual(cell.captionLabel.lineBreakMode, .byTruncatingTail) | ||
| XCTAssertEqual(cell.titleLabel.frame.width, | ||
| 390 - cell.titleLabel.frame.minX - 20, | ||
| accuracy: 0.5) | ||
| XCTAssertLessThan(cell.titleLabel.frame.maxX, cell.contentView.frame.maxX) | ||
| } | ||
|
|
||
| func testUpdatesVisibleTableCellsWhileTheModalShrinks() { | ||
| let model: RootModel = .navigationFluidFullScreen | ||
| let bundle = Bundle(for: FluidModalTableDismissalLayoutTests.self) | ||
| let navigation = UINib(nibName: "NavigationRootNavigationController", bundle: bundle) | ||
| .instantiate(withOwner: nil, options: nil).first as! NavigationRootNavigationController | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Force Cast Violation: Force casts should be avoided. (force_cast) |
||
| let destination = UINib(nibName: "NavigationTableViewController", bundle: bundle) | ||
| .instantiate(withOwner: nil, options: nil).first as! NavigationTableViewController | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Force Cast Violation: Force casts should be avoided. (force_cast) |
||
| let source: TestFluidSourceViewController = TestFluidSourceViewController() | ||
|
|
||
| navigation.configure(modelIndex: model.rawValue) | ||
| navigation.pushViewController(destination, animated: false) | ||
| destination.configure(modelIndex: model.rawValue) | ||
| destination.loadViewIfNeeded() | ||
| source.loadViewIfNeeded() | ||
|
|
||
| let animators: [FluidAnimatorCompatible] = destination.transitionAdditionalDismissAnimations( | ||
| from: destination, | ||
| to: source, | ||
| with: navigation, | ||
| on: UIView(frame: CGRect(x: 0, y: 0, width: 430, height: 930)), | ||
| initialDimension: FluidInitialFrameDimension(for: model.transitionStyle, | ||
| contentOrigin: CGPoint(x: 20, y: 100), | ||
| contentSize: CGSize(width: 390, height: 700), | ||
| contentTransform: CATransform3DIdentity), | ||
| finalDimension: FluidFinalFrameDimension(for: model.transitionStyle, | ||
| portraitContentSize: CGSize(width: 430, height: 930), | ||
| landscapeContentSize: CGSize(width: 930, height: 430), | ||
| portraitContentTransform: CATransform3DIdentity, | ||
| landscapeContentTransform: CATransform3DIdentity), | ||
| initialStyle: model.initialFrameStyle!, | ||
| finalStyle: model.finalFrameStyle!, | ||
| transitionStyle: model.transitionStyle, | ||
| duration: 0.5, | ||
| easing: FluidAnimatorEasing.linear) ?? [] | ||
|
|
||
| XCTAssertTrue(animators.contains { $0.identifier == "cellLayoutAnimator (Dismiss)" }) | ||
| } | ||
| } | ||
|
|
||
| final class NavigationFluidFullScreenDismissUITests: XCTestCase { | ||
| func testFinishAnimatedDismissWithTableContent() { | ||
| let app: XCUIApplication = XCUIApplication() | ||
| let orientation: UIDeviceOrientation = .portrait | ||
| let model: RootModel = .navigationFluidFullScreen | ||
|
|
||
| addTeardownBlock { | ||
| app.terminate() | ||
| XCUIDevice.shared.orientation = .portrait | ||
| } | ||
|
|
||
| XCUIDevice.shared.orientation = orientation | ||
| app.setEnv(MainSpec.env) | ||
| app.launch() | ||
|
|
||
| MainSpec.finishAnimatedPresent(app: app, orientation: orientation, model: model) | ||
| MainSpec.pushViewController(app: app, orientation: orientation, model: model) | ||
| MainSpec.popViewControllerByTappingBackButton(app: app, orientation: orientation, model: model) | ||
| MainSpec.finishAnimatedDismissByTappingContainer(app: app, orientation: orientation, model: model) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line Length Violation: Line should be 120 characters or less: currently 133 characters (line_length)