├── .gitignore ├── Example.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ ├── IDEWorkspaceChecks.plist │ └── swiftpm │ └── Package.resolved ├── Example ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── star.imageset │ │ ├── Contents.json │ │ └── star.pdf ├── Base.lproj │ └── LaunchScreen.storyboard ├── ContentView.swift ├── Info.plist ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json └── SceneDelegate.swift ├── LICENSE ├── Package.swift ├── README.md ├── Sources └── ConfettiView │ └── ConfettiView.swift ├── Tests ├── ConfettiViewTests │ ├── ConfettiViewTests.swift │ └── XCTestManifests.swift └── LinuxMain.swift └── docs └── assets └── example.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 | -------------------------------------------------------------------------------- /Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 52; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 5BFB99E1247EF39C00A13D3E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BFB99E0247EF39C00A13D3E /* AppDelegate.swift */; }; 11 | 5BFB99E3247EF39C00A13D3E /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BFB99E2247EF39C00A13D3E /* SceneDelegate.swift */; }; 12 | 5BFB99E5247EF39C00A13D3E /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BFB99E4247EF39C00A13D3E /* ContentView.swift */; }; 13 | 5BFB99E7247EF39D00A13D3E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5BFB99E6247EF39D00A13D3E /* Assets.xcassets */; }; 14 | 5BFB99EA247EF39D00A13D3E /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5BFB99E9247EF39D00A13D3E /* Preview Assets.xcassets */; }; 15 | 5BFB99ED247EF39D00A13D3E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5BFB99EB247EF39D00A13D3E /* LaunchScreen.storyboard */; }; 16 | 5BFB99F6247EF4C900A13D3E /* ConfettiView in Frameworks */ = {isa = PBXBuildFile; productRef = 5BFB99F5247EF4C900A13D3E /* ConfettiView */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 5BFB99DD247EF39C00A13D3E /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 5BFB99E0247EF39C00A13D3E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | 5BFB99E2247EF39C00A13D3E /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 23 | 5BFB99E4247EF39C00A13D3E /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 24 | 5BFB99E6247EF39D00A13D3E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | 5BFB99E9247EF39D00A13D3E /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 26 | 5BFB99EC247EF39D00A13D3E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 5BFB99EE247EF39D00A13D3E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | /* End PBXFileReference section */ 29 | 30 | /* Begin PBXFrameworksBuildPhase section */ 31 | 5BFB99DA247EF39C00A13D3E /* Frameworks */ = { 32 | isa = PBXFrameworksBuildPhase; 33 | buildActionMask = 2147483647; 34 | files = ( 35 | 5BFB99F6247EF4C900A13D3E /* ConfettiView in Frameworks */, 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 5BFB99D4247EF39C00A13D3E = { 43 | isa = PBXGroup; 44 | children = ( 45 | 5BFB99DF247EF39C00A13D3E /* Example */, 46 | 5BFB99DE247EF39C00A13D3E /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 5BFB99DE247EF39C00A13D3E /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 5BFB99DD247EF39C00A13D3E /* Example.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 5BFB99DF247EF39C00A13D3E /* Example */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 5BFB99E0247EF39C00A13D3E /* AppDelegate.swift */, 62 | 5BFB99E2247EF39C00A13D3E /* SceneDelegate.swift */, 63 | 5BFB99E4247EF39C00A13D3E /* ContentView.swift */, 64 | 5BFB99E6247EF39D00A13D3E /* Assets.xcassets */, 65 | 5BFB99EB247EF39D00A13D3E /* LaunchScreen.storyboard */, 66 | 5BFB99EE247EF39D00A13D3E /* Info.plist */, 67 | 5BFB99E8247EF39D00A13D3E /* Preview Content */, 68 | ); 69 | path = Example; 70 | sourceTree = ""; 71 | }; 72 | 5BFB99E8247EF39D00A13D3E /* Preview Content */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 5BFB99E9247EF39D00A13D3E /* Preview Assets.xcassets */, 76 | ); 77 | path = "Preview Content"; 78 | sourceTree = ""; 79 | }; 80 | /* End PBXGroup section */ 81 | 82 | /* Begin PBXNativeTarget section */ 83 | 5BFB99DC247EF39C00A13D3E /* Example */ = { 84 | isa = PBXNativeTarget; 85 | buildConfigurationList = 5BFB99F1247EF39D00A13D3E /* Build configuration list for PBXNativeTarget "Example" */; 86 | buildPhases = ( 87 | 5BFB99D9247EF39C00A13D3E /* Sources */, 88 | 5BFB99DA247EF39C00A13D3E /* Frameworks */, 89 | 5BFB99DB247EF39C00A13D3E /* Resources */, 90 | ); 91 | buildRules = ( 92 | ); 93 | dependencies = ( 94 | ); 95 | name = Example; 96 | packageProductDependencies = ( 97 | 5BFB99F5247EF4C900A13D3E /* ConfettiView */, 98 | ); 99 | productName = Example; 100 | productReference = 5BFB99DD247EF39C00A13D3E /* Example.app */; 101 | productType = "com.apple.product-type.application"; 102 | }; 103 | /* End PBXNativeTarget section */ 104 | 105 | /* Begin PBXProject section */ 106 | 5BFB99D5247EF39C00A13D3E /* Project object */ = { 107 | isa = PBXProject; 108 | attributes = { 109 | LastSwiftUpdateCheck = 1150; 110 | LastUpgradeCheck = 1150; 111 | ORGANIZATIONNAME = "Jeffrey Greenberg"; 112 | TargetAttributes = { 113 | 5BFB99DC247EF39C00A13D3E = { 114 | CreatedOnToolsVersion = 11.5; 115 | }; 116 | }; 117 | }; 118 | buildConfigurationList = 5BFB99D8247EF39C00A13D3E /* Build configuration list for PBXProject "Example" */; 119 | compatibilityVersion = "Xcode 9.3"; 120 | developmentRegion = en; 121 | hasScannedForEncodings = 0; 122 | knownRegions = ( 123 | en, 124 | Base, 125 | ); 126 | mainGroup = 5BFB99D4247EF39C00A13D3E; 127 | packageReferences = ( 128 | 5BFB99F4247EF4C900A13D3E /* XCRemoteSwiftPackageReference "ConfettiView" */, 129 | ); 130 | productRefGroup = 5BFB99DE247EF39C00A13D3E /* Products */; 131 | projectDirPath = ""; 132 | projectRoot = ""; 133 | targets = ( 134 | 5BFB99DC247EF39C00A13D3E /* Example */, 135 | ); 136 | }; 137 | /* End PBXProject section */ 138 | 139 | /* Begin PBXResourcesBuildPhase section */ 140 | 5BFB99DB247EF39C00A13D3E /* Resources */ = { 141 | isa = PBXResourcesBuildPhase; 142 | buildActionMask = 2147483647; 143 | files = ( 144 | 5BFB99ED247EF39D00A13D3E /* LaunchScreen.storyboard in Resources */, 145 | 5BFB99EA247EF39D00A13D3E /* Preview Assets.xcassets in Resources */, 146 | 5BFB99E7247EF39D00A13D3E /* Assets.xcassets in Resources */, 147 | ); 148 | runOnlyForDeploymentPostprocessing = 0; 149 | }; 150 | /* End PBXResourcesBuildPhase section */ 151 | 152 | /* Begin PBXSourcesBuildPhase section */ 153 | 5BFB99D9247EF39C00A13D3E /* Sources */ = { 154 | isa = PBXSourcesBuildPhase; 155 | buildActionMask = 2147483647; 156 | files = ( 157 | 5BFB99E1247EF39C00A13D3E /* AppDelegate.swift in Sources */, 158 | 5BFB99E3247EF39C00A13D3E /* SceneDelegate.swift in Sources */, 159 | 5BFB99E5247EF39C00A13D3E /* ContentView.swift in Sources */, 160 | ); 161 | runOnlyForDeploymentPostprocessing = 0; 162 | }; 163 | /* End PBXSourcesBuildPhase section */ 164 | 165 | /* Begin PBXVariantGroup section */ 166 | 5BFB99EB247EF39D00A13D3E /* LaunchScreen.storyboard */ = { 167 | isa = PBXVariantGroup; 168 | children = ( 169 | 5BFB99EC247EF39D00A13D3E /* Base */, 170 | ); 171 | name = LaunchScreen.storyboard; 172 | sourceTree = ""; 173 | }; 174 | /* End PBXVariantGroup section */ 175 | 176 | /* Begin XCBuildConfiguration section */ 177 | 5BFB99EF247EF39D00A13D3E /* Debug */ = { 178 | isa = XCBuildConfiguration; 179 | buildSettings = { 180 | ALWAYS_SEARCH_USER_PATHS = NO; 181 | CLANG_ANALYZER_NONNULL = YES; 182 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 183 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 184 | CLANG_CXX_LIBRARY = "libc++"; 185 | CLANG_ENABLE_MODULES = YES; 186 | CLANG_ENABLE_OBJC_ARC = YES; 187 | CLANG_ENABLE_OBJC_WEAK = YES; 188 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 189 | CLANG_WARN_BOOL_CONVERSION = YES; 190 | CLANG_WARN_COMMA = YES; 191 | CLANG_WARN_CONSTANT_CONVERSION = YES; 192 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 193 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 194 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 195 | CLANG_WARN_EMPTY_BODY = YES; 196 | CLANG_WARN_ENUM_CONVERSION = YES; 197 | CLANG_WARN_INFINITE_RECURSION = YES; 198 | CLANG_WARN_INT_CONVERSION = YES; 199 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 200 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 201 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 202 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 203 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 204 | CLANG_WARN_STRICT_PROTOTYPES = YES; 205 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 206 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 207 | CLANG_WARN_UNREACHABLE_CODE = YES; 208 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 209 | COPY_PHASE_STRIP = NO; 210 | DEBUG_INFORMATION_FORMAT = dwarf; 211 | ENABLE_STRICT_OBJC_MSGSEND = YES; 212 | ENABLE_TESTABILITY = YES; 213 | GCC_C_LANGUAGE_STANDARD = gnu11; 214 | GCC_DYNAMIC_NO_PIC = NO; 215 | GCC_NO_COMMON_BLOCKS = YES; 216 | GCC_OPTIMIZATION_LEVEL = 0; 217 | GCC_PREPROCESSOR_DEFINITIONS = ( 218 | "DEBUG=1", 219 | "$(inherited)", 220 | ); 221 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 222 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 223 | GCC_WARN_UNDECLARED_SELECTOR = YES; 224 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 225 | GCC_WARN_UNUSED_FUNCTION = YES; 226 | GCC_WARN_UNUSED_VARIABLE = YES; 227 | IPHONEOS_DEPLOYMENT_TARGET = 13.5; 228 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 229 | MTL_FAST_MATH = YES; 230 | ONLY_ACTIVE_ARCH = YES; 231 | SDKROOT = iphoneos; 232 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 233 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 234 | }; 235 | name = Debug; 236 | }; 237 | 5BFB99F0247EF39D00A13D3E /* Release */ = { 238 | isa = XCBuildConfiguration; 239 | buildSettings = { 240 | ALWAYS_SEARCH_USER_PATHS = NO; 241 | CLANG_ANALYZER_NONNULL = YES; 242 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 243 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 244 | CLANG_CXX_LIBRARY = "libc++"; 245 | CLANG_ENABLE_MODULES = YES; 246 | CLANG_ENABLE_OBJC_ARC = YES; 247 | CLANG_ENABLE_OBJC_WEAK = YES; 248 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 249 | CLANG_WARN_BOOL_CONVERSION = YES; 250 | CLANG_WARN_COMMA = YES; 251 | CLANG_WARN_CONSTANT_CONVERSION = YES; 252 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 253 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 254 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 255 | CLANG_WARN_EMPTY_BODY = YES; 256 | CLANG_WARN_ENUM_CONVERSION = YES; 257 | CLANG_WARN_INFINITE_RECURSION = YES; 258 | CLANG_WARN_INT_CONVERSION = YES; 259 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 260 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 261 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 262 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 263 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 264 | CLANG_WARN_STRICT_PROTOTYPES = YES; 265 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 266 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 267 | CLANG_WARN_UNREACHABLE_CODE = YES; 268 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 269 | COPY_PHASE_STRIP = NO; 270 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 271 | ENABLE_NS_ASSERTIONS = NO; 272 | ENABLE_STRICT_OBJC_MSGSEND = YES; 273 | GCC_C_LANGUAGE_STANDARD = gnu11; 274 | GCC_NO_COMMON_BLOCKS = YES; 275 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 276 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 277 | GCC_WARN_UNDECLARED_SELECTOR = YES; 278 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 279 | GCC_WARN_UNUSED_FUNCTION = YES; 280 | GCC_WARN_UNUSED_VARIABLE = YES; 281 | IPHONEOS_DEPLOYMENT_TARGET = 13.5; 282 | MTL_ENABLE_DEBUG_INFO = NO; 283 | MTL_FAST_MATH = YES; 284 | SDKROOT = iphoneos; 285 | SWIFT_COMPILATION_MODE = wholemodule; 286 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 287 | VALIDATE_PRODUCT = YES; 288 | }; 289 | name = Release; 290 | }; 291 | 5BFB99F2247EF39D00A13D3E /* Debug */ = { 292 | isa = XCBuildConfiguration; 293 | buildSettings = { 294 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 295 | CODE_SIGN_STYLE = Automatic; 296 | CURRENT_PROJECT_VERSION = 0; 297 | DEVELOPMENT_ASSET_PATHS = "\"Example/Preview Content\""; 298 | DEVELOPMENT_TEAM = 57J9ZWLLU7; 299 | ENABLE_PREVIEWS = YES; 300 | INFOPLIST_FILE = Example/Info.plist; 301 | LD_RUNPATH_SEARCH_PATHS = ( 302 | "$(inherited)", 303 | "@executable_path/Frameworks", 304 | ); 305 | MARKETING_VERSION = 1.1; 306 | PRODUCT_BUNDLE_IDENTIFIER = com.ziligy.Example; 307 | PRODUCT_NAME = "$(TARGET_NAME)"; 308 | SWIFT_VERSION = 5.0; 309 | TARGETED_DEVICE_FAMILY = "1,2"; 310 | }; 311 | name = Debug; 312 | }; 313 | 5BFB99F3247EF39D00A13D3E /* Release */ = { 314 | isa = XCBuildConfiguration; 315 | buildSettings = { 316 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 317 | CODE_SIGN_STYLE = Automatic; 318 | CURRENT_PROJECT_VERSION = 0; 319 | DEVELOPMENT_ASSET_PATHS = "\"Example/Preview Content\""; 320 | DEVELOPMENT_TEAM = 57J9ZWLLU7; 321 | ENABLE_PREVIEWS = YES; 322 | INFOPLIST_FILE = Example/Info.plist; 323 | LD_RUNPATH_SEARCH_PATHS = ( 324 | "$(inherited)", 325 | "@executable_path/Frameworks", 326 | ); 327 | MARKETING_VERSION = 1.1; 328 | PRODUCT_BUNDLE_IDENTIFIER = com.ziligy.Example; 329 | PRODUCT_NAME = "$(TARGET_NAME)"; 330 | SWIFT_VERSION = 5.0; 331 | TARGETED_DEVICE_FAMILY = "1,2"; 332 | }; 333 | name = Release; 334 | }; 335 | /* End XCBuildConfiguration section */ 336 | 337 | /* Begin XCConfigurationList section */ 338 | 5BFB99D8247EF39C00A13D3E /* Build configuration list for PBXProject "Example" */ = { 339 | isa = XCConfigurationList; 340 | buildConfigurations = ( 341 | 5BFB99EF247EF39D00A13D3E /* Debug */, 342 | 5BFB99F0247EF39D00A13D3E /* Release */, 343 | ); 344 | defaultConfigurationIsVisible = 0; 345 | defaultConfigurationName = Release; 346 | }; 347 | 5BFB99F1247EF39D00A13D3E /* Build configuration list for PBXNativeTarget "Example" */ = { 348 | isa = XCConfigurationList; 349 | buildConfigurations = ( 350 | 5BFB99F2247EF39D00A13D3E /* Debug */, 351 | 5BFB99F3247EF39D00A13D3E /* Release */, 352 | ); 353 | defaultConfigurationIsVisible = 0; 354 | defaultConfigurationName = Release; 355 | }; 356 | /* End XCConfigurationList section */ 357 | 358 | /* Begin XCRemoteSwiftPackageReference section */ 359 | 5BFB99F4247EF4C900A13D3E /* XCRemoteSwiftPackageReference "ConfettiView" */ = { 360 | isa = XCRemoteSwiftPackageReference; 361 | repositoryURL = "https://github.com/ziligy/ConfettiView"; 362 | requirement = { 363 | kind = upToNextMajorVersion; 364 | minimumVersion = 1.0.0; 365 | }; 366 | }; 367 | /* End XCRemoteSwiftPackageReference section */ 368 | 369 | /* Begin XCSwiftPackageProductDependency section */ 370 | 5BFB99F5247EF4C900A13D3E /* ConfettiView */ = { 371 | isa = XCSwiftPackageProductDependency; 372 | package = 5BFB99F4247EF4C900A13D3E /* XCRemoteSwiftPackageReference "ConfettiView" */; 373 | productName = ConfettiView; 374 | }; 375 | /* End XCSwiftPackageProductDependency section */ 376 | }; 377 | rootObject = 5BFB99D5247EF39C00A13D3E /* Project object */; 378 | } 379 | -------------------------------------------------------------------------------- /Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "ConfettiView", 6 | "repositoryURL": "https://github.com/ziligy/ConfettiView", 7 | "state": { 8 | "branch": null, 9 | "revision": "296020d5553799f0cdf77470138a8822d8e1e133", 10 | "version": "1.1.0" 11 | } 12 | } 13 | ] 14 | }, 15 | "version": 1 16 | } 17 | -------------------------------------------------------------------------------- /Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Example 4 | // 5 | // Created by Jeffrey Greenberg on 5/27/20. 6 | // Copyright © 2020 Jeffrey Greenberg. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | // MARK: UISceneSession Lifecycle 22 | 23 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 24 | // Called when a new scene session is being created. 25 | // Use this method to select a configuration to create the new scene with. 26 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 27 | } 28 | 29 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 30 | // Called when the user discards a scene session. 31 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 32 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 33 | } 34 | 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /Example/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 | -------------------------------------------------------------------------------- /Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Assets.xcassets/star.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "filename" : "star.pdf", 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | }, 21 | "properties" : { 22 | "preserves-vector-representation" : true, 23 | "template-rendering-intent" : "template" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Example/Assets.xcassets/star.imageset/star.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziligy/ConfettiView/68c16c64c0b9299ff87eb5e61c51ef81130acdc7/Example/Assets.xcassets/star.imageset/star.pdf -------------------------------------------------------------------------------- /Example/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Example/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // 4 | // Example for: 5 | // https://github.com/ziligy/ConfettiView 6 | // 7 | // Created by Jeffrey Greenberg on 5/27/20. 8 | // Copyright © 2020 Jeffrey Greenberg. All rights reserved. 9 | // 10 | 11 | import SwiftUI 12 | import ConfettiView 13 | 14 | struct ContentView: View { 15 | 16 | @State private var isShowingConfetti: Bool = false 17 | 18 | var body: some View { 19 | 20 | let confettiCelebrationView = ConfettiCelebrationView(isShowingConfetti: $isShowingConfetti, timeLimit: 4.0) 21 | 22 | let playButton = Button(action: { 23 | NotificationCenter.default.post(name: Notification.Name.playConfettiCelebration, object: Bool.self) 24 | }) { 25 | Text("Play Celebration!!") 26 | }.transition(.slowFadeIn) 27 | 28 | return ZStack { 29 | if !isShowingConfetti { playButton } 30 | confettiCelebrationView 31 | } 32 | } 33 | } 34 | 35 | /// a timed celebration 36 | struct ConfettiCelebrationView: View { 37 | 38 | @Binding var isShowingConfetti: Bool // true while confetti is displayed 39 | 40 | private var timeLimit: TimeInterval // how long to display confetti 41 | 42 | @State private var timer = Timer.publish(every: 0.0, on: .main, in: .common).autoconnect() 43 | 44 | init(isShowingConfetti: Binding, timeLimit: TimeInterval = 4.0) { 45 | self.timeLimit = timeLimit 46 | _isShowingConfetti = isShowingConfetti 47 | } 48 | 49 | var body: some View { 50 | 51 | // define confetti cell elements & fadeout transition 52 | let confetti = ConfettiView( confetti: [ 53 | .text("🎉"), 54 | .text("💪"), 55 | .shape(.circle), 56 | .shape(.triangle), 57 | // if using SF symbols, UIImage takes systemName to build 58 | .image(UIImage(systemName: "star.fill")!) 59 | ]).transition(.slowFadeOut) 60 | 61 | return ZStack { 62 | // show either confetti or nothing 63 | if isShowingConfetti { confetti } else { EmptyView() } 64 | }.onReceive(timer) { time in 65 | // timer beat is one interval then quit the confetti 66 | self.timer.upstream.connect().cancel() 67 | self.isShowingConfetti = false 68 | }.onReceive(NotificationCenter.default.publisher(for: Notification.Name.playConfettiCelebration)) { _ in 69 | // got notification so do --> reset & play 70 | self.resetTimerAndPlay() 71 | } 72 | } 73 | 74 | // reset the timer and turn on confetti 75 | private func resetTimerAndPlay() { 76 | timer = Timer.publish(every: self.timeLimit, on: .main, in: .common).autoconnect() 77 | isShowingConfetti = true 78 | } 79 | 80 | } 81 | 82 | // notification to start timer & display the confetti celebration view 83 | public extension Notification.Name { 84 | static let playConfettiCelebration = Notification.Name("play_confetti_celebration") 85 | } 86 | 87 | // fade in & out transitions for ConfettiView and Play button 88 | extension AnyTransition { 89 | static var slowFadeOut: AnyTransition { 90 | let insertion = AnyTransition.opacity 91 | let removal = AnyTransition.opacity.animation(.easeOut(duration: 1.5)) 92 | return .asymmetric(insertion: insertion, removal: removal) 93 | } 94 | 95 | static var slowFadeIn: AnyTransition { 96 | let insertion = AnyTransition.opacity.animation(.easeIn(duration: 1.5)) 97 | let removal = AnyTransition.opacity 98 | return .asymmetric(insertion: insertion, removal: removal) 99 | } 100 | } 101 | 102 | struct ContentView_Previews: PreviewProvider { 103 | static var previews: some View { 104 | ContentView() 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Example/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 | $(MARKETING_VERSION) 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | 37 | 38 | 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | UISupportedInterfaceOrientations~ipad 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationPortraitUpsideDown 56 | UIInterfaceOrientationLandscapeLeft 57 | UIInterfaceOrientationLandscapeRight 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Example/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Example/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // Example 4 | // 5 | // Created by Jeffrey Greenberg on 5/27/20. 6 | // Copyright © 2020 Jeffrey Greenberg. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import SwiftUI 11 | 12 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 18 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 19 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 20 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 21 | 22 | // Create the SwiftUI view that provides the window contents. 23 | let contentView = ContentView() 24 | 25 | // Use a UIHostingController as window root view controller. 26 | if let windowScene = scene as? UIWindowScene { 27 | let window = UIWindow(windowScene: windowScene) 28 | window.rootViewController = UIHostingController(rootView: contentView) 29 | self.window = window 30 | window.makeKeyAndVisible() 31 | } 32 | } 33 | 34 | func sceneDidDisconnect(_ scene: UIScene) { 35 | // Called as the scene is being released by the system. 36 | // This occurs shortly after the scene enters the background, or when its session is discarded. 37 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 38 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 39 | } 40 | 41 | func sceneDidBecomeActive(_ scene: UIScene) { 42 | // Called when the scene has moved from an inactive state to an active state. 43 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 44 | } 45 | 46 | func sceneWillResignActive(_ scene: UIScene) { 47 | // Called when the scene will move from an active state to an inactive state. 48 | // This may occur due to temporary interruptions (ex. an incoming phone call). 49 | } 50 | 51 | func sceneWillEnterForeground(_ scene: UIScene) { 52 | // Called as the scene transitions from the background to the foreground. 53 | // Use this method to undo the changes made on entering the background. 54 | } 55 | 56 | func sceneDidEnterBackground(_ scene: UIScene) { 57 | // Called as the scene transitions from the foreground to the background. 58 | // Use this method to save data, release shared resources, and store enough scene-specific state information 59 | // to restore the scene back to its current state. 60 | } 61 | 62 | 63 | } 64 | 65 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 jeff greenberg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.2 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "ConfettiView", 8 | platforms: [ .iOS(.v11) ], 9 | products: [ 10 | // Products define the executables and libraries produced by a package, and make them visible to other packages. 11 | .library( 12 | name: "ConfettiView", 13 | targets: ["ConfettiView"]), 14 | ], 15 | dependencies: [ 16 | // Dependencies declare other packages that this package depends on. 17 | // .package(url: /* package url */, from: "1.0.0"), 18 | ], 19 | targets: [ 20 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 21 | // Targets can depend on other targets in this package, and on products in packages which this package depends on. 22 | .target( 23 | name: "ConfettiView", 24 | dependencies: []), 25 | .testTarget( 26 | name: "ConfettiViewTests", 27 | dependencies: ["ConfettiView"]), 28 | ] 29 | ) 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ConfettiView 2 | 3 | A SwiftUI View that emits confetti with user-defined shapes, images, and text. 4 | 5 | SwiftUI ConfettiView by ziligy 6 | 7 | ## Installation 8 | *ConfettiView is available through `Swift Package Manager`* 9 | 10 | - In Xcode choose `File -> Swift Packages -> Add Package Dependency...` 11 | - Paste this Github URL (https://github.com/ziligy/ConfettiView ) into the search bar and click Next. 12 | - When repository displays, click Next. 13 | - When loaded, click Finish. 14 | 15 | 16 | ## Simple Use 17 | ```swift 18 | import SwiftUI 19 | import ConfettiView 20 | 21 | struct ContentView: View { 22 | 23 | let confettiView = ConfettiView( confetti: [ 24 | .text("🎉"), 25 | .text("💪"), 26 | .shape(.circle), 27 | .shape(.triangle), 28 | ]) 29 | 30 | var body: some View { 31 | confettiView 32 | } 33 | } 34 | 35 | ``` 36 | 37 | ## Example 38 | *see included example for:* 39 | - timed-celebration 40 | - fade out 41 | - including images 42 | 43 | ## Apps Using ConfettiView 44 | - [Murph Counter in App Store](https://apps.apple.com/us/app/murph-counter/id1518634872) 45 | 46 | ## Attributions 47 | *inspiration and code influences* 48 | - [NSHipster](https://github.com/NSHipster/ConfettiView) 49 | - [ArthurGuibert](https://github.com/ArthurGuibert/SwiftUI-Particles) 50 | 51 | -------------------------------------------------------------------------------- /Sources/ConfettiView/ConfettiView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import UIKit 3 | 4 | public struct ConfettiView: UIViewRepresentable { 5 | 6 | private var confetti = [Confetti]() 7 | 8 | public init(confetti: [Confetti]) { 9 | self.confetti = confetti 10 | } 11 | 12 | public func makeUIView(context: Context) -> UIConfettiView { 13 | return UIConfettiView() 14 | } 15 | 16 | public func updateUIView(_ uiView: UIConfettiView, context: Context) { 17 | uiView.emit(with: confetti) 18 | } 19 | } 20 | 21 | public enum Confetti { 22 | /// Confetti shapes 23 | public enum Shape { 24 | 25 | case circle 26 | case triangle 27 | case square 28 | 29 | // A custom shape. 30 | case custom(CGPath) 31 | } 32 | 33 | /// A shape with a color. 34 | case shape(Shape, UIColor=UIColor.random) 35 | 36 | /// An image with a tint color. 37 | case image(UIImage, UIColor=UIColor.random) 38 | 39 | /// A string of characters. 40 | case text(String) 41 | } 42 | 43 | 44 | /// The UIView Confetti Emitter 45 | public final class UIConfettiView: UIView { 46 | 47 | private var once: Bool = false 48 | 49 | func emit(with contents: [Confetti]) { 50 | if once { 51 | return 52 | } 53 | 54 | let layer = Layer() 55 | layer.configure(with: contents) 56 | layer.frame = self.bounds 57 | layer.needsDisplayOnBoundsChange = true 58 | layer.position = CGPoint(x: UIScreen.main.bounds.width / 2 , y: -UIScreen.main.bounds.height) 59 | layer.emitterShape = .line 60 | self.layer.addSublayer(layer) 61 | once.toggle() 62 | } 63 | 64 | } 65 | 66 | /// shapes, images, text to be emitted as confetti 67 | fileprivate final class Layer: CAEmitterLayer { 68 | func configure(with contents: [Confetti]) { 69 | emitterCells = contents.map { content in 70 | let cell = CAEmitterCell() 71 | 72 | cell.birthRate = 50.0 73 | cell.lifetime = 10.0 74 | cell.velocity = CGFloat(cell.birthRate * cell.lifetime) 75 | cell.velocityRange = cell.velocity / 2 76 | cell.emissionLongitude = .pi 77 | cell.emissionRange = .pi / 4 78 | cell.spinRange = .pi * 8 79 | cell.scaleRange = 0.25 80 | cell.scale = 1.0 - cell.scaleRange 81 | cell.contents = content.image.cgImage 82 | 83 | if let color = content.color { 84 | cell.color = color.cgColor 85 | } 86 | 87 | return cell 88 | } 89 | } 90 | } 91 | 92 | fileprivate extension Confetti.Shape { 93 | func path(in rect: CGRect) -> CGPath { 94 | switch self { 95 | case .circle: 96 | return CGPath(ellipseIn: rect, transform: nil) 97 | case .triangle: 98 | let path = CGMutablePath() 99 | path.addLines(between: [ 100 | CGPoint(x: rect.midX, y: 0), 101 | CGPoint(x: rect.maxX, y: rect.maxY), 102 | CGPoint(x: rect.minX, y: rect.maxY), 103 | CGPoint(x: rect.midX, y: 0) 104 | ]) 105 | 106 | return path 107 | case .square: 108 | return CGPath(rect: rect, transform: nil) 109 | case .custom(let path): 110 | return path 111 | } 112 | } 113 | 114 | func image(with color: UIColor) -> UIImage { 115 | let rect = CGRect(origin: .zero, size: CGSize(width: 12.0, height: 12.0)) 116 | return UIGraphicsImageRenderer(size: rect.size).image { context in 117 | context.cgContext.setFillColor(color.cgColor) 118 | context.cgContext.addPath(path(in: rect)) 119 | context.cgContext.fillPath() 120 | } 121 | } 122 | } 123 | 124 | fileprivate extension Confetti { 125 | var color: UIColor? { 126 | switch self { 127 | case let .image(_, color), 128 | let .shape(_, color): 129 | return color 130 | default: 131 | return nil 132 | } 133 | } 134 | 135 | var image: UIImage { 136 | switch self { 137 | case let .shape(shape, _): 138 | return shape.image(with: .white) 139 | case let .image(image, _): 140 | return image 141 | case let .text(string): 142 | let defaultAttributes: [NSAttributedString.Key: Any] = [ 143 | .font: UIFont.systemFont(ofSize: 16.0) 144 | ] 145 | 146 | return NSAttributedString(string: "\(string)", attributes: defaultAttributes).image() 147 | } 148 | } 149 | } 150 | 151 | fileprivate extension NSAttributedString { 152 | func image() -> UIImage { 153 | return UIGraphicsImageRenderer(size: size()).image { _ in 154 | self.draw(at: .zero) 155 | } 156 | } 157 | } 158 | 159 | fileprivate extension UIColor 160 | { 161 | public class var random: UIColor { 162 | let hue : CGFloat = CGFloat(arc4random() % 256) / 256 // use 256 to get full range from 0.0 to 1.0 163 | let saturation : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from white 164 | let brightness : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from black 165 | 166 | return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: 1) 167 | } 168 | 169 | } 170 | 171 | -------------------------------------------------------------------------------- /Tests/ConfettiViewTests/ConfettiViewTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | @testable import ConfettiView 3 | 4 | final class ConfettiViewTests: XCTestCase { 5 | func testExample() { 6 | // :-> TO DO 7 | } 8 | 9 | static var allTests = [ 10 | ("testExample", testExample), 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /Tests/ConfettiViewTests/XCTestManifests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | #if !canImport(ObjectiveC) 4 | public func allTests() -> [XCTestCaseEntry] { 5 | return [ 6 | testCase(ConfettiViewTests.allTests), 7 | ] 8 | } 9 | #endif 10 | -------------------------------------------------------------------------------- /Tests/LinuxMain.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | import ConfettiViewTests 4 | 5 | var tests = [XCTestCaseEntry]() 6 | tests += ConfettiViewTests.allTests() 7 | XCTMain(tests) 8 | -------------------------------------------------------------------------------- /docs/assets/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ziligy/ConfettiView/68c16c64c0b9299ff87eb5e61c51ef81130acdc7/docs/assets/example.gif --------------------------------------------------------------------------------