From a173f018132a48e11b5e0bbca9a3dac30ce3f0ae Mon Sep 17 00:00:00 2001 From: Jonas Gessner Date: Tue, 20 Oct 2020 23:54:49 +0200 Subject: [PATCH] A few bug fixes, add example project --- .gitignore | 29 +- .../project.pbxproj | 368 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../xcshareddata/swiftpm/Package.resolved | 25 ++ .../AccentColor.colorset/Contents.json | 11 + .../AppIcon.appiconset/Contents.json | 98 +++++ .../Assets.xcassets/Contents.json | 6 + .../ContentView.swift | 140 +++++++ .../JGProgressHUD-SwiftUI-Example/Info.plist | 50 +++ .../JGProgressHUD_SwiftUI_ExampleApp.swift | 17 + .../Preview Assets.xcassets/Contents.json | 6 + README.md | 4 +- .../JGProgressHUD_SwiftUI.swift | 28 +- 14 files changed, 789 insertions(+), 8 deletions(-) create mode 100644 Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.pbxproj create mode 100644 Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved create mode 100644 Example/JGProgressHUD-SwiftUI-Example/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 Example/JGProgressHUD-SwiftUI-Example/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Example/JGProgressHUD-SwiftUI-Example/Assets.xcassets/Contents.json create mode 100644 Example/JGProgressHUD-SwiftUI-Example/ContentView.swift create mode 100644 Example/JGProgressHUD-SwiftUI-Example/Info.plist create mode 100644 Example/JGProgressHUD-SwiftUI-Example/JGProgressHUD_SwiftUI_ExampleApp.swift create mode 100644 Example/JGProgressHUD-SwiftUI-Example/Preview Content/Preview Assets.xcassets/Contents.json diff --git a/.gitignore b/.gitignore index 5b99a56..323e766 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,31 @@ /Packages /*.xcodeproj xcuserdata/ -.swiftpm \ No newline at end of file +.swiftpm + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Gcc Patch +/*.gcno diff --git a/Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.pbxproj b/Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.pbxproj new file mode 100644 index 0000000..1521d5f --- /dev/null +++ b/Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.pbxproj @@ -0,0 +1,368 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 52; + objects = { + +/* Begin PBXBuildFile section */ + 6B602470253F7EEC00314D3B /* JGProgressHUD_SwiftUI_ExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B60246F253F7EEC00314D3B /* JGProgressHUD_SwiftUI_ExampleApp.swift */; }; + 6B602472253F7EEC00314D3B /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B602471253F7EEC00314D3B /* ContentView.swift */; }; + 6B602474253F7EEE00314D3B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6B602473253F7EEE00314D3B /* Assets.xcassets */; }; + 6B602477253F7EEE00314D3B /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6B602476253F7EEE00314D3B /* Preview Assets.xcassets */; }; + 6B60248D253F92A800314D3B /* JGProgressHUD-SwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = 6B60248C253F92A800314D3B /* JGProgressHUD-SwiftUI */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 6B60246C253F7EEC00314D3B /* JGProgressHUD-SwiftUI-Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "JGProgressHUD-SwiftUI-Example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 6B60246F253F7EEC00314D3B /* JGProgressHUD_SwiftUI_ExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JGProgressHUD_SwiftUI_ExampleApp.swift; sourceTree = ""; }; + 6B602471253F7EEC00314D3B /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + 6B602473253F7EEE00314D3B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 6B602476253F7EEE00314D3B /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 6B602478253F7EEE00314D3B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 6B602469253F7EEC00314D3B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 6B60248D253F92A800314D3B /* JGProgressHUD-SwiftUI in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 6B602463253F7EEC00314D3B = { + isa = PBXGroup; + children = ( + 6B60246E253F7EEC00314D3B /* JGProgressHUD-SwiftUI-Example */, + 6B60246D253F7EEC00314D3B /* Products */, + 6B602485253F85A600314D3B /* Frameworks */, + ); + sourceTree = ""; + }; + 6B60246D253F7EEC00314D3B /* Products */ = { + isa = PBXGroup; + children = ( + 6B60246C253F7EEC00314D3B /* JGProgressHUD-SwiftUI-Example.app */, + ); + name = Products; + sourceTree = ""; + }; + 6B60246E253F7EEC00314D3B /* JGProgressHUD-SwiftUI-Example */ = { + isa = PBXGroup; + children = ( + 6B60246F253F7EEC00314D3B /* JGProgressHUD_SwiftUI_ExampleApp.swift */, + 6B602471253F7EEC00314D3B /* ContentView.swift */, + 6B602473253F7EEE00314D3B /* Assets.xcassets */, + 6B602478253F7EEE00314D3B /* Info.plist */, + 6B602475253F7EEE00314D3B /* Preview Content */, + ); + path = "JGProgressHUD-SwiftUI-Example"; + sourceTree = ""; + }; + 6B602475253F7EEE00314D3B /* Preview Content */ = { + isa = PBXGroup; + children = ( + 6B602476253F7EEE00314D3B /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; + 6B602485253F85A600314D3B /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 6B60246B253F7EEC00314D3B /* JGProgressHUD-SwiftUI-Example */ = { + isa = PBXNativeTarget; + buildConfigurationList = 6B60247B253F7EEE00314D3B /* Build configuration list for PBXNativeTarget "JGProgressHUD-SwiftUI-Example" */; + buildPhases = ( + 6B602468253F7EEC00314D3B /* Sources */, + 6B602469253F7EEC00314D3B /* Frameworks */, + 6B60246A253F7EEC00314D3B /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "JGProgressHUD-SwiftUI-Example"; + packageProductDependencies = ( + 6B60248C253F92A800314D3B /* JGProgressHUD-SwiftUI */, + ); + productName = "JGProgressHUD-SwiftUI-Example"; + productReference = 6B60246C253F7EEC00314D3B /* JGProgressHUD-SwiftUI-Example.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 6B602464253F7EEC00314D3B /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1200; + LastUpgradeCheck = 1200; + TargetAttributes = { + 6B60246B253F7EEC00314D3B = { + CreatedOnToolsVersion = 12.0.1; + }; + }; + }; + buildConfigurationList = 6B602467253F7EEC00314D3B /* Build configuration list for PBXProject "JGProgressHUD-SwiftUI-Example" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 6B602463253F7EEC00314D3B; + packageReferences = ( + 6B60248B253F92A800314D3B /* XCRemoteSwiftPackageReference "JGProgressHUD-SwiftUI" */, + ); + productRefGroup = 6B60246D253F7EEC00314D3B /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 6B60246B253F7EEC00314D3B /* JGProgressHUD-SwiftUI-Example */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 6B60246A253F7EEC00314D3B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6B602477253F7EEE00314D3B /* Preview Assets.xcassets in Resources */, + 6B602474253F7EEE00314D3B /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 6B602468253F7EEC00314D3B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6B602472253F7EEC00314D3B /* ContentView.swift in Sources */, + 6B602470253F7EEC00314D3B /* JGProgressHUD_SwiftUI_ExampleApp.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 6B602479253F7EEE00314D3B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 6B60247A253F7EEE00314D3B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 6B60247C253F7EEE00314D3B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_ASSET_PATHS = "\"JGProgressHUD-SwiftUI-Example/Preview Content\""; + DEVELOPMENT_TEAM = ""; + ENABLE_PREVIEWS = YES; + INFOPLIST_FILE = "JGProgressHUD-SwiftUI-Example/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "com.jonasgessner.JGProgressHUD-SwiftUI-Example"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 6B60247D253F7EEE00314D3B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + DEVELOPMENT_ASSET_PATHS = "\"JGProgressHUD-SwiftUI-Example/Preview Content\""; + DEVELOPMENT_TEAM = ""; + ENABLE_PREVIEWS = YES; + INFOPLIST_FILE = "JGProgressHUD-SwiftUI-Example/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + PRODUCT_BUNDLE_IDENTIFIER = "com.jonasgessner.JGProgressHUD-SwiftUI-Example"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 6B602467253F7EEC00314D3B /* Build configuration list for PBXProject "JGProgressHUD-SwiftUI-Example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6B602479253F7EEE00314D3B /* Debug */, + 6B60247A253F7EEE00314D3B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 6B60247B253F7EEE00314D3B /* Build configuration list for PBXNativeTarget "JGProgressHUD-SwiftUI-Example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6B60247C253F7EEE00314D3B /* Debug */, + 6B60247D253F7EEE00314D3B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 6B60248B253F92A800314D3B /* XCRemoteSwiftPackageReference "JGProgressHUD-SwiftUI" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/JonasGessner/JGProgressHUD-SwiftUI.git"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 0.1.0; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 6B60248C253F92A800314D3B /* JGProgressHUD-SwiftUI */ = { + isa = XCSwiftPackageProductDependency; + package = 6B60248B253F92A800314D3B /* XCRemoteSwiftPackageReference "JGProgressHUD-SwiftUI" */; + productName = "JGProgressHUD-SwiftUI"; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 6B602464253F7EEC00314D3B /* Project object */; +} diff --git a/Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..e1c5a69 --- /dev/null +++ b/Example/JGProgressHUD-SwiftUI-Example.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,25 @@ +{ + "object": { + "pins": [ + { + "package": "JGProgressHUD", + "repositoryURL": "https://github.com/JonasGessner/JGProgressHUD.git", + "state": { + "branch": null, + "revision": "78d7cd35f1d90ff74fd82e486f2cbe4b24be8cf9", + "version": "2.2.0" + } + }, + { + "package": "JGProgressHUD-SwiftUI", + "repositoryURL": "https://github.com/JonasGessner/JGProgressHUD-SwiftUI.git", + "state": { + "branch": null, + "revision": "69898e42da98bc08076bbf158e14d2aeec4db78e", + "version": "0.1.0" + } + } + ] + }, + "version": 1 +} diff --git a/Example/JGProgressHUD-SwiftUI-Example/Assets.xcassets/AccentColor.colorset/Contents.json b/Example/JGProgressHUD-SwiftUI-Example/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/Example/JGProgressHUD-SwiftUI-Example/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Example/JGProgressHUD-SwiftUI-Example/Assets.xcassets/AppIcon.appiconset/Contents.json b/Example/JGProgressHUD-SwiftUI-Example/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..9221b9b --- /dev/null +++ b/Example/JGProgressHUD-SwiftUI-Example/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,98 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "20x20" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "29x29" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "40x40" + }, + { + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "20x20" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "29x29" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "40x40" + }, + { + "idiom" : "ipad", + "scale" : "1x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "76x76" + }, + { + "idiom" : "ipad", + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Example/JGProgressHUD-SwiftUI-Example/Assets.xcassets/Contents.json b/Example/JGProgressHUD-SwiftUI-Example/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/Example/JGProgressHUD-SwiftUI-Example/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Example/JGProgressHUD-SwiftUI-Example/ContentView.swift b/Example/JGProgressHUD-SwiftUI-Example/ContentView.swift new file mode 100644 index 0000000..c1a52ab --- /dev/null +++ b/Example/JGProgressHUD-SwiftUI-Example/ContentView.swift @@ -0,0 +1,140 @@ +// +// ContentView.swift +// JGProgressHUD-SwiftUI-Example +// +// Created by Jonas Gessner on 20.10.20. +// + +import SwiftUI +import JGProgressHUD_SwiftUI + +struct FormContent: View { + @State private var dim = false + @State var showShadow = false + @State var vibrancy = false + @Binding var blockTouches: Bool + + @EnvironmentObject private var hudCoordinator: JGProgressHUDCoordinator + + private func showIndeterminate() { + hudCoordinator.showHUD { + let hud = JGProgressHUD() + if dim { + hud.backgroundColor = UIColor(white: 0, alpha: 0.4) + } + if showShadow { + hud.shadow = JGProgressHUDShadow(color: .black, offset: .zero, radius: 4, opacity: 0.3) + } + hud.vibrancyEnabled = vibrancy + hud.textLabel.text = "Loading" + + hud.dismiss(afterDelay: 2) + return hud + } + } + + private func showSuccess() { + hudCoordinator.showHUD { + let hud = JGProgressHUD() + if dim { + hud.backgroundColor = UIColor(white: 0, alpha: 0.4) + } + if showShadow { + hud.shadow = JGProgressHUDShadow(color: .black, offset: .zero, radius: 4, opacity: 0.3) + } + hud.vibrancyEnabled = vibrancy + hud.textLabel.text = "Loading" + + hud.indicatorView = JGProgressHUDPieIndicatorView() + + // Simulate some long running task + var progress: Float = 0.0 + let timer = Timer(timeInterval: 1 / 60, repeats: true) { timer in + progress += 0.01 + progress = min(1.0, progress) + hud.progress = progress + + if progress == 1 { + timer.invalidate() + + hud.indicatorView = JGProgressHUDSuccessIndicatorView() + hud.textLabel.text = "Success" + + hud.dismiss(afterDelay: 1) + } + } + RunLoop.main.add(timer, forMode: .common) + + return hud + } + } + + private func showError() { + hudCoordinator.showHUD { + let hud = JGProgressHUD() + if dim { + hud.backgroundColor = UIColor(white: 0, alpha: 0.4) + } + if showShadow { + hud.shadow = JGProgressHUDShadow(color: .black, offset: .zero, radius: 4, opacity: 0.3) + } + hud.vibrancyEnabled = vibrancy + hud.textLabel.text = "Loading" + + hud.indicatorView = JGProgressHUDRingIndicatorView() + + // Simulate some long running task + var progress: Float = 0.0 + let timer = Timer(timeInterval: 1 / 60, repeats: true) { timer in + progress += 0.01 + hud.progress = progress + + if progress >= 0.6 { + timer.invalidate() + + hud.indicatorView = JGProgressHUDErrorIndicatorView() + hud.textLabel.text = "Error" + hud.detailTextLabel.text = "Some Info" + + hud.dismiss(afterDelay: 1) + } + } + RunLoop.main.add(timer, forMode: .common) + + return hud + } + } + + var body: some View { + Section(header: Text("Options").font(.headline)) { + Toggle("Block Touches", isOn: $blockTouches) + Toggle("Dim Background", isOn: $dim) + Toggle("Shadow", isOn: $showShadow) + Toggle("Vibrancy Effect", isOn: $vibrancy) + } + + Section { + Button("Show Indeterminate Progress", action: showIndeterminate) + Button("Show Success", action: showSuccess) + Button("Show Error", action: showError) + } + } +} + +struct ContentView: View { + @State private var blockTouches = false + + var body: some View { + JGProgressHUDPresenter(userInteractionOnHUD: blockTouches) { + Form { + FormContent(blockTouches: $blockTouches) + } + } + } +} + +struct ContentView_Previews: PreviewProvider { + static var previews: some View { + ContentView() + } +} diff --git a/Example/JGProgressHUD-SwiftUI-Example/Info.plist b/Example/JGProgressHUD-SwiftUI-Example/Info.plist new file mode 100644 index 0000000..efc211a --- /dev/null +++ b/Example/JGProgressHUD-SwiftUI-Example/Info.plist @@ -0,0 +1,50 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + + UIApplicationSupportsIndirectInputEvents + + UILaunchScreen + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/Example/JGProgressHUD-SwiftUI-Example/JGProgressHUD_SwiftUI_ExampleApp.swift b/Example/JGProgressHUD-SwiftUI-Example/JGProgressHUD_SwiftUI_ExampleApp.swift new file mode 100644 index 0000000..d1a4aec --- /dev/null +++ b/Example/JGProgressHUD-SwiftUI-Example/JGProgressHUD_SwiftUI_ExampleApp.swift @@ -0,0 +1,17 @@ +// +// JGProgressHUD_SwiftUI_ExampleApp.swift +// JGProgressHUD-SwiftUI-Example +// +// Created by Jonas Gessner on 20.10.20. +// + +import SwiftUI + +@main +struct JGProgressHUD_SwiftUI_ExampleApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} diff --git a/Example/JGProgressHUD-SwiftUI-Example/Preview Content/Preview Assets.xcassets/Contents.json b/Example/JGProgressHUD-SwiftUI-Example/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/Example/JGProgressHUD-SwiftUI-Example/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/README.md b/README.md index d33081f..29fbc86 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ You may furthermore access, modify or dismiss a HUD that is already presented by Example --------------- +Also see the [Example Project](https://github.com/JonasGessner/JGProgressHUD-SwiftUI/tree/main/Example). + ```swift import SwiftUI import JGProgressHUD_SwiftUI @@ -78,7 +80,7 @@ Detailed Documentation ---------------- Please see the [JGProgressHUD project](https://github.com/JonasGessner/JGProgressHUD) for documentation on JGProgressHUD itself. -See the doc strings in JGProgressHUD_SwiftUI.swift for more info. +See the doc strings in [JGProgressHUD_SwiftUI.swift](https://github.com/JonasGessner/JGProgressHUD-SwiftUI/blob/main/Sources/JGProgressHUD-SwiftUI/JGProgressHUD_SwiftUI.swift) for more info. License --------- diff --git a/Sources/JGProgressHUD-SwiftUI/JGProgressHUD_SwiftUI.swift b/Sources/JGProgressHUD-SwiftUI/JGProgressHUD_SwiftUI.swift index a7a0ba0..b055a24 100644 --- a/Sources/JGProgressHUD-SwiftUI/JGProgressHUD_SwiftUI.swift +++ b/Sources/JGProgressHUD-SwiftUI/JGProgressHUD_SwiftUI.swift @@ -8,6 +8,7 @@ import Foundation import SwiftUI +import Combine @_exported import JGProgressHUD /** @@ -53,11 +54,14 @@ import SwiftUI ``` */ public struct JGProgressHUDPresenter: View { - private let coordinator = JGProgressHUDCoordinator() + @State private var coordinator = JGProgressHUDCoordinator() let userInteractionOnHUD: Bool + @State private var presenting = false + private var content: () -> Content + public init(userInteractionOnHUD: Bool = false, @ViewBuilder content: @escaping () -> Content) { self.userInteractionOnHUD = userInteractionOnHUD self.content = content @@ -67,18 +71,30 @@ public struct JGProgressHUDPresenter: View { ZStack { content() - JGProgressHUDHost(constructionCoordinator: coordinator, trigger: coordinator.trigger) .allowsHitTesting(coordinator.wantsPresentation && userInteractionOnHUD) - }.environmentObject(coordinator) + JGProgressHUDHost(constructionCoordinator: coordinator, trigger: coordinator.trigger) + .edgesIgnoringSafeArea(.all) + .allowsHitTesting(presenting && userInteractionOnHUD) + } + // Optimization: Only update the presenting variable when requesting userInteractionOnHUD. This reduces the body evaluations when userInteractionOnHUD is off. + .onReceive(coordinator.wantsPresentationPublisher.filter({ _ in userInteractionOnHUD }), perform: { wantsPresentation in + presenting = wantsPresentation + }) + .environmentObject(coordinator) } } /// An instance of this class will be in the environment inside the content of a `JGProgressHUDPresenter`. Acces this instance via the environment and call the `showHUD()` method to show a HUD. To modify a presented HUD, access the `presentedHUD` property. This property is automatically set to `nil` when a presented HUD disappears. Another HUD can be shown subsequently. See `JGProgressHUDPresenter` for more info. -// Implementation note. This class is an ObservableObject so that it can become an environment object. It never actually sends any change events, because no view except JGProgressHUDHost are interested in changes on this object. By not sending change events on this object, the number of re-evaluated views may drastically shrink. JGProgressHUDHost gets notified of changes via the private trigger object. +// Implementation note: This class is an ObservableObject so that it can become an environment object. It never actually sends any change events, because no views except JGProgressHUDHost and JGProgressHUDPresenter are interested in changes on this object. By not sending change events on this object, the number of re-evaluated views may drastically shrink. It is an optimization. JGProgressHUDHost gets notified of changes via the private trigger object, while JGProgressHUDPresenter listens for changes via wantsPresentationPublisher. public final class JGProgressHUDCoordinator: ObservableObject { + fileprivate let wantsPresentationPublisher = PassthroughSubject() + fileprivate var constructor: (() -> JGProgressHUD)? { willSet { trigger.triggerChange() } + didSet { + wantsPresentationPublisher.send(wantsPresentation) + } } /** @@ -122,8 +138,8 @@ public final class JGProgressHUDCoordinator: ObservableObject { // MARK: - Private fileprivate struct JGProgressHUDHost: UIViewRepresentable { - let constructionCoordinator: JGProgressHUDCoordinator - @ObservedObject fileprivate var trigger: JGProgressHUDCoordinator.PrivateObservable + @ObservedObject var constructionCoordinator: JGProgressHUDCoordinator + @ObservedObject var trigger: JGProgressHUDCoordinator.PrivateObservable func makeUIView(context: Context) -> UIView { return UIView()