Skip to content

Commit

Permalink
Merge pull request #21 from splendo/feature/#20-kaluga-0.4.0-migration
Browse files Browse the repository at this point in the history
Updated stencil classes for kaluga 0.4.0
  • Loading branch information
ChristoferAlexander authored Jun 20, 2022
2 parents 7702048 + 3f5b742 commit de63611
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 55 deletions.
2 changes: 1 addition & 1 deletion stencils/Color+Color.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import SwiftUI
import {{ argument.sharedFrameworkName }}

extension {{ argument.sharedFrameworkName }}.Color {
extension {{ argument.sharedFrameworkName }}.KalugaColor {
var swiftUI: SwiftUI.Color {
if #available(iOS 15.0, *) {
return SwiftUI.Color(uiColor: self.uiColor)
Expand Down
2 changes: 1 addition & 1 deletion stencils/KalugaBackgroundStyle+SwiftUI.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extension {{ argument.sharedFrameworkName }}.BackgroundStyle {
case is {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleNone:
finalStoke = {{ argument.sharedFrameworkName }}.BackgroundStyle.StrokeStyleStroke(
width: 0.0,
color: Color(uiColor: .clear)
color: KalugaColor(uiColor: .clear)
)
default:
preconditionFailure("Unknown stroke style type!")
Expand Down
7 changes: 4 additions & 3 deletions stencils/KalugaDate+Extensions.stencil
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import Foundation
import {{ argument.sharedFrameworkName }}

typealias KalugaDate = {{ argument.sharedFrameworkName }}.Date
typealias KalugaDate = {{ argument.sharedFrameworkName }}.KalugaDate
typealias DefaultKalugaDate = {{ argument.sharedFrameworkName }}.DefaultKalugaDate

extension Foundation.Date {

func toKalugaDate() -> KalugaDate {
KalugaDate.Companion().epoch(
DefaultKalugaDate.Companion().epoch(
offsetInMilliseconds: Int64(self.timeIntervalSince1970 * 1_000),
timeZone: TimeZone.Companion().current(),
locale: Locale.Companion().defaultLocale
Expand All @@ -21,7 +22,7 @@ extension KalugaDate {
}

static var today: KalugaDate {
KalugaDate.Companion().today(
DefaultKalugaDate.Companion().today(
timeZone: TimeZone.Companion().current(),
locale: Locale.Companion().defaultLocale
)
Expand Down
12 changes: 6 additions & 6 deletions stencils/NavigationBarColor.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {{ argument.sharedFrameworkName }}
struct NavigationBarColor: ViewModifier {

init(
backgroundColor: {{ argument.sharedFrameworkName }}.Color,
tintColor: {{ argument.sharedFrameworkName }}.Color,
shadowColor: {{ argument.sharedFrameworkName }}.Color,
backgroundColor: {{ argument.sharedFrameworkName }}.KalugaColor,
tintColor: {{ argument.sharedFrameworkName }}.KalugaColor,
shadowColor: {{ argument.sharedFrameworkName }}.KalugaColor,
font: UIFont,
largeFont: UIFont
) {
Expand Down Expand Up @@ -37,9 +37,9 @@ struct NavigationBarColor: ViewModifier {

extension View {
func navigationBarColor(
backgroundColor: {{ argument.sharedFrameworkName }}.Color,
tintColor: {{ argument.sharedFrameworkName }}.Color,
shadowColor: {{ argument.sharedFrameworkName }}.Color,
backgroundColor: {{ argument.sharedFrameworkName }}.KalugaColor,
tintColor: {{ argument.sharedFrameworkName }}.KalugaColor,
shadowColor: {{ argument.sharedFrameworkName }}.KalugaColor,
font: UIFont = .systemFont(ofSize: 17, weight: .semibold),
largeFont: UIFont = .boldSystemFont(ofSize: 34)
) -> some View {
Expand Down
15 changes: 6 additions & 9 deletions stencils/Observable.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SwiftUI
import Combine
import {{ argument.sharedFrameworkName }}

typealias KotlinObject = AnyObject & Equatable
typealias KotlinObject = AnyObject

typealias ObjectObservable<T: KotlinObject & HasDefaultValue> = MappedWithDefaultObservable<T, T, EmptyMapper<T>>
typealias StringObservable = MappedWithDefaultObservable<NSString, String, StringMapper>
Expand All @@ -11,15 +11,15 @@ typealias IntObservable = MappedWithDefaultObservable<KotlinInt, Int, IntMapper>
typealias FloatObservable = MappedWithDefaultObservable<KotlinFloat, Float, FloatMapper>
typealias DoubleObservable = MappedWithDefaultObservable<KotlinDouble, Double, DoubleMapper>
{% if argument.includeResources %}
typealias UIColorObservable = MappedWithDefaultObservable<{{ argument.sharedFrameworkName }}.Color, UIColor, UIColorMapper>
typealias ColorObservable = MappedWithDefaultObservable<{{ argument.sharedFrameworkName }}.Color, SwiftUI.Color, ColorMapper>
typealias UIColorObservable = MappedWithDefaultObservable<{{ argument.sharedFrameworkName }}.KalugaColor, UIColor, UIColorMapper>
typealias ColorObservable = MappedWithDefaultObservable<{{ argument.sharedFrameworkName }}.KalugaColor, SwiftUI.Color, ColorMapper>
typealias UIImageObservable = MappedWithDefaultObservable<UIImage, UIImage, EmptyMapper<UIImage>>
typealias ImageObservable = MappedWithDefaultObservable<UIImage, Image, ImageMapper>
{% endif %}
typealias DateObservable = MappedWithDefaultObservable<KalugaDate, Foundation.Date, DateMapper>
typealias ObjectSimpleObservable<T: KotlinObject> = MappedObservable<T, T, EmptyMapper<T>>

class Observable<Input: KotlinObject, Output: Equatable>: ObservableObject {
class Observable<Input: KotlinObject, Output: Any>: ObservableObject {

@Published private(set) var value: Output

Expand Down Expand Up @@ -53,9 +53,6 @@ class Observable<Input: KotlinObject, Output: Equatable>: ObservableObject {
}
return
}
guard self.input != newValue else {
return
}
let mapped = mapper(newValue!)
if animated {
withAnimation {
Expand All @@ -78,7 +75,7 @@ class Observable<Input: KotlinObject, Output: Equatable>: ObservableObject {

class MappedObservable<
Input: KotlinObject,
Output: Equatable,
Output: Any,
Mapper: PlatformValueToMapper
>: Observable<Input, Output> where Mapper.Input == Input, Mapper.Output == Output {
init(_ observable: BaseInitializedObservable<Input>, defaultValue: Output, animated: Bool = false) {
Expand All @@ -88,7 +85,7 @@ class MappedObservable<

class MappedWithDefaultObservable<
Input: KotlinObject,
Output: Equatable & HasDefaultValue,
Output: Any & HasDefaultValue,
Mapper: PlatformValueToMapper
>: MappedObservable<Input, Output, Mapper> where Mapper.Input == Input, Mapper.Output == Output {
override init(
Expand Down
14 changes: 7 additions & 7 deletions stencils/PlatformMappers.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,27 @@ enum DateOptionalMapper: PlatformOptionalValueMapper {

{% if argument.includeResources %}
enum UIColorMapper: PlatformValueMapper {
static func to(_ value: {{ argument.sharedFrameworkName }}.Color) -> UIColor { value.uiColor }
static func from(_ value: UIColor) -> {{ argument.sharedFrameworkName }}.Color { {{ argument.sharedFrameworkName }}.Color(uiColor: value) }
static func to(_ value: {{ argument.sharedFrameworkName }}.KalugaColor) -> UIColor { value.uiColor }
static func from(_ value: UIColor) -> {{ argument.sharedFrameworkName }}.KalugaColor { {{ argument.sharedFrameworkName }}.KalugaColor(uiColor: value) }
}

enum UIColorOptionalMapper: PlatformOptionalValueMapper {
static func to(_ value: {{ argument.sharedFrameworkName }}.Color?) -> UIColor? { value?.uiColor }
static func from(_ value: UIColor?) -> {{ argument.sharedFrameworkName }}.Color? {
static func to(_ value: {{ argument.sharedFrameworkName }}.KalugaColor?) -> UIColor? { value?.uiColor }
static func from(_ value: UIColor?) -> {{ argument.sharedFrameworkName }}.KalugaColor? {
if let value = value {
return {{ argument.sharedFrameworkName }}.Color(uiColor: value)
return {{ argument.sharedFrameworkName }}.KalugaColor(uiColor: value)
} else {
return nil
}
}
}

enum ColorMapper: PlatformValueToMapper {
static func to(_ value: {{ argument.sharedFrameworkName }}.Color) -> SwiftUI.Color { value.swiftUI }
static func to(_ value: {{ argument.sharedFrameworkName }}.KalugaColor) -> SwiftUI.Color { value.swiftUI }
}

enum ColorOptionalMapper: PlatformOptionalValueToMapper {
static func to(_ value: {{ argument.sharedFrameworkName }}.Color?) -> SwiftUI.Color? { value?.swiftUI }
static func to(_ value: {{ argument.sharedFrameworkName }}.KalugaColor?) -> SwiftUI.Color? { value?.swiftUI }
}

enum ImageMapper: PlatformValueToMapper {
Expand Down
10 changes: 2 additions & 8 deletions stencils/Subject.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typealias FloatSubject = MappedSubject<KotlinFloat, Float, FloatMapper>
typealias DoubleSubject = MappedSubject<KotlinDouble, Double, DoubleMapper>
typealias DateSubject = MappedSubject<KalugaDate, Foundation.Date, DateMapper>

class Subject<Input: KotlinObject, Output: Equatable>: ObservableObject {
class Subject<Input: KotlinObject, Output: Any>: ObservableObject {

@Published var value: Output

Expand All @@ -32,9 +32,6 @@ class Subject<Input: KotlinObject, Output: Equatable>: ObservableObject {
value = defaultValue
}
cancellable = _value.projectedValue.sink { newValue in
if let current = subject.currentOrNull, newValue == toMapper(current) {
return
}
subject.post(newValue: fromMapper(newValue))
}
subject
Expand All @@ -51,9 +48,6 @@ class Subject<Input: KotlinObject, Output: Equatable>: ObservableObject {
}
return
}
guard self.input != newValue else {
return
}
let mapped = toMapper(newValue!)
if animated {
withAnimation {
Expand All @@ -76,7 +70,7 @@ class Subject<Input: KotlinObject, Output: Equatable>: ObservableObject {

class MappedSubject<
Input: KotlinObject,
Output: Equatable & HasDefaultValue,
Output: Any & HasDefaultValue,
Mapper: PlatformValueMapper
>: Subject<Input, Output> where Mapper.Input == Input, Mapper.Output == Output {

Expand Down
11 changes: 4 additions & 7 deletions stencils/UninitializedObservable.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ typealias IntUninitializedObservable = MappedUninitializedObservable<KotlinInt,
typealias FloatUninitializedObservable = MappedUninitializedObservable<KotlinFloat, Float, FloatOptionalMapper>
typealias DoubleUninitializedObservable = MappedUninitializedObservable<KotlinDouble, Double, DoubleOptionalMapper>
{% if argument.includeResources %}
typealias UIColorUninitializedObservable = MappedUninitializedObservable<{{ argument.sharedFrameworkName }}.Color, UIColor, UIColorOptionalMapper>
typealias ColorUninitializedObservable = MappedUninitializedObservable<{{ argument.sharedFrameworkName }}.Color, SwiftUI.Color, ColorOptionalMapper>
typealias UIColorUninitializedObservable = MappedUninitializedObservable<{{ argument.sharedFrameworkName }}.KalugaColor, UIColor, UIColorOptionalMapper>
typealias ColorUninitializedObservable = MappedUninitializedObservable<{{ argument.sharedFrameworkName }}.KalugaColor, SwiftUI.Color, ColorOptionalMapper>
typealias UIImageUninitializedObservable = MappedUninitializedObservable<UIImage, UIImage, EmptyOptionalMapper<UIImage>>
typealias ImageUninitializedObservable = MappedUninitializedObservable<UIImage, Image, ImageOptionalMapper>
{% endif %}
typealias DateUninitializedObservable = MappedUninitializedObservable<KalugaDate, Foundation.Date, DateOptionalMapper>

class UninitializedObservable<Input: KotlinObject, Output: Equatable>: ObservableObject {
class UninitializedObservable<Input: KotlinObject, Output: Any>: ObservableObject {

@Published private(set) var value: Output?

Expand All @@ -41,9 +41,6 @@ class UninitializedObservable<Input: KotlinObject, Output: Equatable>: Observabl
defer {
self.input = newValue
}
guard self.input != newValue else {
return
}
let mapped = mapper(newValue)
if animated {
withAnimation {
Expand All @@ -66,7 +63,7 @@ class UninitializedObservable<Input: KotlinObject, Output: Equatable>: Observabl

class MappedUninitializedObservable<
Input: KotlinObject,
Output: Equatable,
Output: Any,
Mapper: PlatformOptionalValueToMapper
>: UninitializedObservable<Input, Output> where Mapper.Input == Input, Mapper.Output == Output {
init(_ observable: BaseUninitializedObservable<Input>, animated: Bool = false) {
Expand Down
16 changes: 3 additions & 13 deletions stencils/UninitializedSubject.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ typealias FloatUninitializedSubject = MappedUninitializedSubject<KotlinFloat, Fl
typealias DoubleUninitializedSubject = MappedUninitializedSubject<KotlinDouble, Double, DoubleOptionalMapper>
typealias DateUninitializedSubject = MappedUninitializedSubject<KalugaDate, Foundation.Date, DateOptionalMapper>

class UninitializedSubject<Input: KotlinObject, Output: Equatable>: ObservableObject {
class UninitializedSubject<Input: KotlinObject, Output: Any>: ObservableObject {

@Published var value: Output?

Expand All @@ -28,14 +28,7 @@ class UninitializedSubject<Input: KotlinObject, Output: Equatable>: ObservableOb
value = toMapper(input!)
}
cancellable = _value.projectedValue.sink { newValue in
if let current = subject.currentOrNull, newValue == toMapper(current) {
return
}
if let newValue = newValue {
subject.post(newValue: fromMapper(newValue))
} else {
subject.post(newValue: nil)
}
subject.post(newValue: fromMapper(newValue))
}
subject
.observe { [weak self] newValue in
Expand All @@ -45,9 +38,6 @@ class UninitializedSubject<Input: KotlinObject, Output: Equatable>: ObservableOb
defer {
self.input = newValue
}
guard self.input != newValue else {
return
}
let mapped: Output?
if let newValue = newValue {
mapped = toMapper(newValue)
Expand Down Expand Up @@ -75,7 +65,7 @@ class UninitializedSubject<Input: KotlinObject, Output: Equatable>: ObservableOb

class MappedUninitializedSubject<
Input: KotlinObject,
Output: Equatable,
Output: Any,
Mapper: PlatformOptionalValueMapper
>: UninitializedSubject<Input, Output> where Mapper.Input == Input, Mapper.Output == Output {
init(_ subject: BaseUninitializedSubject<Input>, animated: Bool = false) {
Expand Down

0 comments on commit de63611

Please sign in to comment.