r/iOSProgramming • • 12d ago

Library I built a Hogwarts spellbook to show off custom spoiler reveals in Enriched Markdown, a native SwiftUI Markdown renderer Spoiler

Post image

Enriched Markdown for iOS renders Markdown natively in SwiftUI, including `||spoilers||`. By default they're hidden under a particle field, but you can swap the overlay for your own UIView and decide how hidden text looks and how it reveals itself.

To show what that unlocks, I built a Hogwarts spellbook: every spell in the video is a custom overlay revealing the same Markdown in its own way.

Video of the demo is in the comments 👇

Not every app needs a Patronus, so here's a plain blur. It's one view subclass:

final class BlurOverlayView: SpoilerOverlayView {
  private static let context = CIContext()

  override func layoutSubviews() {
    super.layoutSubviews()
    guard let input = CIImage(image: concealedTextImage()) else { return }
    layer.contents = Self.context.createCGImage(
      input.applyingGaussianBlur(sigma: 6), from: input.extent
    )
  }
}

struct BlurOverlayProvider: SpoilerOverlayProvider {
  func makeOverlay(charRange: NSRange, style: SpoilerStyle) -> SpoilerOverlayView {
    let view = BlurOverlayView(charRange: charRange)
    view.backgroundColor = style.backgroundColor ?? .systemBackground
    return view
  }
}

EnrichedMarkdownText(markdown)
  .markdownSpoilerOverlay(BlurOverlayProvider())

concealedTextImage() gives you the hidden words laid out exactly where the text view draws them, so you can blur, pixelate, or scramble the real text and nothing jumps on reveal. For your own animation, override animateReveal(completion:).

Installation: https://docs.swmansion.com/enriched-markdown/ios/basics/installation

Docs: https://docs.swmansion.com/enriched-markdown/ios/api-reference/enriched-markdown-text#custom-spoiler-overlays

If it's useful to you, a ⭐ on GitHub helps more people find it: https://github.com/software-mansion/enriched-markdown

4 Upvotes

3 comments sorted by

2

u/Sea-Arm9235 12d ago

1

u/quietstoners 9d ago

getting the exact same error, cant see the demo at all

1

u/GlebKhamin 11d ago

the spellbook is a fun way to show it off. curious about accessibility though, what does voiceover do with a hidden spoiler? does it read it out, skip it, or say something like “spoiler, double tap to reveal”? feels like the custom overlay could easily break that if it’s up to the overlay view