-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
200 additions
and
6 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,34 @@ | ||
// | ||
// Date+PovioKit.swift | ||
// PovioKit | ||
// | ||
// Created by Borut Tomazin on 14/05/2024. | ||
// Copyright © 2024 Povio Inc. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension Date { | ||
var isToday: Bool { calendar.isDateInToday(self) } | ||
var isYesterday: Bool { calendar.isDateInYesterday(self) } | ||
var isInFuture: Bool { self > Date() } | ||
|
||
/// Returns first day of the week | ||
var startOfWeek: Date? { | ||
let components: Set<Calendar.Component> = [.yearForWeekOfYear, .weekOfYear, .hour, .minute, .second, .nanosecond] | ||
return calendar.date(from: calendar.dateComponents(components, from: self)) | ||
} | ||
|
||
/// Returns last day of the week | ||
var endOfWeek: Date? { | ||
guard let startOfWeek = Date().startOfWeek else { return nil } | ||
return calendar.date(byAdding: .day, value: 6, to: startOfWeek) | ||
} | ||
} | ||
|
||
// MARK: - Private Methods | ||
private extension Date { | ||
var calendar: Calendar { | ||
Calendar.autoupdatingCurrent | ||
} | ||
} |
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/Core/Extensions/SwiftUI/AnyTransition+PovioKit.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 @@ | ||
// | ||
// AnyTransition+PovioKit.swift | ||
// PovioKit | ||
// | ||
// Created by Borut Tomazin on 14/05/2024. | ||
// Copyright © 2024 Povio Inc. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension AnyTransition { | ||
/// `slideLeft` is a inverse transition of system `slide` | ||
static var slideLeft: AnyTransition { | ||
.asymmetric( | ||
insertion: .move(edge: .trailing), | ||
removal: .move(edge: .leading) | ||
) | ||
} | ||
} |
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,46 @@ | ||
// | ||
// Color+PovioKit.swift | ||
// PovioKit | ||
// | ||
// Created by Borut Tomazin on 14/05/2024. | ||
// Copyright © 2024 Povio Inc. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension Color { | ||
/// Initialize Color with `red`, `green` and `blue` components. | ||
/// | ||
/// Example: `Color(red: 0, green: 0, blue: 0)` | ||
init(red: Int, green: Int, blue: Int) { | ||
self.init(red: Double(red) / 255.0, green: Double(green) / 255.0, blue: Double(blue) / 255.0) | ||
} | ||
|
||
/// Initialize Color with given `hex` value. | ||
/// | ||
/// Example: `Color(hex: "000000")` | ||
init(hex: String) { | ||
let hex = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted) | ||
var int: UInt64 = 0 | ||
Scanner(string: hex).scanHexInt64(&int) | ||
let alpha, red, green, blue: UInt64 | ||
switch hex.count { | ||
case 3: // RGB (12-bit) | ||
(alpha, red, green, blue) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17) | ||
case 6: // RGB (24-bit) | ||
(alpha, red, green, blue) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF) | ||
case 8: // ARGB (32-bit) | ||
(alpha, red, green, blue) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF) | ||
default: | ||
(alpha, red, green, blue) = (1, 1, 1, 0) | ||
} | ||
|
||
self.init( | ||
.sRGB, | ||
red: Double(red) / 255, | ||
green: Double(green) / 255, | ||
blue: Double(blue) / 255, | ||
opacity: Double(alpha) / 255 | ||
) | ||
} | ||
} |
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,26 @@ | ||
// | ||
// View+PovioKit.swift | ||
// PovioKit | ||
// | ||
// Created by Borut Tomazin on 02/03/2024. | ||
// Copyright © 2024 Povio Inc. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension View { | ||
/// Returns square frame for given `size`. | ||
func frame(size: CGFloat? = nil, alignment: Alignment = .center) -> some View { | ||
frame(width: size, height: size, alignment: alignment) | ||
} | ||
|
||
/// Hides view using opacity. | ||
func hidden(_ hidden: Bool) -> some View { | ||
opacity(hidden ? 0 : 1) | ||
} | ||
|
||
/// Disables animation on view. | ||
func noAnimation() -> some View { | ||
animation(nil, value: UUID()) | ||
} | ||
} |
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,18 @@ | ||
// | ||
// CGSize+PovioKit.swift | ||
// PovioKit | ||
// | ||
// Created by Borut Tomazin on 14/05/2024. | ||
// Copyright © 2024 Povio Inc. All rights reserved. | ||
// | ||
|
||
#if os(iOS) | ||
import UIKit | ||
|
||
public extension CGSize { | ||
init(size: CGFloat) { | ||
self.init(width: size, height: size) | ||
} | ||
} | ||
|
||
#endif |
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
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
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
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