Skip to content

sentryco/HoverMenu

Repository files navigation

Tests codebeat badge

HoverMenu

HoverMenu is a Swift package that provides a classic hover menu implementation for both iOS and macOS platforms. It offers a unified API to create context menus that adapt to the specific UI patterns of each operating system.

Note

For iOS, the menu is horizontally arranged (the classic look from UIKit that currently is not available in SwiftUI), and for macOS, the menu is vertically arranged.

Features

  • Platform Support: Fully supports both iOS and macOS, ensuring a consistent experience across devices.
  • Customizable Menus: Offers extensive customization options for menu items including actions, icons, and optional keyboard shortcuts.
  • SwiftUI Integration: Seamlessly integrates with SwiftUI, allowing for modern, declarative UI code.

Usage Example

To use HoverMenu in your SwiftUI application, you can follow this simple example:

import SwiftUI
import HoverMenu

struct ContentView: View {
    var body: some View {
        Text("Right-click or hover to see the menu")
            .hoverMenu {
                Button("Refresh", action: refreshAction)
                Button("Settings", action: settingsAction)
                Divider()
                Button("Quit", action: quitAction)
            }
    }

    func refreshAction() {
        print("Refreshed")
    }

    func settingsAction() {
        print("Settings opened")
    }

    func quitAction() {
        print("Application quitting")
    }
}

Installation

dependencies: [
    .package(url: "https://github.com/sentryco/HoverMenu", branch: "main")
]

Todo:

  • Add preview for macOS
  • Rename repo to PopupMenu or PopoverMenu ?
  • Refactoring and Code Cleanup
  • Testing and Documentation (Improving tests and documentation can help maintain high code quality and ease future development efforts.)
  • Code Organization and Structure: Separation of Concerns: Some files contain multiple responsibilities, which could be separated into more focused components or extensions. For example, the PopupMenu.swift file handles UI interactions and also manages state and UI updates, which could be more cleanly separated.
  • Refactoring and Code Cleanup: PopupMenu and EditMenu Classes: There are multiple Fixme comments indicating areas that need attention, such as refactoring and cleaning up the code. For instance, in PopupMenu.swift and EditMenu+Coordinator.swift, there are suggestions to investigate and possibly refactor the way menus are presented and how gestures are handled.
  • Remove unit-tests, add uitests
  • UI/UX Enhancements: User Interface Polish: Enhancing the user interface, such as adding icons to menu items or improving the layout and responsiveness of UI components.

About

Classic hover menu for iOS and macOS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages