InstructUI

main

InstructUI โ€” A Swift package for building instructional overlays and guided interactions in SwiftUI views.
michaelborgmann/InstructUI

InstructUI

Swift iOS SPM License Version

๐Ÿงญ A Swift package for building guided, touch-friendly instructional overlays in SwiftUI. Ideal for apps with voice assistance, learning flows, or gesture-based tutorials.


Features

  • โœ… InstructionOverlay โ€” draws a cutout and message above any UI element
  • โœ… InstructionGuide โ€” attachable ViewModifier for multi-step instruction flows
  • โœ… Built-in speech synthesis with SpeechKit
  • โœ… Child-friendly and gesture-driven by design
  • โœ… Works with `PreferenceKey-based layout tracking
  • โœ… Fully documented with DocC-style comments

Installation

Use Swift Package Manager:

.package(url: "https://github.com/michaelborgmann/InstructUI.git", from: "0.1.0")

Then import it where needed:

import InstructUI

If using voice support, also include:

import SpeechKit

Usage

1. Define Instruction Steps

Create an array of InstructionStep using frames from instructionAnchor preferences:

@State var steps: [InstructionStep] = []
@State var currentStepIndex: Int? = 0
let speaker = SpeechSynthesizer()

2. Mark Views with Anchors

Attach instructionAnchor(id:) to any view you want to highlight:

Button("Tap me") {
    currentStepIndex = 0
}
.instructionAnchor(id: "start-button")

3. Add InstructionGuide Modifier

Apply the InstructionGuide view modifier to your main container:

.frame(maxWidth: .infinity, maxHeight: .infinity) // Optional: ensure layout fills the screen
.modifier(InstructionGuide(steps: $steps, currentStepIndex: $currentStepIndex, speaker: speaker))
.edgesIgnoringSafeArea(.all) // Optional: extend behind safe areas

4. Track Anchored View Frames

Use .onPreferenceChange(ViewFrameKey.self) to populate your steps once layout is complete:

.onPreferenceChange(ViewFrameKey.self) { frames in
    if !frames.isEmpty {
        instructionSteps = [
            InstructionStep(message: "This is an instruction overlay on top of a button", highlightFrame: frames["instruction-button"]!, isMessageBelow: true)
        ]
    }
}

Navigate Steps (Optional)

You can advance to the next step manually or by listening to a custom event:

.onReceive(NotificationCenter.default.publisher(for: .instructionNext)) { _ in
    if let i = currentStepIndex {
        let next = i + 1
        currentStepIndex = next < steps.count ? next : nil
    }
}

๐Ÿงช SwiftUI Previews

To see it in action, check out the #Preview examples inside InstructionGuide.swift. These show single-step and scrollable usage patterns, helpful for getting started or customizing your implementation.


Requirements

iOS 17+ Swift 5.9 or 6 Swift Concurrency Swift Package Manager (SPM)


License

MIT License โ€” see LICENSE

Please credit this project if you use it in commercial or open-source apps.


About

Created by Michael Borgmann for the Wonder Tales storytelling engine. Part of the Vicentina Studios toolchain for creative, language-rich experiences.

Description

  • Swift Tools 6.1.0
View More Packages from this Author

Dependencies

Last updated: Fri Aug 01 2025 03:42:04 GMT-0900 (Hawaii-Aleutian Daylight Time)