jjochen / JJFloatingActionButton

Floating Action Button for iOS
https://jjochen.github.io/JJFloatingActionButton
MIT License
376 stars 75 forks source link

Spacing Betwens Items #258

Closed johnharutyunyan closed 4 years ago

johnharutyunyan commented 4 years ago

Hello , guys. Is it possible to have space between items ? Can I have different spacing between From Action Button and First Item - 30, after First Item spacing - 15

jjochen commented 4 years ago

Configuring the space between items is fairly simple:

        actionButton.itemAnimationConfiguration = .popUp(withInterItemSpacing: 15)

A different spacing for the first item is a bit more complicated at the moment and should probably be easier (I'll make it configurable #262).

        let configuration = JJItemAnimationConfiguration()
        configuration.itemLayout = JJItemLayout { items, actionButton in
            var previousItem: JJActionItem?
            for item in items {
                let previousView = previousItem ?? actionButton
                let spacing: CGFloat = previousItem == nil ? 60 : 15
                item.bottomAnchor.constraint(equalTo: previousView.topAnchor, constant: -spacing).isActive = true
                item.circleView.centerXAnchor.constraint(equalTo: actionButton.centerXAnchor).isActive = true
                previousItem = item
            }
        }
        configuration.closedState = .scale()
        actionButton.itemAnimationConfiguration = configuration

And I'm realizing now that some methods in there are not public. I will fix that as soon as possible (#259)

jjochen commented 4 years ago

This should be easier with version 2.5.0

actionButton.itemAnimationConfiguration = .popUp(withInterItemSpacing: 15, firstItemSpacing: 30)
jjochen commented 4 years ago

I will close this now. If you have more questions feel free to reopen it.