Skip to content

Commit 2529de3

Browse files
committed
add swift formatter
1 parent a22862c commit 2529de3

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

compose-ui/src/iosMain/kotlin/dev/dimension/flare/ui/controllers/ComposeUIHelper.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import dev.dimension.flare.di.KoinHelper
1111
import dev.dimension.flare.ui.humanizer.SwiftFormatter
1212
import kotlinx.coroutines.CoroutineScope
1313
import kotlinx.coroutines.Dispatchers
14+
import kotlinx.coroutines.IO
1415
import kotlinx.coroutines.launch
16+
import kotlinx.coroutines.runBlocking
1517
import kotlinx.coroutines.withContext
1618
import org.koin.core.context.startKoin
17-
import org.koin.dsl.binds
19+
import org.koin.dsl.bind
1820
import org.koin.dsl.module
1921

2022
public object ComposeUIHelper {
@@ -28,10 +30,10 @@ public object ComposeUIHelper {
2830
module {
2931
single {
3032
ProxyInAppNotification(inAppNotification, get())
31-
} binds arrayOf(InAppNotification::class)
33+
} bind InAppNotification::class
3234
single {
3335
swiftFormatter
34-
}
36+
} bind SwiftFormatter::class
3537
},
3638
)
3739
modules(dev.dimension.flare.di.composeUiModule)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import Foundation
2+
import KotlinSharedUI
3+
4+
class Formatter: SwiftFormatter {
5+
private init() {}
6+
7+
static let shared = Formatter()
8+
nonisolated func formatNumber(number: Int64) -> String {
9+
return Int(number)
10+
.formatted(
11+
.number
12+
.notation(.compactName)
13+
.grouping(.never)
14+
.precision(.fractionLength(0...2))
15+
)
16+
}
17+
}

iosApp/flare/FlareApp.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ struct FlareApp: App {
88
configureAudioSessionForMixing()
99
ComposeUIHelper.shared.initialize(
1010
inAppNotification: SwiftInAppNotification.shared,
11+
swiftFormatter: Formatter.shared
1112
)
1213
}
1314
var body: some Scene {

iosApp/flare/UI/Component/DateTimeText.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,9 @@ struct DateTimeText: View {
77

88
var body: some View {
99
if fullTime {
10-
HStack {
11-
Text(data.platformValue, style: .date)
12-
Text(data.platformValue, style: .time)
13-
}
10+
Text(data.platformValue, style: .date) + Text(data.platformValue, style: .time)
1411
} else {
15-
switch data.diff {
16-
case .days: Text(data.platformValue, style: .relative)
17-
case .hours: Text(data.platformValue, style: .relative)
18-
case .minutes: Text(data.platformValue, style: .relative)
19-
case .seconds: Text(data.platformValue, style: .relative)
20-
case .monthDay: Text(data.platformValue, style: .date)
21-
case .yearMonthDay: Text(data.platformValue, style: .date)
22-
}
12+
Text(data.platformValue, style: .relative)
2313
}
2414
}
2515
}

0 commit comments

Comments
 (0)