ํ์คํฌ๋ฆฐ ํฌ๊ธฐ๊ฐ ์๋ ๋ทฐ์์ ํ์คํฌ๋ฆฐ 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://user-images.githubusercontent.com/2215080/172043362-8e0c5d6d-712f-4773-863f-50687e961a86.mp4
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"])
]
)
File > Swift Packages > Add Package Dependency๋ฅผ ์ ํํ ๋ค์, ์๋์ URL์ ์ ๋ ฅํฉ๋๋ค.
https://github.com/riiid/FullScreenOverlay.git
์์ธํ ๋ด์ฉ์ Adding Package Dependencies to Your App์ ์ฐธ์กฐํ์ธ์.
์ ํฌ๋ ๋ชจ๋ ์ข ๋ฅ์ ๊ธฐ์ฌ๋ฅผ ํ์ํ๋ฉฐ, ๊ธฐ์ฌํด ์ฃผ์๋ ๋ถ๋ค์ ๋ชจ๋ ์๊ฒฌ์ ์กด์คํฉ๋๋ค. ๊ฐ๋จํ ๊ธฐ๋ฅ ์ถ๊ฐ, ๋ฒ๊ทธ ํฝ์ค, ์คํ ์์ ๋ฑ์ด๋ผ๋ ์ฃผ์ ํ์ง ๋ง๊ณ ์ด์๋ PR์ ์์ฑํ์ฌ ์๊ฒฌ์ ์ ๊ธฐํด ์ฃผ์ธ์.
PreferenceKey
๋ฅผ ์ฌ์ฉํด ๊ตฌํ๋ ์ต์ด ๋ฒ์ ์์ ๋ฐ์ํ๋ ์คํฌ๋กค๋ทฐ ์ด์์, EnvironmentObject
๋ฅผ ์ฌ์ฉํด ๊ตฌํ๋ ๋ ๋ฒ์งธ ๋ฒ์ ์์ ๋ฐ์ํ๋ CPU ์ฌ์ฉ๋ ์ด์๋ฅผ ๋ฐ๊ฒฌํด์ฃผ์
จ์ต๋๋ค.FullScreenOverlay๋ MIT ๋ผ์ด์ ์ค ํ์ ๋ฐฐํฌ๋ฉ๋๋ค. ์์ธํ ๋ด์ฉ์ LICENSE๋ฅผ ์ฐธ์กฐํ์ธ์.
link |
Stars: 18 |
Last commit: 1 year ago |
fullScreenOverlayPresentationSpace(_:)
modifier that takes a PresentationSpace
instance as a parameter.fullScreenOverlayPresentationSpace(name:)
modifier that takes a String
instance as a parameter.Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics