Skip to content

Commit cf7c6ee

Browse files
committedJul 16, 2020
Update project structure
1 parent d9beca1 commit cf7c6ee

27 files changed

+732
-371
lines changed
 

‎DynamicColor.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Pod::Spec.new do |s|
2020
s.tvos.framework = 'UIKit'
2121
s.watchos.framework = 'UIKit'
2222

23-
s.source_files = 'Sources/*.swift'
23+
s.source_files = 'Sources/**/*.swift'
2424
s.requires_arc = true
2525
end

‎Examples/DynamicColor/DynamicColor.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
// DynamicColor.h
33
// DynamicColor
44
//
5-
// Created by Yannick LORIOT on 12/06/15.
6-
// Copyright (c) 2015 Yannick LORIOT. All rights reserved.
5+
// Created by Yannick Loriot on 16/07/2020.
6+
// Copyright © 2020 Yannick LORIOT. All rights reserved.
77
//
88

9-
#import <UIKit/UIKit.h>
9+
#import <Foundation/Foundation.h>
1010

1111
//! Project version number for DynamicColor.
1212
FOUNDATION_EXPORT double DynamicColorVersionNumber;
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// DynamicColor.swift
3+
// DynamicColor
4+
//
5+
// Created by Yannick Loriot on 16/07/2020.
6+
// Copyright © 2020 Yannick LORIOT. All rights reserved.
7+
//
8+
9+
class DynamicColor {
10+
11+
}

‎Examples/DynamicColor/Info.plist

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<plist version="1.0">
44
<dict>
55
<key>CFBundleDevelopmentRegion</key>
6-
<string>en</string>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
77
<key>CFBundleExecutable</key>
88
<string>$(EXECUTABLE_NAME)</string>
99
<key>CFBundleIdentifier</key>
@@ -13,14 +13,10 @@
1313
<key>CFBundleName</key>
1414
<string>$(PRODUCT_NAME)</string>
1515
<key>CFBundlePackageType</key>
16-
<string>FMWK</string>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>$(MARKETING_VERSION)</string>
19-
<key>CFBundleSignature</key>
20-
<string>????</string>
18+
<string>1.0</string>
2119
<key>CFBundleVersion</key>
2220
<string>$(CURRENT_PROJECT_VERSION)</string>
23-
<key>NSPrincipalClass</key>
24-
<string></string>
2521
</dict>
2622
</plist>

‎Examples/DynamicColorExample.xcodeproj/project.pbxproj

+226-219
Large diffs are not rendered by default.

‎Examples/WatchOSExample WatchKit Extension/InterfaceController.swift

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import WatchKit
1010
import Foundation
11+
import DynamicColor
1112

1213
class InterfaceController: WKInterfaceController {
1314
@IBOutlet var tableView: WKInterfaceTable!

‎Examples/WatchOSExample.xcodeproj/project.pbxproj

+294-94
Large diffs are not rendered by default.

‎Examples/WatchOSExample/Assets.xcassets/AppIcon.appiconset/Contents.json

+57-27
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,97 @@
22
"images" : [
33
{
44
"idiom" : "iphone",
5-
"size" : "29x29",
6-
"scale" : "2x"
5+
"scale" : "2x",
6+
"size" : "20x20"
77
},
88
{
99
"idiom" : "iphone",
10-
"size" : "29x29",
11-
"scale" : "3x"
10+
"scale" : "3x",
11+
"size" : "20x20"
1212
},
1313
{
1414
"idiom" : "iphone",
15-
"size" : "40x40",
16-
"scale" : "2x"
15+
"scale" : "2x",
16+
"size" : "29x29"
1717
},
1818
{
1919
"idiom" : "iphone",
20-
"size" : "40x40",
21-
"scale" : "3x"
20+
"scale" : "3x",
21+
"size" : "29x29"
2222
},
2323
{
2424
"idiom" : "iphone",
25-
"size" : "60x60",
26-
"scale" : "2x"
25+
"scale" : "2x",
26+
"size" : "40x40"
2727
},
2828
{
2929
"idiom" : "iphone",
30-
"size" : "60x60",
31-
"scale" : "3x"
30+
"scale" : "3x",
31+
"size" : "40x40"
32+
},
33+
{
34+
"idiom" : "iphone",
35+
"scale" : "2x",
36+
"size" : "60x60"
37+
},
38+
{
39+
"idiom" : "iphone",
40+
"scale" : "3x",
41+
"size" : "60x60"
42+
},
43+
{
44+
"idiom" : "ipad",
45+
"scale" : "1x",
46+
"size" : "20x20"
3247
},
3348
{
3449
"idiom" : "ipad",
35-
"size" : "29x29",
36-
"scale" : "1x"
50+
"scale" : "2x",
51+
"size" : "20x20"
3752
},
3853
{
3954
"idiom" : "ipad",
40-
"size" : "29x29",
41-
"scale" : "2x"
55+
"scale" : "1x",
56+
"size" : "29x29"
4257
},
4358
{
4459
"idiom" : "ipad",
45-
"size" : "40x40",
46-
"scale" : "1x"
60+
"scale" : "2x",
61+
"size" : "29x29"
4762
},
4863
{
4964
"idiom" : "ipad",
50-
"size" : "40x40",
51-
"scale" : "2x"
65+
"scale" : "1x",
66+
"size" : "40x40"
5267
},
5368
{
5469
"idiom" : "ipad",
55-
"size" : "76x76",
56-
"scale" : "1x"
70+
"scale" : "2x",
71+
"size" : "40x40"
5772
},
5873
{
5974
"idiom" : "ipad",
60-
"size" : "76x76",
61-
"scale" : "2x"
75+
"scale" : "1x",
76+
"size" : "76x76"
77+
},
78+
{
79+
"idiom" : "ipad",
80+
"scale" : "2x",
81+
"size" : "76x76"
82+
},
83+
{
84+
"idiom" : "ipad",
85+
"scale" : "2x",
86+
"size" : "83.5x83.5"
87+
},
88+
{
89+
"idiom" : "ios-marketing",
90+
"scale" : "1x",
91+
"size" : "1024x1024"
6292
}
6393
],
6494
"info" : {
65-
"version" : 1,
66-
"author" : "xcode"
95+
"author" : "xcode",
96+
"version" : 1
6797
}
68-
}
98+
}

‎Examples/iOSExample/ViewController.swift

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import UIKit
10+
import DynamicColor
1011

1112
class ViewController: UIViewController {
1213
private let colorCellIdentifier = "ColorCell"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎Sources/DynamicColorSpace.swift ‎Sources/Shared/DynamicColorSpace.swift

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
*
2525
*/
2626

27-
import Foundation
28-
2927
/**
3028
Defines the supported color spaces.
3129
*/

‎Sources/Shared/GrayscalingMode.swift

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* DynamicColor
3+
*
4+
* Copyright 2015-present Yannick Loriot.
5+
* http://yannickloriot.com
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*
25+
*/
26+
27+
/**
28+
Defines the mode (i.e color space) used for grayscaling.
29+
30+
[More info](https://en.wikipedia.org/wiki/Lightness#Lightness_and_human_perception)
31+
*/
32+
public enum GrayscalingMode {
33+
/// XYZ luminance
34+
case luminance
35+
/// HSL lightness
36+
case lightness
37+
/// RGB average
38+
case average
39+
/// HSV value
40+
case value
41+
}

‎Sources/HSL.swift ‎Sources/Shared/HSL.swift

+11-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*
2525
*/
2626

27+
import SwiftUI
28+
2729
#if os(iOS) || os(tvOS) || os(watchOS)
2830
import UIKit
2931
#elseif os(OSX)
@@ -106,14 +108,21 @@ internal struct HSL {
106108
- returns: A DynamicColor object corresponding to the current HSV color.
107109
*/
108110
func toDynamicColor() -> DynamicColor {
111+
let (r, g, b, a) = rgbaComponents()
112+
113+
return DynamicColor(red: r, green: g, blue: b, alpha: a)
114+
}
115+
116+
/// Returns the RGBA components from the current HSV color.
117+
func rgbaComponents() -> (CGFloat, CGFloat, CGFloat, CGFloat) {
109118
let m2 = l <= 0.5 ? l * (s + 1.0) : (l + s) - (l * s)
110119
let m1 = (l * 2.0) - m2
111120

112121
let r = hueToRGB(m1: m1, m2: m2, h: h + (1.0 / 3.0))
113122
let g = hueToRGB(m1: m1, m2: m2, h: h)
114123
let b = hueToRGB(m1: m1, m2: m2, h: h - (1.0 / 3.0))
115-
116-
return DynamicColor(red: r, green: g, blue: b, alpha: CGFloat(a))
124+
125+
return (r, g, b, CGFloat(a))
117126
}
118127

119128
/// Hue to RGB helper function

‎Sources/Utils.swift ‎Sources/Shared/Utils.swift

-16
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,3 @@ internal func roundToHex(_ x: CGFloat) -> UInt32 {
7171

7272
return UInt32(rounded)
7373
}
74-
75-
/**
76-
Defines the mode (i.e color space) used for grayscaling.
77-
78-
[More info](https://en.wikipedia.org/wiki/Lightness#Lightness_and_human_perception)
79-
*/
80-
public enum GrayscalingMode {
81-
/// XYZ luminance
82-
case luminance
83-
/// HSL lightness
84-
case lightness
85-
/// RGB average
86-
case average
87-
/// HSV value
88-
case value
89-
}
File renamed without changes.
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* DynamicColor
3+
*
4+
* Copyright 2015-present Yannick Loriot.
5+
* http://yannickloriot.com
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*
25+
*/
26+
27+
import SwiftUI
28+
29+
#if os(iOS) || os(tvOS) || os(watchOS)
30+
import UIKit
31+
#elseif os(OSX)
32+
import AppKit
33+
#endif
34+
35+
/// Convert a DynamicColor to a SwiftUI color
36+
extension DynamicColor {
37+
/**
38+
Returns the Color from an Dynamic Color.
39+
40+
- returns: A Color (SwiftUI).
41+
*/
42+
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
43+
func toColor() -> Color {
44+
return Color(self)
45+
}
46+
}

‎Sources/SwiftUI/HSL+Color.swift

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* DynamicColor
3+
*
4+
* Copyright 2015-present Yannick Loriot.
5+
* http://yannickloriot.com
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*
25+
*/
26+
27+
import SwiftUI
28+
29+
extension HSL {
30+
@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
31+
func toColor() -> Color {
32+
let (r, g, b, a) = rgbaComponents()
33+
34+
return SwiftUI.Color(red: Double(r), green: Double(g), blue: Double(b), opacity: Double(a))
35+
}
36+
}
37+

0 commit comments

Comments
 (0)
Please sign in to comment.