From 40e6aa588937ccb25d3762409c47386bd3e6dba9 Mon Sep 17 00:00:00 2001 From: Jochen Pfeiffer Date: Mon, 8 Jan 2024 11:41:15 +0100 Subject: [PATCH] Add example for custom layout/animation --- .../ConfigurationExampleViewController.swift | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Example/JJFloatingActionButton/ConfigurationExampleViewController.swift b/Example/JJFloatingActionButton/ConfigurationExampleViewController.swift index 7346f3c..d35bf2f 100644 --- a/Example/JJFloatingActionButton/ConfigurationExampleViewController.swift +++ b/Example/JJFloatingActionButton/ConfigurationExampleViewController.swift @@ -56,7 +56,24 @@ class ConfigurationExampleViewController: UIViewController { actionButton.buttonImageSize = CGSize(width: 30, height: 30) actionButton.buttonAnimationConfiguration = .transition(toImage: #imageLiteral(resourceName: "X")) - actionButton.itemAnimationConfiguration = .slideIn(withInterItemSpacing: 14, firstItemSpacing: 28) + + let itemAnimationConfiguration = JJItemAnimationConfiguration() + itemAnimationConfiguration.itemLayout = JJItemLayout { items, actionButton in + var previousItem: JJActionItem? + for item in items { + let previousView = previousItem?.circleView ?? actionButton.circleView + item.bottomAnchor.constraint(equalTo: previousView.topAnchor, constant: -5).isActive = true + item.leftAnchor.constraint(equalTo: previousView.rightAnchor, constant: -2).isActive = true + previousItem = item + + } + } + + itemAnimationConfiguration.closedState = JJItemPreparation { item, _, _, _ in + item.transform = CGAffineTransform(scaleX: 5, y: 0) + item.alpha = 0 + } + actionButton.itemAnimationConfiguration = itemAnimationConfiguration actionButton.layer.shadowColor = UIColor.black.cgColor actionButton.layer.shadowOffset = CGSize(width: 0, height: 1)