From d4420f6b3124c3df4fd01e135eb598a5fe5074bb Mon Sep 17 00:00:00 2001 From: Badarinath Venkatnarayansetty Date: Thu, 26 Aug 2021 11:44:04 -0700 Subject: [PATCH] Providing option for custom spacing (#87) Co-authored-by: Badarinath Venkatnarayansetty --- Example/StepperView/ExampleView3.swift | 1 + README.md | 9 ++++++--- .../Extension/EnvironmentValues+Extension.swift | 13 +++++++++++++ Sources/StepperView/Extension/View+Extensions.swift | 5 +++++ .../Views/StepIndicatorVerticalView.swift | 5 ++++- 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Example/StepperView/ExampleView3.swift b/Example/StepperView/ExampleView3.swift index 3274595..1d57b5a 100644 --- a/Example/StepperView/ExampleView3.swift +++ b/Example/StepperView/ExampleView3.swift @@ -38,6 +38,7 @@ struct ExampleView3:View { .stepIndicatorMode(StepperMode.vertical) .indicators(indicationTypes) .lineOptions(StepperLineOptions.custom(1, Colors.blue(.teal).rawValue)) + .stepperEdgeInsets(EdgeInsets(top: 10, leading: 5, bottom: 10, trailing: 10)) // for custom leading , trailing , top and bottom spacing } }.padding(.vertical, 50) } diff --git a/README.md b/README.md index db47fae..b7bb18a 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ StepperView is available through [CocoaPods](https://cocoapods.org). To install it, simply add the following line to your Podfile. ```ruby -pod 'StepperView','~> 1.6.6' +pod 'StepperView','~> 1.6.7' ``` ## Carthage @@ -74,7 +74,7 @@ pod 'StepperView','~> 1.6.6' [Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate StepperView into your Xcode project using Carthage, specify it in your Cartfile: ```ruby -github "badrinathvm/stepperView" == 1.6.6 +github "badrinathvm/stepperView" == 1.6.7 ``` ## Swift Package Manager @@ -83,7 +83,7 @@ StepperView is available through [Swift Package Manager](https://swift.org/packa ```ruby dependencies: [ - .package(url: "https://github.com/badrinathvm/StepperView.git", from: "1.6.6") + .package(url: "https://github.com/badrinathvm/StepperView.git", from: "1.6.7") ] ``` @@ -172,6 +172,9 @@ dependencies: [ .pitStopLineOptions(_ options: [StepperLineOptions]) 1. line customization `color` , `width` , `corner radius` + +.stepperEdgeInsets(_ value: EdgeInsets) + 1. Provides custiom `leading`, `trailing`, `top` & `bottom` spacing. ``` ## Usage diff --git a/Sources/StepperView/Extension/EnvironmentValues+Extension.swift b/Sources/StepperView/Extension/EnvironmentValues+Extension.swift index 365e2f0..e371883 100644 --- a/Sources/StepperView/Extension/EnvironmentValues+Extension.swift +++ b/Sources/StepperView/Extension/EnvironmentValues+Extension.swift @@ -82,6 +82,12 @@ extension EnvironmentValues { get { self[StepLifeCycleKey.self] } set { self[StepLifeCycleKey.self] = newValue } } + + /// property wrapper for `StepperEdgeInsetsKey` + var stepperEdgeInsets: EdgeInsets { + get { self[StepperEdgeInsetsKey.self] } + set { self[StepperEdgeInsetsKey.self] = newValue } + } } /// Environment Key for Steps @@ -167,3 +173,10 @@ struct StepLifeCycleKey: EnvironmentKey { /// provide a default value for custom dependency static var defaultValue:[StepLifeCycle] = [] } + +/// Environment Key for pit stop line options. +@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) +struct StepperEdgeInsetsKey: EnvironmentKey { + /// provide a default value for custom dependency + static var defaultValue: EdgeInsets = EdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10) +} diff --git a/Sources/StepperView/Extension/View+Extensions.swift b/Sources/StepperView/Extension/View+Extensions.swift index f7a6bbc..3157ceb 100644 --- a/Sources/StepperView/Extension/View+Extensions.swift +++ b/Sources/StepperView/Extension/View+Extensions.swift @@ -156,6 +156,11 @@ public extension View { self.environment(\EnvironmentValues.autoSpacing, value) } + /// Configures edgeInsets to environment value + func stepperEdgeInsets(_ value: EdgeInsets) -> some View { + self.environment(\EnvironmentValues.stepperEdgeInsets, value) + } + /// Configures line options to environment value func lineOptions(_ options: StepperLineOptions) -> some View { self.environment(\EnvironmentValues.lineOptions, options) diff --git a/Sources/StepperView/Views/StepIndicatorVerticalView.swift b/Sources/StepperView/Views/StepIndicatorVerticalView.swift index d7f051e..30fe2cc 100644 --- a/Sources/StepperView/Views/StepIndicatorVerticalView.swift +++ b/Sources/StepperView/Views/StepIndicatorVerticalView.swift @@ -33,6 +33,9 @@ struct StepIndicatorVerticalView: View where Cell:View { /// environment variable to access autospacing @Environment(\.autoSpacing) var autoSpacing + /// environment variable for edge Insets + @Environment(\.stepperEdgeInsets) var stepperEdgeInsets + /// environment variable to access steplife cycles @Environment(\.stepLifeCycle) var stepLifeCycle @@ -128,7 +131,7 @@ struct StepIndicatorVerticalView: View where Cell:View { self.dynamicSpace = Array($0.values).max() ?? 0.0 //print("Auto Spacing:: \(self.dynamicSpace)") } - }.padding() + }.padding(stepperEdgeInsets) } }