@@ -84,7 +84,7 @@ public struct FloatingButton<MainView, ButtonView>: View where MainView: View, B
8484 . offset ( alignmentOffsets. isEmpty ? . zero : alignmentOffsets [ i] )
8585 . offset ( buttonOffset ( at: i) )
8686 . scaleEffect ( isOpen ? 1 : initialScaling)
87- . opacity ( isOpen ? 1 : initialOpacity)
87+ . opacity ( mainButtonSize == . zero ? 0 : isOpen ? 1 : initialOpacity)
8888 . animation ( buttonAnimation ( at: i) , value: isOpen)
8989 }
9090
@@ -175,18 +175,36 @@ public struct FloatingButton<MainView, ButtonView>: View where MainView: View, B
175175 }
176176 }
177177
178- wholeMenuSize. wrappedValue = . zero
179- menuButtonsSize. wrappedValue = . zero
178+ var buttonsSize = CGSize . zero
180179 for size in sizes {
181- menuButtonsSize. wrappedValue = CGSize (
182- width: max ( size. width, menuButtonsSize. wrappedValue. width) ,
183- height: menuButtonsSize. wrappedValue. height + size. height + spacing
180+ if [ . top, . bottom] . contains ( alignment) {
181+ buttonsSize = CGSize (
182+ width: max ( size. width, buttonsSize. width) ,
183+ height: buttonsSize. height + size. height + spacing
184+ )
185+ } else {
186+ buttonsSize = CGSize (
187+ width: buttonsSize. width + size. width + spacing,
188+ height: max ( size. height, buttonsSize. height)
189+ )
190+ }
191+ }
192+
193+ var wholeSize = CGSize . zero
194+ if [ . top, . bottom] . contains ( alignment) {
195+ wholeSize = CGSize (
196+ width: max ( buttonsSize. width, mainButtonSize. width) ,
197+ height: buttonsSize. height + mainButtonSize. height
198+ )
199+ } else {
200+ wholeSize = CGSize (
201+ width: buttonsSize. width + mainButtonSize. width,
202+ height: max ( buttonsSize. height, mainButtonSize. height)
184203 )
185204 }
186- wholeMenuSize. wrappedValue = CGSize (
187- width: max ( menuButtonsSize. wrappedValue. width, mainButtonSize. width) ,
188- height: menuButtonsSize. wrappedValue. height + mainButtonSize. height
189- )
205+
206+ menuButtonsSize. wrappedValue = buttonsSize
207+ wholeMenuSize. wrappedValue = wholeSize
190208 }
191209
192210 fileprivate func roundToTwoDigits( _ size: CGSize ) -> CGSize {
0 commit comments