Skip to content

YugoMatsuda/FloatingMenuActionButton

Repository files navigation

FloatingMenuActionButton

Example

Overview

This is an open-source library to use with SwiftUI. It allows you to create Floating menu action button.

Installation

Swift Package Manager

To integrate FloatingMenuActionButton into your Xcode project using Xcode 12, specify it in File > Swift Packages > Add Package Dependency...:

https://github.com/YugoMatsuda/FloatingMenuActionButton

Usage

import SwiftUI
import FloatingMenuActionButton

struct ContentView: View {
    @State var isSelected = false
    @State private var showOtherView = false
    var body: some View {
        ZStack {
            if isSelected {
                Color.gray.edgesIgnoringSafeArea(.all)
                    .onTapGesture {
                        withAnimation(.easeIn(duration: 0.2)) {
                            isSelected.toggle()
                        }
                    }
            }
            
            VStack {
                Spacer()
                
                HStack {
                    Spacer()
                    
                    FloatingMenuActionButton(isSelected: $isSelected, floatingMenuItems: generateFloatingMenuItems())
                }
                .padding()
            }
        }
        .sheet(isPresented: $showOtherView) {
            Text("Other View")
        }
    }
    
    private func generateFloatingMenuItems() -> [FloatingMenuItem] {
        return  [ .init(iconName: "pencil", buttonAction: { showOtherView.toggle() }),
                  .init(iconName: "camera.fill", buttonAction: { showOtherView.toggle() }),
                  .init(iconName: "paperplane.fill", buttonAction: { showOtherView.toggle() }),
        ]
    }
}

About

FloatingMenuActionButton

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages