-
-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chocoford
authored
Jun 26, 2023
1 parent
8a378a8
commit 3f1d7f2
Showing
2 changed files
with
39 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// ViewExtension.swift | ||
// | ||
// | ||
// Created by Chocoford on 2023/6/16. | ||
// | ||
|
||
import SwiftUI | ||
|
||
enum SafeAreaRegionsCompatible { | ||
case all | ||
case container | ||
case keyboard | ||
|
||
@available(iOS 14.0, macOS 11.0, macCatalyst 14.0, *) | ||
var safeAreaRegions: SafeAreaRegions { | ||
switch self { | ||
case .all: | ||
return .all | ||
case .container: | ||
return .container | ||
case .keyboard: | ||
return .keyboard | ||
} | ||
} | ||
} | ||
|
||
internal extension View { | ||
@ViewBuilder | ||
func ignoresSafeAreaCompatible(_ regions: SafeAreaRegionsCompatible = .all, | ||
edges: Edge.Set = .all) -> some View { | ||
if #available(iOS 14.0, macOS 11.0, *) { | ||
ignoresSafeArea(regions.safeAreaRegions, edges: edges) | ||
} else { | ||
edgesIgnoringSafeArea(edges) | ||
} | ||
} | ||
} |