-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from adri567/preference_key_on_pricelabel
Instead of makeView to get the size of the price label, we are now us…
- Loading branch information
Showing
3 changed files
with
46 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// View+Extensions.swift | ||
// | ||
// | ||
// Created by Adrian Suthold on 18.05.22. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
extension View { | ||
|
||
/// Get the actual width of the price label | ||
/// - Parameter width: Width of the price label | ||
/// - Returns: Since we are using this method as a modifier we need to return some View, to use it on a rectangle | ||
func getTextWidth(_ width: CGFloat) -> some View { | ||
preference(key: PriceLabelPreferenceKey.self, value: width) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Sources/CheesyChart/Utilities/PriceLabelPreferenceKey.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// PriceLabelPreferenceKey.swift | ||
// | ||
// | ||
// Created by Adrian Suthold on 18.05.22. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
struct PriceLabelPreferenceKey: PreferenceKey { | ||
|
||
static var defaultValue: CGFloat = 0.0 | ||
|
||
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { | ||
value = nextValue() | ||
} | ||
|
||
} |