diff --git a/AxisTooltipExample/AxisTooltipExample.xcodeproj/project.pbxproj b/AxisTooltipExample/AxisTooltipExample.xcodeproj/project.pbxproj new file mode 100644 index 0000000..c4a1522 --- /dev/null +++ b/AxisTooltipExample/AxisTooltipExample.xcodeproj/project.pbxproj @@ -0,0 +1,496 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 55; + objects = { + +/* Begin PBXBuildFile section */ + 4B6D19CC27CAFC76007518B8 /* AxisTooltipExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6D19BC27CAFC75007518B8 /* AxisTooltipExampleApp.swift */; }; + 4B6D19CD27CAFC76007518B8 /* AxisTooltipExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6D19BC27CAFC75007518B8 /* AxisTooltipExampleApp.swift */; }; + 4B6D19CE27CAFC76007518B8 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6D19BD27CAFC75007518B8 /* ContentView.swift */; }; + 4B6D19CF27CAFC76007518B8 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B6D19BD27CAFC75007518B8 /* ContentView.swift */; }; + 4B6D19D027CAFC76007518B8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B6D19BE27CAFC76007518B8 /* Assets.xcassets */; }; + 4B6D19D127CAFC76007518B8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B6D19BE27CAFC76007518B8 /* Assets.xcassets */; }; + 4B6D19DE27CB019E007518B8 /* AxisTooltip in Frameworks */ = {isa = PBXBuildFile; productRef = 4B6D19DD27CB019E007518B8 /* AxisTooltip */; }; + 4B6D19E027CB01A3007518B8 /* AxisTooltip in Frameworks */ = {isa = PBXBuildFile; productRef = 4B6D19DF27CB01A3007518B8 /* AxisTooltip */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 4B6D19BC27CAFC75007518B8 /* AxisTooltipExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AxisTooltipExampleApp.swift; sourceTree = ""; }; + 4B6D19BD27CAFC75007518B8 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + 4B6D19BE27CAFC76007518B8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 4B6D19C327CAFC76007518B8 /* AxisTooltipExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AxisTooltipExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 4B6D19C927CAFC76007518B8 /* AxisTooltipExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AxisTooltipExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 4B6D19CB27CAFC76007518B8 /* macOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = macOS.entitlements; sourceTree = ""; }; + 4B6D19DB27CAFC8B007518B8 /* AxisTooltip */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = AxisTooltip; path = ..; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 4B6D19C027CAFC76007518B8 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 4B6D19DE27CB019E007518B8 /* AxisTooltip in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 4B6D19C627CAFC76007518B8 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 4B6D19E027CB01A3007518B8 /* AxisTooltip in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 4B6D19B627CAFC75007518B8 = { + isa = PBXGroup; + children = ( + 4B6D19DA27CAFC8B007518B8 /* Packages */, + 4B6D19BB27CAFC75007518B8 /* Shared */, + 4B6D19CA27CAFC76007518B8 /* macOS */, + 4B6D19C427CAFC76007518B8 /* Products */, + 4B6D19DC27CB019E007518B8 /* Frameworks */, + ); + sourceTree = ""; + }; + 4B6D19BB27CAFC75007518B8 /* Shared */ = { + isa = PBXGroup; + children = ( + 4B6D19BC27CAFC75007518B8 /* AxisTooltipExampleApp.swift */, + 4B6D19BD27CAFC75007518B8 /* ContentView.swift */, + 4B6D19BE27CAFC76007518B8 /* Assets.xcassets */, + ); + path = Shared; + sourceTree = ""; + }; + 4B6D19C427CAFC76007518B8 /* Products */ = { + isa = PBXGroup; + children = ( + 4B6D19C327CAFC76007518B8 /* AxisTooltipExample.app */, + 4B6D19C927CAFC76007518B8 /* AxisTooltipExample.app */, + ); + name = Products; + sourceTree = ""; + }; + 4B6D19CA27CAFC76007518B8 /* macOS */ = { + isa = PBXGroup; + children = ( + 4B6D19CB27CAFC76007518B8 /* macOS.entitlements */, + ); + path = macOS; + sourceTree = ""; + }; + 4B6D19DA27CAFC8B007518B8 /* Packages */ = { + isa = PBXGroup; + children = ( + 4B6D19DB27CAFC8B007518B8 /* AxisTooltip */, + ); + name = Packages; + sourceTree = ""; + }; + 4B6D19DC27CB019E007518B8 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 4B6D19C227CAFC76007518B8 /* AxisTooltipExample (iOS) */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4B6D19D427CAFC76007518B8 /* Build configuration list for PBXNativeTarget "AxisTooltipExample (iOS)" */; + buildPhases = ( + 4B6D19BF27CAFC76007518B8 /* Sources */, + 4B6D19C027CAFC76007518B8 /* Frameworks */, + 4B6D19C127CAFC76007518B8 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "AxisTooltipExample (iOS)"; + packageProductDependencies = ( + 4B6D19DD27CB019E007518B8 /* AxisTooltip */, + ); + productName = "AxisTooltipExample (iOS)"; + productReference = 4B6D19C327CAFC76007518B8 /* AxisTooltipExample.app */; + productType = "com.apple.product-type.application"; + }; + 4B6D19C827CAFC76007518B8 /* AxisTooltipExample (macOS) */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4B6D19D727CAFC76007518B8 /* Build configuration list for PBXNativeTarget "AxisTooltipExample (macOS)" */; + buildPhases = ( + 4B6D19C527CAFC76007518B8 /* Sources */, + 4B6D19C627CAFC76007518B8 /* Frameworks */, + 4B6D19C727CAFC76007518B8 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "AxisTooltipExample (macOS)"; + packageProductDependencies = ( + 4B6D19DF27CB01A3007518B8 /* AxisTooltip */, + ); + productName = "AxisTooltipExample (macOS)"; + productReference = 4B6D19C927CAFC76007518B8 /* AxisTooltipExample.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 4B6D19B727CAFC75007518B8 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1320; + LastUpgradeCheck = 1320; + TargetAttributes = { + 4B6D19C227CAFC76007518B8 = { + CreatedOnToolsVersion = 13.2.1; + }; + 4B6D19C827CAFC76007518B8 = { + CreatedOnToolsVersion = 13.2.1; + }; + }; + }; + buildConfigurationList = 4B6D19BA27CAFC75007518B8 /* Build configuration list for PBXProject "AxisTooltipExample" */; + compatibilityVersion = "Xcode 13.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 4B6D19B627CAFC75007518B8; + productRefGroup = 4B6D19C427CAFC76007518B8 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 4B6D19C227CAFC76007518B8 /* AxisTooltipExample (iOS) */, + 4B6D19C827CAFC76007518B8 /* AxisTooltipExample (macOS) */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 4B6D19C127CAFC76007518B8 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4B6D19D027CAFC76007518B8 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 4B6D19C727CAFC76007518B8 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4B6D19D127CAFC76007518B8 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 4B6D19BF27CAFC76007518B8 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4B6D19CE27CAFC76007518B8 /* ContentView.swift in Sources */, + 4B6D19CC27CAFC76007518B8 /* AxisTooltipExampleApp.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 4B6D19C527CAFC76007518B8 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4B6D19CF27CAFC76007518B8 /* ContentView.swift in Sources */, + 4B6D19CD27CAFC76007518B8 /* AxisTooltipExampleApp.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 4B6D19D227CAFC76007518B8 /* 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++17"; + 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; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 4B6D19D327CAFC76007518B8 /* 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++17"; + 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; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 4B6D19D527CAFC76007518B8 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = SM6445X39C; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.devstore.AxisTooltipExample; + PRODUCT_NAME = AxisTooltipExample; + SDKROOT = iphoneos; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 4B6D19D627CAFC76007518B8 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = SM6445X39C; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + IPHONEOS_DEPLOYMENT_TARGET = 14.0; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.devstore.AxisTooltipExample; + PRODUCT_NAME = AxisTooltipExample; + SDKROOT = iphoneos; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 4B6D19D827CAFC76007518B8 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = macOS/macOS.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = SM6445X39C; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 11.0; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.devstore.AxisTooltipExample; + PRODUCT_NAME = AxisTooltipExample; + SDKROOT = macosx; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 4B6D19D927CAFC76007518B8 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_ENTITLEMENTS = macOS/macOS.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = SM6445X39C; + ENABLE_HARDENED_RUNTIME = YES; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 11.0; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.devstore.AxisTooltipExample; + PRODUCT_NAME = AxisTooltipExample; + SDKROOT = macosx; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 4B6D19BA27CAFC75007518B8 /* Build configuration list for PBXProject "AxisTooltipExample" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4B6D19D227CAFC76007518B8 /* Debug */, + 4B6D19D327CAFC76007518B8 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4B6D19D427CAFC76007518B8 /* Build configuration list for PBXNativeTarget "AxisTooltipExample (iOS)" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4B6D19D527CAFC76007518B8 /* Debug */, + 4B6D19D627CAFC76007518B8 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4B6D19D727CAFC76007518B8 /* Build configuration list for PBXNativeTarget "AxisTooltipExample (macOS)" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4B6D19D827CAFC76007518B8 /* Debug */, + 4B6D19D927CAFC76007518B8 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCSwiftPackageProductDependency section */ + 4B6D19DD27CB019E007518B8 /* AxisTooltip */ = { + isa = XCSwiftPackageProductDependency; + productName = AxisTooltip; + }; + 4B6D19DF27CB01A3007518B8 /* AxisTooltip */ = { + isa = XCSwiftPackageProductDependency; + productName = AxisTooltip; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 4B6D19B727CAFC75007518B8 /* Project object */; +} diff --git a/AxisTooltipExample/AxisTooltipExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/AxisTooltipExample/AxisTooltipExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/AxisTooltipExample/AxisTooltipExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/AxisTooltipExample/AxisTooltipExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/AxisTooltipExample/AxisTooltipExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/AxisTooltipExample/AxisTooltipExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/AxisTooltipExample/Shared/Assets.xcassets/AccentColor.colorset/Contents.json b/AxisTooltipExample/Shared/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/AxisTooltipExample/Shared/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/AxisTooltipExample/Shared/Assets.xcassets/AppIcon.appiconset/Contents.json b/AxisTooltipExample/Shared/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..c136eaf --- /dev/null +++ b/AxisTooltipExample/Shared/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,148 @@ +{ + "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" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "16x16" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "32x32" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "128x128" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "256x256" + }, + { + "idiom" : "mac", + "scale" : "1x", + "size" : "512x512" + }, + { + "idiom" : "mac", + "scale" : "2x", + "size" : "512x512" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/AxisTooltipExample/Shared/Assets.xcassets/Contents.json b/AxisTooltipExample/Shared/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/AxisTooltipExample/Shared/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/AxisTooltipExample/Shared/AxisTooltipExampleApp.swift b/AxisTooltipExample/Shared/AxisTooltipExampleApp.swift new file mode 100644 index 0000000..7f31377 --- /dev/null +++ b/AxisTooltipExample/Shared/AxisTooltipExampleApp.swift @@ -0,0 +1,18 @@ +// +// AxisTooltipExampleApp.swift +// AxisTooltipExample +// +// Created by jasu on 2022/02/27. +// Copyright (c) 2022 jasu All rights reserved. +// + +import SwiftUI + +@main +struct AxisTooltipExampleApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} diff --git a/AxisTooltipExample/Shared/ContentView.swift b/AxisTooltipExample/Shared/ContentView.swift new file mode 100644 index 0000000..fe446e7 --- /dev/null +++ b/AxisTooltipExample/Shared/ContentView.swift @@ -0,0 +1,163 @@ +// +// ContentView.swift +// AxisTooltipExample +// +// Created by jasu on 2022/02/27. +// Copyright (c) 2022 jasu All rights reserved. +// + +import SwiftUI +import AxisTooltip + +struct ContentView: View { + + @State private var isPresented: Bool = true + @State private var constant: ATConstant = .init(border: ATBorderConstant(color: .pink)) + + let alignments: [Alignment] = [.center, .leading, .trailing, .top, .bottom, .topLeading, .topTrailing, .bottomLeading, .bottomTrailing] + @State private var alignmentIndex: Int = 0 + + var body: some View { + + NavigationView { + NavigationLink("Show") { + VStack { + ZStack { + Text("AxisTooltip") + .bold() + .padding() + .background(Color.pink) + .cornerRadius(10) + .onTapGesture { + isPresented.toggle() + } + .axisToolTip(isPresented: $isPresented, alignment: alignments[alignmentIndex], constant: constant, foreground: { + Label("Contrary to popular belief, Lorem Ipsum is not simply random text.", systemImage: "heart") + .padding() + .frame(width: 200) + }) + } + .background(Color.blue.opacity(0.2)) + Spacer() + VStack { + VStack(alignment: .leading, spacing: 5) { + Text("● Border").foregroundColor(Color.accentColor).opacity(0.5) + HStack { + HStack { + Text(" color :").opacity(0.5) + ColorPicker("", selection: $constant.border.color).labelsHidden() + } + Divider().frame(maxHeight: 40) + HStack { + Text(" style :").opacity(0.5) + Button { + if constant.border.style == nil { + constant.border.style = StrokeStyle(lineWidth: 2, dash: [5]) + }else { + constant.border.style = nil + } + } label: { + Text(constant.border.style == nil ? "Off" : "On") + .padding(7) + .background(constant.border.style == nil ? Color.gray.opacity(0.2) : Color.accentColor) + .cornerRadius(8) + } + .buttonStyle((PlainButtonStyle())) + } + } + HStack { + Text(" radius :").opacity(0.5) + Slider(value: $constant.border.radius, in: 0...26) + Text("\(constant.border.radius, specifier: "%.2f")") + } + HStack { + Text(" lineWidth :").opacity(0.5) + Slider(value: $constant.border.lineWidth, in: 0...26) + Text("\(constant.border.lineWidth, specifier: "%.2f")") + } + .disabled(constant.border.style != nil) + .opacity(constant.border.style != nil ? 0.5 : 1) + } + + VStack(alignment: .leading, spacing: 5) { + Text("● Arrow").foregroundColor(Color.accentColor).opacity(0.5) + HStack { + VStack { + HStack { + Text(" width : ").opacity(0.5) + Spacer() + Text("\(constant.arrow.width, specifier: "%.2f")") + } + Slider(value: $constant.arrow.width, in: 0...26) + } + Divider().frame(maxHeight: 40) + VStack { + HStack { + Text(" height : ").opacity(0.5) + Spacer() + Text("\(constant.arrow.height, specifier: "%.2f")") + } + Slider(value: $constant.arrow.height, in: 0...26) + } + } + } + VStack(alignment: .leading, spacing: 5) { + Text("● distance").foregroundColor(Color.accentColor).opacity(0.5) + HStack { + Slider(value: $constant.distance, in: 0...26) + Text("\(constant.distance, specifier: "%.2f")") + } + } + VStack(alignment: .leading, spacing: 5) { + Text("● AxisMode").foregroundColor(Color.accentColor).opacity(0.5) + HStack { + Picker("", selection: $constant.axisMode) { + Text("Top").tag(ATAxisMode.top) + Text("Bottom").tag(ATAxisMode.bottom) + Text("Leading").tag(ATAxisMode.leading) + Text("Trailing").tag(ATAxisMode.trailing) + } + .pickerStyle(SegmentedPickerStyle()) + Toggle("", isOn: $isPresented).labelsHidden() + } + } + Picker("", selection: $alignmentIndex) { + ForEach(Array(alignments.enumerated()), id:\.offset) { index, align in + Image(systemName: getAlignmentIcon(alignments[index])).tag(index) + } + } + .pickerStyle(SegmentedPickerStyle()) + } + .zIndex(-1) + } + .font(.callout) + .animation(.easeInOut, value: constant) + .animation(.easeInOut, value: alignmentIndex) + .padding() + .navigationBarTitleDisplayMode(.inline) + } + } + } + + private func getAlignmentIcon(_ alignment: Alignment) -> String { + switch alignment { + case .center: return "rectangle.center.inset.filled" + case .leading: return "rectangle.leftthird.inset.filled" + case .trailing: return "rectangle.rightthird.inset.filled" + case .top: return "rectangle.topthird.inset.filled" + case .bottom: return "rectangle.bottomthird.inset.filled" + case .topLeading: return "rectangle.inset.topleft.filled" + case .topTrailing: return "rectangle.inset.topright.filled" + case .bottomLeading: return "rectangle.inset.bottomleft.filled" + case .bottomTrailing: return "rectangle.inset.bottomright.filled" + default: + return "" + } + } +} + +struct ContentView_Previews: PreviewProvider { + static var previews: some View { + ContentView().preferredColorScheme(.dark) + } +} diff --git a/AxisTooltipExample/macOS/macOS.entitlements b/AxisTooltipExample/macOS/macOS.entitlements new file mode 100644 index 0000000..f2ef3ae --- /dev/null +++ b/AxisTooltipExample/macOS/macOS.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.files.user-selected.read-only + + + diff --git a/Markdown/Bottom.png b/Markdown/Bottom.png new file mode 100644 index 0000000..919294a Binary files /dev/null and b/Markdown/Bottom.png differ diff --git a/Markdown/Leading.png b/Markdown/Leading.png new file mode 100644 index 0000000..8cab298 Binary files /dev/null and b/Markdown/Leading.png differ diff --git a/Markdown/Top.png b/Markdown/Top.png new file mode 100644 index 0000000..1ed7d7b Binary files /dev/null and b/Markdown/Top.png differ diff --git a/Markdown/Trailing.png b/Markdown/Trailing.png new file mode 100644 index 0000000..7430a9d Binary files /dev/null and b/Markdown/Trailing.png differ diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..e3de58f --- /dev/null +++ b/Package.swift @@ -0,0 +1,32 @@ +// swift-tools-version:5.5 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "AxisTooltip", + platforms: [ + .iOS(.v14), + .macOS(.v11) + ], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "AxisTooltip", + targets: ["AxisTooltip"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "AxisTooltip", + dependencies: []), + .testTarget( + name: "AxisTooltipTests", + dependencies: ["AxisTooltip"]), + ] +) diff --git a/README.md b/README.md index d6010cd..3e66afa 100644 --- a/README.md +++ b/README.md @@ -1 +1,59 @@ -# AxisTooltip \ No newline at end of file +# **AxisTooltip for SwiftUI** +A library that displays tooltips in the desired view. Supports iOS and macOS. + +[![Platforms](https://img.shields.io/badge/Platforms-iOS%20%7C%20macOS-blue?style=flat-square)](https://developer.apple.com/macOS) +[![iOS](https://img.shields.io/badge/iOS-14.0-blue.svg)](https://developer.apple.com/iOS) +[![macOS](https://img.shields.io/badge/macOS-11.0-blue.svg)](https://developer.apple.com/macOS) +[![instagram](https://img.shields.io/badge/instagram-@dev.fabula-orange.svg?style=flat-square)](https://www.instagram.com/dev.fabula) +[![SPM](https://img.shields.io/badge/SPM-compatible-red?style=flat-square)](https://developer.apple.com/documentation/swift_packages/package/) +[![MIT](https://img.shields.io/badge/licenses-MIT-red.svg)](https://opensource.org/licenses/MIT) + +## Screenshot +|Top/Bottom|Leading/Trailing| +|:---:|:---:| +||| +||| + +https://user-images.githubusercontent.com/1617304/156180887-8f9f5ece-c4d6-4218-ac9b-275ac76fa071.mov + +## Example +[https://fabulaapp.page.link/232](https://fabulaapp.page.link/232) + +## Usages +```swift +Text("AxisTooltip") + .bold() + .padding() + .onTapGesture { + isPresented.toggle() + } + .axisToolTip(isPresented: $isPresented, constant: constant, foreground: { + Label("Contrary to popular belief, Lorem Ipsum is not simply random text.", systemImage: "heart") + .padding() + .frame(width: 200) + }) + // or - Custom background settings. + // .axisToolTip(isPresented: $isPresented, constant: constant, background: { + // Color.blue + //}, foreground: { + // Label("Contrary to popular belief, Lorem Ipsum is not simply random text.", systemImage: "heart") + // .padding() + // .frame(width: 200) + //}) +``` + +## Swift Package Manager +The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. Once you have your Swift package set up, adding AxisTooltip as a dependency is as easy as adding it to the dependencies value of your Package.swift. + +```swift +dependencies: [ + .package(url: "https://github.com/jasudev/AxisTooltip.git", .branch("main")) +] +``` + +## Contact +instagram : [@dev.fabula](https://www.instagram.com/dev.fabula) +email : [dev.fabula@gmail.com](mailto:dev.fabula@gmail.com) + +## License +AxisTooltip is available under the MIT license. See the [LICENSE](LICENSE) file for more info. diff --git a/Sources/AxisTooltip/AxisTooltip.swift b/Sources/AxisTooltip/AxisTooltip.swift new file mode 100644 index 0000000..d9dd530 --- /dev/null +++ b/Sources/AxisTooltip/AxisTooltip.swift @@ -0,0 +1,240 @@ +// +// AxisTooltip.swift +// AxisTooltip +// +// Created by jasu on 2022/02/27. +// Copyright (c) 2022 jasu All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is furnished +// to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import SwiftUI + +public struct AxisTooltip: ViewModifier where B: View, F: View { + + @Environment(\.colorScheme) private var colorScheme + @State private var parentRect: CGRect = .zero + @State private var targetRect: CGRect = .zero + @State private var tooltipRect: CGRect = .zero + + /// Indicates whether tooltips are displayed. + @Binding var isPresented: Bool + + /// Defines the axis of the target view that displays the tooltip. The default value is `.center` + public var alignment: Alignment + + /// Defines the settings for the tooltip. + public var constant: ATConstant + + /// The background view of the tooltip. + public var background: (() -> B)? = nil + + /// The content view of the tooltip. + public var foreground: () -> F + + public func body(content: Content) -> some View { + GeometryReader { parentProxy in + ZStack(alignment: alignment) { + Color.clear + .takeFrame($parentRect) + content + .takeFrame($targetRect) + .overlay( + GeometryReader { proxy in + ZStack { + if isPresented { + foreground() + .fixedSize() + .takeFrame($tooltipRect) + .background(backgroundView) + .overlay( + ZStack { + if let style = constant.border.style { + shape() + .stroke(style: style) + .fill(constant.border.color) + }else { + shape() + .stroke(constant.border.color, lineWidth: constant.border.lineWidth) + } + } + ) + .clipShape(shape()) + .offset(position()) + .animation(.none, value: isPresented) + .shadow(color: constant.shadow.color, + radius: constant.shadow.radius, + x: constant.shadow.x, + y: constant.shadow.y) + } + } + .opacity(isPresented ? 1 : 0) + .blur(radius: isPresented ? 0 : 3) + .animation(constant.animation ?? .none , value: isPresented) + } + ) + } + } + } + + //MARK: - Properties + private var backgroundView: some View { + ZStack { + if let background = background { + background() + }else { + if #available(iOS 15.0, *) { + if #available(macOS 12.0, *) { + Rectangle() + .fill(colorScheme == .dark ? Color.black.opacity(0.015) : Color.black.opacity(0.015)) + .background(.ultraThinMaterial) + } else { + Rectangle() + .fill(colorScheme == .dark ? Color.white.opacity(0.06) : Color.black.opacity(0.06)) + } + } else { + Rectangle() + .fill(colorScheme == .dark ? Color.white.opacity(0.06) : Color.black.opacity(0.06)) + } + } + } + .frame(width: tooltipRect.width + constant.arrow.height * 2, height: tooltipRect.height + constant.arrow.height * 2) + } + + private func shape() -> some Shape { + TooltipShape(axisMode: constant.axisMode, + cornerRadius: constant.border.radius, + arrowWidth: constant.arrow.width, + arrowHeight: constant.arrow.height, + arrowPosition: arrowPosition()) + } + + private func arrowPosition() -> CGFloat { + switch constant.axisMode { + case .top, .bottom: + var value = tooltipRect.width * 0.5 + if Int(targetRect.midX) < Int(tooltipRect.midX) { + value = (targetRect.origin.x - parentRect.origin.x) + targetRect.width * 0.5 + }else if Int(targetRect.midX) > Int(tooltipRect.midX) { + value = (tooltipRect.width - targetRect.width) + targetRect.width * 0.5 + } + return value + case .leading, .trailing: + var value = tooltipRect.height * 0.5 + if Int(targetRect.midY) < Int(tooltipRect.midY) { + value = (targetRect.origin.y - parentRect.origin.y) + targetRect.height * 0.5 + }else if Int(targetRect.midY) > Int(tooltipRect.midY) { + value = (tooltipRect.height - targetRect.height) + targetRect.height * 0.5 + } + return value + } + } + + private func position() -> CGSize { + switch constant.axisMode { + case .top, .bottom: + var value: CGFloat = -tooltipRect.width * 0.5 + targetRect.width * 0.5 + let target = (targetRect.origin.x - parentRect.origin.x + targetRect.width) + let padding = parentRect.width - target + let margin = (tooltipRect.width - targetRect.width) * 0.5 + + if (targetRect.origin.x - parentRect.origin.x) < margin { + value = -(targetRect.origin.x - parentRect.origin.x) + } else if padding < margin { + value = targetRect.width + padding - tooltipRect.width + } + return CGSize(width: value, + height: constant.axisMode == .bottom ? targetRect.height + constant.distance + constant.arrow.height : -(tooltipRect.height + constant.distance + constant.arrow.height)) + case .leading, .trailing: + var value: CGFloat = -tooltipRect.height * 0.5 + targetRect.height * 0.5 + let target = (targetRect.origin.y - parentRect.origin.y + targetRect.height) + let padding = parentRect.height - target + let margin = (tooltipRect.height - targetRect.height) * 0.5 + + if (targetRect.origin.y - parentRect.origin.y) < margin { + value = -(targetRect.origin.y - parentRect.origin.y) + } else if padding < margin { + value = targetRect.height + padding - tooltipRect.height + } + return CGSize(width: constant.axisMode == .trailing ? targetRect.width + constant.distance + constant.arrow.height : -(tooltipRect.width + constant.distance + constant.arrow.height), + height: value) + } + } +} + +public extension AxisTooltip where B == EmptyView, F : View { + + /// Initializes `AxisTooltip` + /// - Parameters: + /// - isPresented: Indicates whether tooltips are displayed. + /// - alignment: Defines the axis of the target view that displays the tooltip. The default value is `.center` + /// - constant: Defines the settings for the tooltip. + /// - foreground: The content view of the tooltip. + init(isPresented: Binding, + alignment: Alignment = .center, + constant: ATConstant = .init(), + @ViewBuilder foreground: @escaping () -> F) { + _isPresented = isPresented + self.alignment = alignment + self.constant = constant + self.foreground = foreground + } +} + +public extension AxisTooltip where B : View, F : View { + + /// Initializes `AxisTooltip` + /// - Parameters: + /// - isPresented: Indicates whether tooltips are displayed. + /// - alignment: Defines the axis of the target view that displays the tooltip. The default value is `.center` + /// - constant: Defines the settings for the tooltip. + /// - background: The background view of the tooltip. + /// - foreground: The content view of the tooltip. + init(isPresented: Binding, + alignment: Alignment = .center, + constant: ATConstant = .init(), + @ViewBuilder background: @escaping () -> B, + @ViewBuilder foreground: @escaping () -> F) { + _isPresented = isPresented + self.alignment = alignment + self.constant = constant + self.background = background + self.foreground = foreground + } +} + +struct AxisTooltip_Previews: PreviewProvider { + static var previews: some View { + VStack { + Text("Hello!") + .font(.largeTitle) + .padding() + .background(Color.purple) + .modifier(AxisTooltip(isPresented: .constant(true), alignment: .trailing, + constant: .init(axisMode: .bottom), + foreground: { + Text("Tooltipfwefewefefew") + .padding() + .frame(height: 200) + + })) + } + .padding() + .preferredColorScheme(.light) + } +} diff --git a/Sources/AxisTooltip/Constants/ATArrowConstant.swift b/Sources/AxisTooltip/Constants/ATArrowConstant.swift new file mode 100644 index 0000000..7b8f103 --- /dev/null +++ b/Sources/AxisTooltip/Constants/ATArrowConstant.swift @@ -0,0 +1,42 @@ +// +// ATArrowConstant.swift +// AxisTooltip +// +// Created by jasu on 2022/02/28. +// Copyright (c) 2022 jasu All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is furnished +// to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import SwiftUI + +/// The definition of arrow indication. +public struct ATArrowConstant: Equatable { + + public var width: CGFloat + public var height: CGFloat + + /// Initializes `ATArrowConstant` + /// - Parameters: + /// - width: The width of the arrow. The default value is `10`. + /// - height: The height of the arrow. The default value is `10`. + public init(width: CGFloat = 10, height: CGFloat = 10) { + self.width = width + self.height = height + } +} diff --git a/Sources/AxisTooltip/Constants/ATBorderConstant.swift b/Sources/AxisTooltip/Constants/ATBorderConstant.swift new file mode 100644 index 0000000..fcfe596 --- /dev/null +++ b/Sources/AxisTooltip/Constants/ATBorderConstant.swift @@ -0,0 +1,52 @@ +// +// ATBorderConstant.swift +// AxisTooltip +// +// Created by jasu on 2022/02/28. +// Copyright (c) 2022 jasu All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is furnished +// to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import SwiftUI + +/// The definition of a border. +public struct ATBorderConstant: Equatable { + + public var radius: CGFloat + public var lineWidth: CGFloat + public var color: Color + public var style: StrokeStyle? + + /// Initializes `ATBorderConstant` + /// - Parameters: + /// - radius: The corner radius of the rectangle. The default value is `10`. + /// - lineWidth: The width of the stroke that outlines this shape. The default value is `2`. + /// - color: The color of the line. The default value is `.white.opacity(0.1)`. + /// - style: The stroke characteristics --- such as the line's width and + /// whether the stroke is dashed --- that determine how to render this shape. The default value is `nil`. + public init(radius: CGFloat = 10, + lineWidth: CGFloat = 2, + color: Color = .white.opacity(0.1), + style: StrokeStyle? = nil) { + self.radius = radius + self.lineWidth = lineWidth + self.color = color + self.style = style + } +} diff --git a/Sources/AxisTooltip/Constants/ATConstant.swift b/Sources/AxisTooltip/Constants/ATConstant.swift new file mode 100644 index 0000000..2956674 --- /dev/null +++ b/Sources/AxisTooltip/Constants/ATConstant.swift @@ -0,0 +1,67 @@ +// +// ATConstant.swift +// AxisTooltip +// +// Created by jasu on 2022/02/27. +// Copyright (c) 2022 jasu All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is furnished +// to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import SwiftUI + +/// The position mode of the tooltip. +public enum ATAxisMode: Equatable { + case top + case bottom + case leading + case trailing +} + +/// Defines the settings for the tooltip. +public struct ATConstant: Equatable { + + public var axisMode: ATAxisMode + public var border: ATBorderConstant + public var arrow: ATArrowConstant + public var shadow: ATShadowConstant + public var distance: CGFloat + public var animation: Animation? + + /// Initializes `ATConstant` + /// - Parameters: + /// - axisMode: The position mode of the tooltip. + /// - border: The definition of a border. + /// - arrow: The definition of arrow indication. + /// - shadow: Defines the shadow of the tooltip. + /// - distance: The distance between the view and the tooltip. The default value is `8`. + /// - animation: An animation of the tooltip. The default value is `.easeInOut(duration: 0.28)`. + public init(axisMode: ATAxisMode = .bottom, + border: ATBorderConstant = .init(), + arrow: ATArrowConstant = .init(), + shadow: ATShadowConstant = .init(), + distance: CGFloat = 8, + animation: Animation? = .easeInOut(duration: 0.28)) { + self.axisMode = axisMode + self.border = border + self.arrow = arrow + self.shadow = shadow + self.distance = distance + self.animation = animation + } +} diff --git a/Sources/AxisTooltip/Constants/ATShadowConstant.swift b/Sources/AxisTooltip/Constants/ATShadowConstant.swift new file mode 100644 index 0000000..676ee21 --- /dev/null +++ b/Sources/AxisTooltip/Constants/ATShadowConstant.swift @@ -0,0 +1,51 @@ +// +// ATShadowConstant.swift +// AxisTooltip +// +// Created by jasu on 2022/02/28. +// Copyright (c) 2022 jasu All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is furnished +// to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import SwiftUI + +/// Defines the shadow of the tooltip. +public struct ATShadowConstant: Equatable { + + public var color: Color + public var radius: CGFloat + public var x: CGFloat + public var y: CGFloat + + /// Initializes `ATShadowConstant` + /// - Parameters: + /// - color: The shadow's color. The default value is `.black.opacity(0.3)`. + /// - radius: The shadow's size. The default value is `3`. + /// - x: A horizontal offset you use to position the shadow relative to the tooltip. The default value is `0`. + /// - y: A vertical offset you use to position the shadow relative to the tooltip. The default value is `0`. + public init(color: Color = .black.opacity(0.3), + radius: CGFloat = 3, + x: CGFloat = 0, + y: CGFloat = 0) { + self.color = color + self.radius = radius + self.x = x + self.y = y + } +} diff --git a/Sources/AxisTooltip/Extensions/View+Extensions.swift b/Sources/AxisTooltip/Extensions/View+Extensions.swift new file mode 100644 index 0000000..f1e3994 --- /dev/null +++ b/Sources/AxisTooltip/Extensions/View+Extensions.swift @@ -0,0 +1,51 @@ +// +// View+Extensions.swift +// AxisTooltip +// +// Created by jasu on 2022/02/17. +// Copyright (c) 2022 jasu All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is furnished +// to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import SwiftUI + +public extension View { + + func axisToolTip(isPresented: Binding, + alignment: Alignment = .center, + constant: ATConstant = .init(), + @ViewBuilder foreground: @escaping () -> F) -> some View { + self.modifier(AxisTooltip(isPresented: isPresented, + alignment: alignment, + constant: constant, + foreground: foreground)) + } + + func axisToolTip(isPresented: Binding, + alignment: Alignment = .center, + constant: ATConstant = .init(), + @ViewBuilder background: @escaping () -> B, + @ViewBuilder foreground: @escaping () -> F) -> some View { + self.modifier(AxisTooltip(isPresented: isPresented, + alignment: alignment, + constant: constant, + background: background, + foreground: foreground)) + } +} diff --git a/Sources/AxisTooltip/Shape/TooltipShape.swift b/Sources/AxisTooltip/Shape/TooltipShape.swift new file mode 100644 index 0000000..e3101ad --- /dev/null +++ b/Sources/AxisTooltip/Shape/TooltipShape.swift @@ -0,0 +1,229 @@ +// +// TooltipShape.swift +// AxisTooltip +// +// Created by jasu on 2022/02/27. +// Copyright (c) 2022 jasu All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is furnished +// to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import SwiftUI + +/// The shape of the tooltip. +struct TooltipShape: InsettableShape { + + let axisMode: ATAxisMode + let cornerRadius: CGFloat + let arrowWidth: CGFloat + let arrowHeight: CGFloat + + var arrowPosition: CGFloat + var amount: CGFloat = 0 + + var animatableData: CGFloat { + get { arrowPosition } + set { + arrowPosition = newValue + } + } + + func path(in rect: CGRect) -> Path { + switch axisMode { + case .top: return arrowBottom(rect.size) + case .bottom: return arrowTop(rect.size) + case .leading: return arrowTrailing(rect.size) + case .trailing: return arrowLeading(rect.size) + } + } + + private func arrowTop(_ size: CGSize) -> Path { + var path = Path() + + let x = limitX(size.width) + path.move(to: CGPoint(x: x - arrowWidth , y: 0)) + path.addLine(to: CGPoint(x: x , y: -arrowHeight)) + path.addLine(to: CGPoint(x: x + arrowWidth , y: 0)) + path.addArc(center: CGPoint(x: size.width - cornerRadius + amount, y: cornerRadius + amount), + radius: cornerRadius, + startAngle: Angle(degrees: -90), + endAngle: Angle(degrees: 0), + clockwise: false) + path.addArc(center: CGPoint(x: size.width - cornerRadius + amount, y: size.height - cornerRadius + amount), + radius: cornerRadius, + startAngle: Angle(degrees: 0), + endAngle: Angle(degrees: 90), + clockwise: false) + + path.addArc(center: CGPoint(x: cornerRadius + amount, y: size.height - cornerRadius + amount), + radius: cornerRadius, startAngle: Angle(degrees: 90), + endAngle: Angle(degrees: 180), + clockwise: false) + + path.addArc(center: CGPoint(x: cornerRadius + amount, y: cornerRadius + amount), + radius: cornerRadius, + startAngle: Angle(degrees: 180), + endAngle: Angle(degrees: 270), + clockwise: false) + + path.closeSubpath() + return path + } + + private func arrowBottom(_ size: CGSize) -> Path { + var path = Path() + + let x = limitX(size.width) + + path.move(to: CGPoint(x: cornerRadius , y: 0)) + path.addArc(center: CGPoint(x: size.width - cornerRadius + amount, y: cornerRadius + amount), + radius: cornerRadius, + startAngle: Angle(degrees: -90), + endAngle: Angle(degrees: 0), + clockwise: false) + path.addArc(center: CGPoint(x: size.width - cornerRadius + amount, y: size.height - cornerRadius + amount), + radius: cornerRadius, + startAngle: Angle(degrees: 0), + endAngle: Angle(degrees: 90), + clockwise: false) + path.addLine(to: CGPoint(x: x + arrowWidth , y: size.height)) + path.addLine(to: CGPoint(x: x, y: size.height + arrowHeight)) + path.addLine(to: CGPoint(x: x - arrowWidth , y: size.height)) + path.addArc(center: CGPoint(x: cornerRadius + amount, y: size.height - cornerRadius + amount), + radius: cornerRadius, startAngle: Angle(degrees: 90), + endAngle: Angle(degrees: 180), + clockwise: false) + path.addArc(center: CGPoint(x: cornerRadius + amount, y: cornerRadius + amount), + radius: cornerRadius, + startAngle: Angle(degrees: 180), + endAngle: Angle(degrees: 270), + clockwise: false) + path.closeSubpath() + return path + } + + private func arrowLeading(_ size: CGSize) -> Path { + var path = Path() + + let y = limitY(size.height) + + path.move(to: CGPoint(x: cornerRadius , y: 0)) + path.addArc(center: CGPoint(x: size.width - cornerRadius + amount, y: cornerRadius + amount), + radius: cornerRadius, + startAngle: Angle(degrees: -90), + endAngle: Angle(degrees: 0), + clockwise: false) + path.addArc(center: CGPoint(x: size.width - cornerRadius + amount, y: size.height - cornerRadius + amount), + radius: cornerRadius, + startAngle: Angle(degrees: 0), + endAngle: Angle(degrees: 90), + clockwise: false) + path.addArc(center: CGPoint(x: cornerRadius + amount, y: size.height - cornerRadius + amount), + radius: cornerRadius, startAngle: Angle(degrees: 90), + endAngle: Angle(degrees: 180), + clockwise: false) + path.addLine(to: CGPoint(x: 0 , y: y + arrowWidth)) + path.addLine(to: CGPoint(x: 0 - arrowHeight, y: y)) + path.addLine(to: CGPoint(x: 0 , y: y - arrowWidth)) + path.addArc(center: CGPoint(x: cornerRadius + amount, y: cornerRadius + amount), + radius: cornerRadius, + startAngle: Angle(degrees: 180), + endAngle: Angle(degrees: 270), + clockwise: false) + path.closeSubpath() + return path + } + + private func arrowTrailing(_ size: CGSize) -> Path { + var path = Path() + + let y = limitY(size.height) + + path.move(to: CGPoint(x: cornerRadius , y: 0)) + path.addArc(center: CGPoint(x: size.width - cornerRadius + amount, y: cornerRadius + amount), + radius: cornerRadius, + startAngle: Angle(degrees: -90), + endAngle: Angle(degrees: 0), + clockwise: false) + path.addLine(to: CGPoint(x: size.width , y: y - arrowWidth)) + path.addLine(to: CGPoint(x: size.width + arrowHeight, y: y)) + path.addLine(to: CGPoint(x: size.width , y: y + arrowWidth)) + path.addArc(center: CGPoint(x: size.width - cornerRadius + amount, y: size.height - cornerRadius + amount), + radius: cornerRadius, + startAngle: Angle(degrees: 0), + endAngle: Angle(degrees: 90), + clockwise: false) + path.addArc(center: CGPoint(x: cornerRadius + amount, y: size.height - cornerRadius + amount), + radius: cornerRadius, startAngle: Angle(degrees: 90), + endAngle: Angle(degrees: 180), + clockwise: false) + path.addArc(center: CGPoint(x: cornerRadius + amount, y: cornerRadius + amount), + radius: cornerRadius, + startAngle: Angle(degrees: 180), + endAngle: Angle(degrees: 270), + clockwise: false) + path.closeSubpath() + return path + } + + func inset(by amount: CGFloat) -> some InsettableShape { + var shape = self + shape.amount += amount + return shape + } + + private func limitX(_ w: CGFloat) -> CGFloat { + var x = arrowPosition + let cornerArrowWidth = cornerRadius + arrowWidth + if arrowPosition >= (w - cornerArrowWidth) { + x = w - cornerArrowWidth + }else if arrowPosition <= cornerArrowWidth { + x = cornerArrowWidth + } + return x + } + + private func limitY(_ h: CGFloat) -> CGFloat { + var y = arrowPosition + let cornerArrowWidth = cornerRadius + arrowWidth + if arrowPosition >= (h - cornerArrowWidth) { + y = h - cornerArrowWidth + }else if arrowPosition <= cornerArrowWidth { + y = cornerArrowWidth + } + return y + } + +} + +struct TooltipShape_Previews: PreviewProvider { + static var previews: some View { + VStack { + TooltipShape(axisMode: .leading, cornerRadius: 30, arrowWidth: 20, arrowHeight: 20, arrowPosition: 120) + .stroke() + .font(.callout) + .padding() + .frame(width: 200) + Spacer() + TooltipShape(axisMode: .trailing, cornerRadius: 60, arrowWidth: 20, arrowHeight: 20, arrowPosition: 0) + .stroke() + .fill(Color.blue) + .frame(width: 260, height: 260) + } + } +} diff --git a/Sources/AxisTooltip/Utils/FrameModifier.swift b/Sources/AxisTooltip/Utils/FrameModifier.swift new file mode 100644 index 0000000..7941664 --- /dev/null +++ b/Sources/AxisTooltip/Utils/FrameModifier.swift @@ -0,0 +1,61 @@ +// +// FrameModifier.swift +// AxisTooltip +// +// Created by jasu on 2022/02/27. +// Copyright (c) 2022 jasu All rights reserved. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is furnished +// to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +import SwiftUI + +struct FrameModifier: ViewModifier { + + @Binding var rect: CGRect + + init(_ rect: Binding) { + _rect = rect + } + + func body(content: Content) -> some View { + content + .background( + GeometryReader { proxy in + Color.clear.preference(key: FramePreferenceKey.self, value: proxy.frame(in: .global)) + } + ) + .onPreferenceChange(FramePreferenceKey.self) { preference in + self.rect = preference + } + } +} + +extension View { + func takeFrame(_ rect: Binding) -> some View { + self.modifier(FrameModifier(rect)) + } +} + +struct FramePreferenceKey: PreferenceKey { + typealias V = CGRect + static var defaultValue: V = .zero + static func reduce(value: inout V, nextValue: () -> V) { + value = nextValue() + } +} diff --git a/Tests/AxisTooltipTests/AxisTooltipTests.swift b/Tests/AxisTooltipTests/AxisTooltipTests.swift new file mode 100644 index 0000000..9964b43 --- /dev/null +++ b/Tests/AxisTooltipTests/AxisTooltipTests.swift @@ -0,0 +1,11 @@ +import XCTest +@testable import AxisTooltip + +final class AxisTooltipTests: XCTestCase { + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct + // results. + XCTAssertEqual(AxisTooltip().text, "Hello, World!") + } +}