├── .gitignore ├── LICENSE ├── PopupSwiftUI.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── PopupSwiftUI ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── ContentView.swift ├── Info.plist ├── Loader.swift ├── Popup.swift ├── PopupSwiftUIApp.swift ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json └── Snackbar.swift ├── README.md ├── demo-1.gif ├── demo-2.gif └── demo-3.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | 92 | .DS_Store 93 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /PopupSwiftUI.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 728D71F325CBFE8B00F52C42 /* Loader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 728D71F225CBFE8B00F52C42 /* Loader.swift */; }; 11 | 728D71F625CBFEA300F52C42 /* Snackbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 728D71F525CBFEA300F52C42 /* Snackbar.swift */; }; 12 | 728D71F925CBFEB600F52C42 /* Popup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 728D71F825CBFEB600F52C42 /* Popup.swift */; }; 13 | 72FC78D025BB3FF900BA7362 /* PopupSwiftUIApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72FC78CF25BB3FF900BA7362 /* PopupSwiftUIApp.swift */; }; 14 | 72FC78D225BB3FF900BA7362 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 72FC78D125BB3FF900BA7362 /* ContentView.swift */; }; 15 | 72FC78D425BB3FFA00BA7362 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 72FC78D325BB3FFA00BA7362 /* Assets.xcassets */; }; 16 | 72FC78D725BB3FFA00BA7362 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 72FC78D625BB3FFA00BA7362 /* Preview Assets.xcassets */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 728D71F225CBFE8B00F52C42 /* Loader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Loader.swift; sourceTree = ""; }; 21 | 728D71F525CBFEA300F52C42 /* Snackbar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Snackbar.swift; sourceTree = ""; }; 22 | 728D71F825CBFEB600F52C42 /* Popup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Popup.swift; sourceTree = ""; }; 23 | 72FC78CC25BB3FF900BA7362 /* PopupSwiftUI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PopupSwiftUI.app; sourceTree = BUILT_PRODUCTS_DIR; }; 24 | 72FC78CF25BB3FF900BA7362 /* PopupSwiftUIApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopupSwiftUIApp.swift; sourceTree = ""; }; 25 | 72FC78D125BB3FF900BA7362 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 26 | 72FC78D325BB3FFA00BA7362 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 27 | 72FC78D625BB3FFA00BA7362 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 28 | 72FC78D825BB3FFA00BA7362 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | 72FC78C925BB3FF900BA7362 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 72FC78C325BB3FF900BA7362 = { 43 | isa = PBXGroup; 44 | children = ( 45 | 72FC78CE25BB3FF900BA7362 /* PopupSwiftUI */, 46 | 72FC78CD25BB3FF900BA7362 /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 72FC78CD25BB3FF900BA7362 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 72FC78CC25BB3FF900BA7362 /* PopupSwiftUI.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 72FC78CE25BB3FF900BA7362 /* PopupSwiftUI */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 72FC78CF25BB3FF900BA7362 /* PopupSwiftUIApp.swift */, 62 | 72FC78D125BB3FF900BA7362 /* ContentView.swift */, 63 | 728D71F825CBFEB600F52C42 /* Popup.swift */, 64 | 728D71F525CBFEA300F52C42 /* Snackbar.swift */, 65 | 728D71F225CBFE8B00F52C42 /* Loader.swift */, 66 | 72FC78D325BB3FFA00BA7362 /* Assets.xcassets */, 67 | 72FC78D825BB3FFA00BA7362 /* Info.plist */, 68 | 72FC78D525BB3FFA00BA7362 /* Preview Content */, 69 | ); 70 | path = PopupSwiftUI; 71 | sourceTree = ""; 72 | }; 73 | 72FC78D525BB3FFA00BA7362 /* Preview Content */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 72FC78D625BB3FFA00BA7362 /* Preview Assets.xcassets */, 77 | ); 78 | path = "Preview Content"; 79 | sourceTree = ""; 80 | }; 81 | /* End PBXGroup section */ 82 | 83 | /* Begin PBXNativeTarget section */ 84 | 72FC78CB25BB3FF900BA7362 /* PopupSwiftUI */ = { 85 | isa = PBXNativeTarget; 86 | buildConfigurationList = 72FC78DB25BB3FFA00BA7362 /* Build configuration list for PBXNativeTarget "PopupSwiftUI" */; 87 | buildPhases = ( 88 | 72FC78C825BB3FF900BA7362 /* Sources */, 89 | 72FC78C925BB3FF900BA7362 /* Frameworks */, 90 | 72FC78CA25BB3FF900BA7362 /* Resources */, 91 | ); 92 | buildRules = ( 93 | ); 94 | dependencies = ( 95 | ); 96 | name = PopupSwiftUI; 97 | productName = PopupSwiftUI; 98 | productReference = 72FC78CC25BB3FF900BA7362 /* PopupSwiftUI.app */; 99 | productType = "com.apple.product-type.application"; 100 | }; 101 | /* End PBXNativeTarget section */ 102 | 103 | /* Begin PBXProject section */ 104 | 72FC78C425BB3FF900BA7362 /* Project object */ = { 105 | isa = PBXProject; 106 | attributes = { 107 | LastSwiftUpdateCheck = 1220; 108 | LastUpgradeCheck = 1220; 109 | TargetAttributes = { 110 | 72FC78CB25BB3FF900BA7362 = { 111 | CreatedOnToolsVersion = 12.2; 112 | }; 113 | }; 114 | }; 115 | buildConfigurationList = 72FC78C725BB3FF900BA7362 /* Build configuration list for PBXProject "PopupSwiftUI" */; 116 | compatibilityVersion = "Xcode 9.3"; 117 | developmentRegion = en; 118 | hasScannedForEncodings = 0; 119 | knownRegions = ( 120 | en, 121 | Base, 122 | ); 123 | mainGroup = 72FC78C325BB3FF900BA7362; 124 | productRefGroup = 72FC78CD25BB3FF900BA7362 /* Products */; 125 | projectDirPath = ""; 126 | projectRoot = ""; 127 | targets = ( 128 | 72FC78CB25BB3FF900BA7362 /* PopupSwiftUI */, 129 | ); 130 | }; 131 | /* End PBXProject section */ 132 | 133 | /* Begin PBXResourcesBuildPhase section */ 134 | 72FC78CA25BB3FF900BA7362 /* Resources */ = { 135 | isa = PBXResourcesBuildPhase; 136 | buildActionMask = 2147483647; 137 | files = ( 138 | 72FC78D725BB3FFA00BA7362 /* Preview Assets.xcassets in Resources */, 139 | 72FC78D425BB3FFA00BA7362 /* Assets.xcassets in Resources */, 140 | ); 141 | runOnlyForDeploymentPostprocessing = 0; 142 | }; 143 | /* End PBXResourcesBuildPhase section */ 144 | 145 | /* Begin PBXSourcesBuildPhase section */ 146 | 72FC78C825BB3FF900BA7362 /* Sources */ = { 147 | isa = PBXSourcesBuildPhase; 148 | buildActionMask = 2147483647; 149 | files = ( 150 | 72FC78D225BB3FF900BA7362 /* ContentView.swift in Sources */, 151 | 72FC78D025BB3FF900BA7362 /* PopupSwiftUIApp.swift in Sources */, 152 | 728D71F925CBFEB600F52C42 /* Popup.swift in Sources */, 153 | 728D71F625CBFEA300F52C42 /* Snackbar.swift in Sources */, 154 | 728D71F325CBFE8B00F52C42 /* Loader.swift in Sources */, 155 | ); 156 | runOnlyForDeploymentPostprocessing = 0; 157 | }; 158 | /* End PBXSourcesBuildPhase section */ 159 | 160 | /* Begin XCBuildConfiguration section */ 161 | 72FC78D925BB3FFA00BA7362 /* Debug */ = { 162 | isa = XCBuildConfiguration; 163 | buildSettings = { 164 | ALWAYS_SEARCH_USER_PATHS = NO; 165 | CLANG_ANALYZER_NONNULL = YES; 166 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 167 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 168 | CLANG_CXX_LIBRARY = "libc++"; 169 | CLANG_ENABLE_MODULES = YES; 170 | CLANG_ENABLE_OBJC_ARC = YES; 171 | CLANG_ENABLE_OBJC_WEAK = YES; 172 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 173 | CLANG_WARN_BOOL_CONVERSION = YES; 174 | CLANG_WARN_COMMA = YES; 175 | CLANG_WARN_CONSTANT_CONVERSION = YES; 176 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 177 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 178 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 179 | CLANG_WARN_EMPTY_BODY = YES; 180 | CLANG_WARN_ENUM_CONVERSION = YES; 181 | CLANG_WARN_INFINITE_RECURSION = YES; 182 | CLANG_WARN_INT_CONVERSION = YES; 183 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 184 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 185 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 186 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 187 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 188 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 189 | CLANG_WARN_STRICT_PROTOTYPES = YES; 190 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 191 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 192 | CLANG_WARN_UNREACHABLE_CODE = YES; 193 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 194 | COPY_PHASE_STRIP = NO; 195 | DEBUG_INFORMATION_FORMAT = dwarf; 196 | ENABLE_STRICT_OBJC_MSGSEND = YES; 197 | ENABLE_TESTABILITY = YES; 198 | GCC_C_LANGUAGE_STANDARD = gnu11; 199 | GCC_DYNAMIC_NO_PIC = NO; 200 | GCC_NO_COMMON_BLOCKS = YES; 201 | GCC_OPTIMIZATION_LEVEL = 0; 202 | GCC_PREPROCESSOR_DEFINITIONS = ( 203 | "DEBUG=1", 204 | "$(inherited)", 205 | ); 206 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 207 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 208 | GCC_WARN_UNDECLARED_SELECTOR = YES; 209 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 210 | GCC_WARN_UNUSED_FUNCTION = YES; 211 | GCC_WARN_UNUSED_VARIABLE = YES; 212 | IPHONEOS_DEPLOYMENT_TARGET = 14.2; 213 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 214 | MTL_FAST_MATH = YES; 215 | ONLY_ACTIVE_ARCH = YES; 216 | SDKROOT = iphoneos; 217 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 218 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 219 | }; 220 | name = Debug; 221 | }; 222 | 72FC78DA25BB3FFA00BA7362 /* Release */ = { 223 | isa = XCBuildConfiguration; 224 | buildSettings = { 225 | ALWAYS_SEARCH_USER_PATHS = NO; 226 | CLANG_ANALYZER_NONNULL = YES; 227 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 228 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 229 | CLANG_CXX_LIBRARY = "libc++"; 230 | CLANG_ENABLE_MODULES = YES; 231 | CLANG_ENABLE_OBJC_ARC = YES; 232 | CLANG_ENABLE_OBJC_WEAK = YES; 233 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 234 | CLANG_WARN_BOOL_CONVERSION = YES; 235 | CLANG_WARN_COMMA = YES; 236 | CLANG_WARN_CONSTANT_CONVERSION = YES; 237 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 238 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 239 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 240 | CLANG_WARN_EMPTY_BODY = YES; 241 | CLANG_WARN_ENUM_CONVERSION = YES; 242 | CLANG_WARN_INFINITE_RECURSION = YES; 243 | CLANG_WARN_INT_CONVERSION = YES; 244 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 245 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 246 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 247 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 248 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 249 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 250 | CLANG_WARN_STRICT_PROTOTYPES = YES; 251 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 252 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 253 | CLANG_WARN_UNREACHABLE_CODE = YES; 254 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 255 | COPY_PHASE_STRIP = NO; 256 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 257 | ENABLE_NS_ASSERTIONS = NO; 258 | ENABLE_STRICT_OBJC_MSGSEND = YES; 259 | GCC_C_LANGUAGE_STANDARD = gnu11; 260 | GCC_NO_COMMON_BLOCKS = YES; 261 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 262 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 263 | GCC_WARN_UNDECLARED_SELECTOR = YES; 264 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 265 | GCC_WARN_UNUSED_FUNCTION = YES; 266 | GCC_WARN_UNUSED_VARIABLE = YES; 267 | IPHONEOS_DEPLOYMENT_TARGET = 14.2; 268 | MTL_ENABLE_DEBUG_INFO = NO; 269 | MTL_FAST_MATH = YES; 270 | SDKROOT = iphoneos; 271 | SWIFT_COMPILATION_MODE = wholemodule; 272 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 273 | VALIDATE_PRODUCT = YES; 274 | }; 275 | name = Release; 276 | }; 277 | 72FC78DC25BB3FFA00BA7362 /* Debug */ = { 278 | isa = XCBuildConfiguration; 279 | buildSettings = { 280 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 281 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 282 | CODE_SIGN_STYLE = Automatic; 283 | DEVELOPMENT_ASSET_PATHS = "\"PopupSwiftUI/Preview Content\""; 284 | ENABLE_PREVIEWS = YES; 285 | INFOPLIST_FILE = PopupSwiftUI/Info.plist; 286 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 287 | LD_RUNPATH_SEARCH_PATHS = ( 288 | "$(inherited)", 289 | "@executable_path/Frameworks", 290 | ); 291 | PRODUCT_BUNDLE_IDENTIFIER = vadimbulavin.PopupSwiftUI; 292 | PRODUCT_NAME = "$(TARGET_NAME)"; 293 | SWIFT_VERSION = 5.0; 294 | TARGETED_DEVICE_FAMILY = "1,2"; 295 | }; 296 | name = Debug; 297 | }; 298 | 72FC78DD25BB3FFA00BA7362 /* Release */ = { 299 | isa = XCBuildConfiguration; 300 | buildSettings = { 301 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 302 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 303 | CODE_SIGN_STYLE = Automatic; 304 | DEVELOPMENT_ASSET_PATHS = "\"PopupSwiftUI/Preview Content\""; 305 | ENABLE_PREVIEWS = YES; 306 | INFOPLIST_FILE = PopupSwiftUI/Info.plist; 307 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 308 | LD_RUNPATH_SEARCH_PATHS = ( 309 | "$(inherited)", 310 | "@executable_path/Frameworks", 311 | ); 312 | PRODUCT_BUNDLE_IDENTIFIER = vadimbulavin.PopupSwiftUI; 313 | PRODUCT_NAME = "$(TARGET_NAME)"; 314 | SWIFT_VERSION = 5.0; 315 | TARGETED_DEVICE_FAMILY = "1,2"; 316 | }; 317 | name = Release; 318 | }; 319 | /* End XCBuildConfiguration section */ 320 | 321 | /* Begin XCConfigurationList section */ 322 | 72FC78C725BB3FF900BA7362 /* Build configuration list for PBXProject "PopupSwiftUI" */ = { 323 | isa = XCConfigurationList; 324 | buildConfigurations = ( 325 | 72FC78D925BB3FFA00BA7362 /* Debug */, 326 | 72FC78DA25BB3FFA00BA7362 /* Release */, 327 | ); 328 | defaultConfigurationIsVisible = 0; 329 | defaultConfigurationName = Release; 330 | }; 331 | 72FC78DB25BB3FFA00BA7362 /* Build configuration list for PBXNativeTarget "PopupSwiftUI" */ = { 332 | isa = XCConfigurationList; 333 | buildConfigurations = ( 334 | 72FC78DC25BB3FFA00BA7362 /* Debug */, 335 | 72FC78DD25BB3FFA00BA7362 /* Release */, 336 | ); 337 | defaultConfigurationIsVisible = 0; 338 | defaultConfigurationName = Release; 339 | }; 340 | /* End XCConfigurationList section */ 341 | }; 342 | rootObject = 72FC78C425BB3FF900BA7362 /* Project object */; 343 | } 344 | -------------------------------------------------------------------------------- /PopupSwiftUI.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /PopupSwiftUI.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /PopupSwiftUI/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /PopupSwiftUI/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /PopupSwiftUI/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /PopupSwiftUI/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // PopupSwiftUI 4 | // 5 | // Created by Vadim Bulavin on 22.01.2021. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct ContentView: View { 11 | @State private var isLoaderPresented = false 12 | @State private var isTopSnackbarPresented = false 13 | 14 | var body: some View { 15 | TabView { 16 | leftTab 17 | rightTab 18 | } 19 | .popup(isPresented: isTopSnackbarPresented, alignment: .top, direction: .top, content: Snackbar.init) 20 | .popup(isPresented: isLoaderPresented, alignment: .center, content: Loader.init) 21 | } 22 | 23 | private var leftTab: some View { 24 | VStack { 25 | Button( 26 | action: { self.isLoaderPresented.toggle() }, 27 | label: { Text(isLoaderPresented ? "Hide Loader" : "Show Loader") } 28 | ) 29 | Spacer() 30 | } 31 | .foregroundColor(.black) 32 | .tabItem { Label("Bottom", systemImage: "arrow.up") } 33 | } 34 | 35 | private var rightTab: some View { 36 | VStack { 37 | Button( 38 | action: { self.isTopSnackbarPresented.toggle() }, 39 | label: { Text(isTopSnackbarPresented ? "Hide Alert" : "Show Alert") } 40 | ) 41 | } 42 | .foregroundColor(.black) 43 | .tabItem { Label("Top", systemImage: "arrow.down") } 44 | } 45 | } 46 | 47 | struct ContentView_Previews: PreviewProvider { 48 | static var previews: some View { 49 | ContentView() 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /PopupSwiftUI/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | 28 | UIApplicationSupportsIndirectInputEvents 29 | 30 | UILaunchScreen 31 | 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /PopupSwiftUI/Loader.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Loader.swift 3 | // PopupSwiftUI 4 | // 5 | // Created by Vadim Bulavin on 04.02.2021. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct Loader: View { 11 | var body: some View { 12 | Group { 13 | ProgressView("Loading…") 14 | .progressViewStyle(CircularProgressViewStyle(tint: Color.black)) 15 | } 16 | .padding() 17 | .background(Color.black.opacity(0.1)) 18 | .cornerRadius(10) 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /PopupSwiftUI/Popup.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Popup.swift 3 | // PopupSwiftUI 4 | // 5 | // Created by Vadim Bulavin on 04.02.2021. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct Popup: ViewModifier { 11 | let popup: T 12 | let alignment: Alignment 13 | let direction: Direction 14 | let isPresented: Bool 15 | 16 | init(isPresented: Bool, alignment: Alignment, direction: Direction, @ViewBuilder content: () -> T) { 17 | self.isPresented = isPresented 18 | self.alignment = alignment 19 | self.direction = direction 20 | popup = content() 21 | } 22 | 23 | func body(content: Content) -> some View { 24 | content 25 | .overlay(popupContent()) 26 | } 27 | 28 | @ViewBuilder 29 | private func popupContent() -> some View { 30 | GeometryReader { geometry in 31 | if isPresented { 32 | popup 33 | .animation(.spring()) 34 | .transition(.offset(x: 0, y: direction.offset(popupFrame: geometry.frame(in: .global)))) 35 | .frame(width: geometry.size.width, height: geometry.size.height, alignment: alignment) 36 | } 37 | } 38 | } 39 | } 40 | 41 | extension Popup { 42 | enum Direction { 43 | case top, bottom 44 | 45 | func offset(popupFrame: CGRect) -> CGFloat { 46 | switch self { 47 | case .top: 48 | let aboveScreenEdge = -popupFrame.maxY 49 | return aboveScreenEdge 50 | case .bottom: 51 | let belowScreenEdge = UIScreen.main.bounds.height - popupFrame.minY 52 | return belowScreenEdge 53 | } 54 | } 55 | } 56 | } 57 | 58 | extension View { 59 | func popup( 60 | isPresented: Bool, 61 | alignment: Alignment = .center, 62 | direction: Popup.Direction = .bottom, 63 | @ViewBuilder content: () -> T 64 | ) -> some View { 65 | return modifier(Popup(isPresented: isPresented, alignment: alignment, direction: direction, content: content)) 66 | } 67 | } 68 | 69 | private extension View { 70 | func onGlobalFrameChange(_ onChange: @escaping (CGRect) -> Void) -> some View { 71 | background(GeometryReader { geometry in 72 | Color.clear.preference(key: FramePreferenceKey.self, value: geometry.frame(in: .global)) 73 | }) 74 | .onPreferenceChange(FramePreferenceKey.self, perform: onChange) 75 | } 76 | 77 | func print(_ varargs: Any...) -> Self { 78 | Swift.print(varargs) 79 | return self 80 | } 81 | } 82 | 83 | private struct FramePreferenceKey: PreferenceKey { 84 | static let defaultValue = CGRect.zero 85 | static func reduce(value: inout CGRect, nextValue: () -> CGRect) { 86 | value = nextValue() 87 | } 88 | } 89 | 90 | private extension View { 91 | @ViewBuilder func applyIf(_ condition: @autoclosure () -> Bool, apply: (Self) -> T) -> some View { 92 | if condition() { 93 | apply(self) 94 | } else { 95 | self 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /PopupSwiftUI/PopupSwiftUIApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PopupSwiftUIApp.swift 3 | // PopupSwiftUI 4 | // 5 | // Created by Vadim Bulavin on 22.01.2021. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct PopupSwiftUIApp: App { 12 | var body: some Scene { 13 | WindowGroup { 14 | ContentView() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /PopupSwiftUI/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /PopupSwiftUI/Snackbar.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Snackbar.swift 3 | // PopupSwiftUI 4 | // 5 | // Created by Vadim Bulavin on 04.02.2021. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct Snackbar: View { 11 | var body: some View { 12 | HStack() { 13 | Image(systemName: "person.fill") 14 | .resizable() 15 | .aspectRatio(contentMode: ContentMode.fill) 16 | .frame(width: 40, height: 40) 17 | 18 | VStack(alignment: .leading, spacing: 4) { 19 | Text("Archi") 20 | .foregroundColor(.black) 21 | .font(.headline) 22 | 23 | Text("Gotcha, let's meet at 9am") 24 | .font(.body) 25 | .foregroundColor(.black) 26 | } 27 | } 28 | .padding(15) 29 | .frame(maxWidth: .infinity, idealHeight: 100) 30 | .background(Color.black.opacity(0.1)) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Article related to this project 2 | 3 | - [Custom Popup in SwiftUI](https://www.vadimbulavin.com/swiftui-popup-sheet-popover/). 4 | 5 | --- 6 | 7 | # PopupSwiftUI 8 | 9 | The project demonstrates how to implement a custom popup in SwiftUI. 10 | 11 | Usage: 12 | 13 | ```swift 14 | struct Popup_Previews: PreviewProvider { 15 | static var previews: some View { 16 | Color.clear 17 | .modifier(Popup(isPresented: true, // <--- Add the popup view modifier 18 | content: { Color.yellow.frame(width: 100, height: 100) })) 19 | .previewDevice("iPod touch") 20 | } 21 | } 22 | ``` 23 | 24 | Result: 25 | 26 | | Loading Indicator | Snackbar Message | 27 | |---|---| 28 | | How to show a popup in SwiftUI | How to show a popup in SwiftUI | 29 | -------------------------------------------------------------------------------- /demo-1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/V8tr/PopupSwiftUI/b35f2c07dbe576a955df16fcfb82a73ae376c613/demo-1.gif -------------------------------------------------------------------------------- /demo-2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/V8tr/PopupSwiftUI/b35f2c07dbe576a955df16fcfb82a73ae376c613/demo-2.gif -------------------------------------------------------------------------------- /demo-3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/V8tr/PopupSwiftUI/b35f2c07dbe576a955df16fcfb82a73ae376c613/demo-3.gif --------------------------------------------------------------------------------