Swiftpack.co - riiid/FullScreenOverlay as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by riiid.
riiid/FullScreenOverlay v1.1.0
A novel way to present a full-screen SwiftUI overlay from the view not in full-screen size.
โญ๏ธ 11
๐Ÿ•“ 11 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/riiid/FullScreenOverlay.git", from: "v1.1.0")

FullScreenOverlay

Build

ํ’€์Šคํฌ๋ฆฐ ํฌ๊ธฐ๊ฐ€ ์•„๋‹Œ ๋ทฐ์—์„œ ํ’€์Šคํฌ๋ฆฐ SwiftUI ์˜ค๋ฒ„๋ ˆ์ด๋ฅผ ๋„์šฐ๋Š” ํš๊ธฐ์ ์ธ ๋ฐฉ๋ฒ•.

import SwiftUI
import FullScreenOverlay

content
    .fullScreenOverlay(presentationSpace: .named("RootView")) {
        overlayContent
    }

๋ชฉ์ฐจ

๋™๊ธฐ

SwiftUI์—์„œ ZStack์ด๋‚˜ overlay(alignment:content:) ๋ชจ๋””ํŒŒ์ด์–ด๋ฅผ ์‚ฌ์šฉํ•ด ํ™”๋ฉด ์ „์ฒด๋ฅผ ๋ฎ๋Š” ์ปค์Šคํ…€ ๋ฐ”ํ…€์‹œํŠธ๋ฅผ ๋„์šฐ๋ ค๋ฉด, ํ™”๋ฉด๊ณผ ๋™์ผํ•œ ํฌ๊ธฐ๋ฅผ ๊ฐ–๋Š” ์ตœ์ƒ์œ„ ๋ทฐ์—์„œ ์˜ค๋ฒ„๋ ˆ์ด๋ฅผ ๋„์›Œ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์‹œ ๋งํ•ด, ์ž‘์€ ํฌ๊ธฐ์˜ ์ปดํฌ๋„ŒํŠธ ๋ทฐ์—์„œ๋Š” ํ™”๋ฉด ์ „์ฒด๋ฅผ ๋ฎ๋Š” ์ปค์Šคํ…€ ๋ฐ”ํ…€์‹œํŠธ๋ฅผ ๋„์šธ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. iOS 14 ์ด์ƒ ๋ฒ„์ „๋ถ€ํ„ฐ๋Š” ์ „์ฒด ํ™”๋ฉด ํฌ๊ธฐ๋กœ ๋ชจ๋‹ฌ ๋ทฐ๋ฅผ ๋„์šธ ์ˆ˜ ์žˆ๋Š” fullScreenCover(isPresented:onDismiss:content:) ๋ชจ๋””ํŒŒ์ด์–ด๊ฐ€ ์ œ๊ณต๋˜์ง€๋งŒ, ์ด๋Š” ๋‹จ์ˆœํžˆ sheet(isPresented:onDismiss:content:) ๋ชจ๋””ํŒŒ์ด์–ด์˜ modalPresentationStyle์„ .fullScreen์œผ๋กœ ๊ณ ์ •ํ•œ ๊ฒƒ์œผ๋กœ, overlay(alignment:content:) ๋ชจ๋””ํŒŒ์ด์–ด๋ฅผ ๋Œ€์‹ ํ•˜์—ฌ ํ™”๋ฉด ์ „์ฒด๋ฅผ ๋ฎ๋Š” ์ปค์Šคํ…€ ๋ฐ”ํ…€์‹œํŠธ๋ฅผ ๋„์šฐ๊ธฐ์—๋Š” ๋ถ€์ ์ ˆํ•ฉ๋‹ˆ๋‹ค.

FullScreenOverlay๋Š” ํ•˜์œ„ ๋ทฐ์—์„œ ์ƒ์„ฑํ•œ ์˜ค๋ฒ„๋ ˆ์ด๋ฅผ ์ตœ์ƒ์œ„ ๋ทฐ๊ฐ€ ๋Œ€์‹  ๋„์šธ ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜์—ฌ, ์ž‘์€ ํฌ๊ธฐ์˜ ์ปดํฌ๋„ŒํŠธ ๋ทฐ์— ํ™”๋ฉด์„ ์ „์ฒด๋ฅผ ๋ฎ๋Š” ์˜ค๋ฒ„๋ ˆ์ด๋ฅผ ์†์‰ฝ๊ฒŒ ๋ถ™์ผ ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ค๋‹ˆ๋‹ค.

์‚ฌ์šฉ

ํ”„๋ ˆ์  ํ…Œ์ด์…˜ ๊ณต๊ฐ„ ์„ค์ •ํ•˜๊ธฐ

FullScreenOverlay๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋จผ์ € ์˜ค๋ฒ„๋ ˆ์ด๋ฅผ ๋„์šธ ํ”„๋ ˆ์  ํ…Œ์ด์…˜ ๊ณต๊ฐ„์„ ์„ค์ •ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ค๋ฒ„๋ ˆ์ด๊ฐ€ ๋„์›Œ์ง€๊ธธ ์›ํ•˜๋Š” ๋ทฐ(์˜ˆ: ์ตœ์ƒ์œ„ ๋ฃจํŠธ ๋ทฐ)์— fullScreenOverlayPresentationSpace(_:) ๋ชจ๋””ํŒŒ์ด์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ”„๋ ˆ์  ํ…Œ์ด์…˜ ๊ณต๊ฐ„๊ณผ ๊ทธ ์ด๋ฆ„์„ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

RootView()
    .fullScreenOverlayPresentationSpace(.named("RootView"))

ํ”„๋ ˆ์  ํ…Œ์ด์…˜ ๊ณต๊ฐ„์œผ๋กœ ์‚ฌ์šฉํ•˜๋ ค๋Š” ๋ทฐ๊ฐ€ ์ถฉ๋ถ„ํžˆ ํฌ์ง€ ์•Š์€ ๊ฒฝ์šฐ, frame(maxWidth:maxHeight:) ๋ชจ๋””ํŒŒ์ด์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ทฐ์˜ ํฌ๊ธฐ๋ฅผ ๋„“ํ˜€์ค€ ๋‹ค์Œ ๋ชจ๋””ํŒŒ์ด์–ด๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

FittingRootView()
    .frame(maxWidth: .infinity, maxHeight: .infinity)
    .fullScreenOverlayPresentationSpace(.named("FittingRootView"))

ํ”„๋ ˆ์  ํ…Œ์ด์…˜ ๊ณต๊ฐ„์€ ์—ฌ๋Ÿฌ ๊ณณ์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. NavigationView๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ, NavigationLink์˜ destination ๋ทฐ์— ๋ณ„๋„์˜ ํ”„๋ ˆ์  ํ…Œ์ด์…˜ ๊ณต๊ฐ„์„ ์„ค์ •ํ•˜๋ฉด, ํ•ด๋‹น destination ๋ทฐ ๋‚ด๋ถ€์—์„œ๋งŒ ์˜ค๋ฒ„๋ ˆ์ด๋ฅผ ๋„์šธ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

NavigationView {
    NavigationLink(
        "Detail",
        destination: {
            DetailView()
                .fullScreenOverlayPresentationSpace(.named("DetailView"))
        }
    )
}
.fullScreenOverlayPresentationSpace(.named("NavigationView"))

PresentationSpace.named(_:)๋Š” SwiftUI์˜ CoordinateSpace.named(_:)์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ AnyHashable ํƒ€์ž…์„ ์ด๋ฆ„์œผ๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ String์ด ์•„๋‹ˆ๋”๋ผ๋„ Hashable์„ ๋งŒ์กฑํ•˜๋Š” ํƒ€์ž…์ด๋ผ๋ฉด ์–ด๋–ค ๊ฒƒ์ด๋“  ์ด๋ฆ„์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

extension RootView {
    struct PresentationSpaceName: Hashable {}
}

RootView()
    .fullScreenOverlayPresentationSpace(.named(RootView.PresentationSpaceName()))

์˜ค๋ฒ„๋ ˆ์ด ๋„์šฐ๊ธฐ

ํ”„๋ ˆ์  ํ…Œ์ด์…˜ ๊ณต๊ฐ„์„ ์„ค์ •ํ–ˆ๋‹ค๋ฉด, FullScreenOverlay๋ฅผ ์‚ฌ์šฉํ•  ์ค€๋น„๊ฐ€ ๋œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

SomeView()
    .fullScreenOverlay(presentationSpace: .named("RootView")) {
        SomeOverlay()
    }

overlay(alignment:content:) ๋ชจ๋””ํŒŒ์ด์–ด์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ, content ํด๋กœ์ €์— ํ•˜๋‚˜ ์ด์ƒ์˜ ๋ทฐ๊ฐ€ ๋“ค์–ด์žˆ์„ ๊ฒฝ์šฐ ๋‚ด๋ถ€์ ์œผ๋กœ ZStack์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ทฐ๋ฅผ ์ •๋ ฌํ•ด ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. ZStack์˜ alignment ์˜ต์…˜์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ, frame(maxWidth:maxHeight:alignment:) ๋ชจ๋””ํŒŒ์ด์–ด๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

SomeView()
    .fullScreenOverlay(presentationSpace: .named("RootView")) {
        BackgroundDim()
        BottomSheet().frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
    }

์˜ˆ์ œ

์•„๋ž˜๋Š” FullScreenOverlay๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ„๋‹จํ•œ ๋ฐ”ํ…€์‹œํŠธ ํ”„๋ ˆ์  ํ…Œ์ด์…˜์„ ๊ตฌํ˜„ํ•œ ์˜ˆ์ œ์ž…๋‹ˆ๋‹ค.

https://github.com/riiid/FullScreenOverlay/blob/2b251c2d6da1fd7712ef0723e6d5b2110bbf5aeb/Sources/Previews/Previews.swift#L1-L63

https://user-images.githubusercontent.com/2215080/172043362-8e0c5d6d-712f-4773-863f-50687e961a86.mp4

์š”๊ตฌ ์‚ฌํ•ญ

  • Swift 5.1+
  • Xcode 11.0+
  • iOS 13.0+
  • Mac Catalyst 13.0+
  • macOS 10.15+
  • tvOS 13.0+
  • watchOS 6.0+

์„ค์น˜

Swift Package Manager

Package.swift ํŒŒ์ผ์˜ dependencies์— ์•„๋ž˜ ๋ผ์ธ์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

.package(url: "https://github.com/riiid/FullScreenOverlay.git", .upToNextMajor(from: "1.1.0"))

๊ทธ ๋‹ค์Œ, AttributedFont๋ฅผ ํƒ€๊ฒŸ์˜ ์˜์กด์„ฑ์œผ๋กœ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

.target(name: "MyTarget", dependencies: ["FullScreenOverlay"])

์™„์„ฑ๋œ ๋””์Šคํฌ๋ฆฝ์…˜์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

// swift-tools-version:5.1

import PackageDescription

let package = Package(
    name: "MyPackage",
    dependencies: [
        .package(url: "https://github.com/riiid/FullScreenOverlay.git", .upToNextMajor(from: "1.1.0"))
    ],
    targets: [
        .target(name: "MyTarget", dependencies: ["FullScreenOverlay"])
    ]
)

Xcode

File > Swift Packages > Add Package Dependency๋ฅผ ์„ ํƒํ•œ ๋‹ค์Œ, ์•„๋ž˜์˜ URL์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

https://github.com/riiid/FullScreenOverlay.git

์ž์„ธํ•œ ๋‚ด์šฉ์€ Adding Package Dependencies to Your App์„ ์ฐธ์กฐํ•˜์„ธ์š”.

๊ธฐ์—ฌํ•˜๊ธฐ

์ €ํฌ๋Š” ๋ชจ๋“  ์ข…๋ฅ˜์˜ ๊ธฐ์—ฌ๋ฅผ ํ™˜์˜ํ•˜๋ฉฐ, ๊ธฐ์—ฌํ•ด ์ฃผ์‹œ๋Š” ๋ถ„๋“ค์˜ ๋ชจ๋“  ์˜๊ฒฌ์„ ์กด์ค‘ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ„๋‹จํ•œ ๊ธฐ๋Šฅ ์ถ”๊ฐ€, ๋ฒ„๊ทธ ํ”ฝ์Šค, ์˜คํƒ€ ์ˆ˜์ • ๋“ฑ์ด๋ผ๋„ ์ฃผ์ €ํ•˜์ง€ ๋ง๊ณ  ์ด์Šˆ๋‚˜ PR์„ ์ƒ์„ฑํ•˜์—ฌ ์˜๊ฒฌ์„ ์ œ๊ธฐํ•ด ์ฃผ์„ธ์š”.

๋ฉ”์ธํ…Œ์ด๋„ˆ

๋„์›€์„ ์ฃผ์‹  ๋ถ„๋“ค

  • ์ด๊ฑด์„ (@hxperl): PreferenceKey๋ฅผ ์‚ฌ์šฉํ•ด ๊ตฌํ˜„๋œ ์ตœ์ดˆ ๋ฒ„์ „์—์„œ ๋ฐœ์ƒํ•˜๋˜ ์Šคํฌ๋กค๋ทฐ ์ด์Šˆ์™€, EnvironmentObject๋ฅผ ์‚ฌ์šฉํ•ด ๊ตฌํ˜„๋œ ๋‘ ๋ฒˆ์งธ ๋ฒ„์ „์—์„œ ๋ฐœ์ƒํ•˜๋˜ CPU ์‚ฌ์šฉ๋Ÿ‰ ์ด์Šˆ๋ฅผ ๋ฐœ๊ฒฌํ•ด์ฃผ์…จ์Šต๋‹ˆ๋‹ค.

๋ผ์ด์„ ์Šค

FullScreenOverlay๋Š” MIT ๋ผ์ด์„ ์Šค ํ•˜์— ๋ฐฐํฌ๋ฉ๋‹ˆ๋‹ค. ์ž์„ธํ•œ ๋‚ด์šฉ์€ LICENSE๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.

GitHub

link
Stars: 11
Last commit: 11 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

v1.1.0
11 weeks ago

Added

  • Added fullScreenOverlayPresentationSpace(_:) modifier that takes a PresentationSpace instance as a parameter.

Changed

  • Deprecated fullScreenOverlayPresentationSpace(name:) modifier that takes a String instance as a parameter.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics