Skip to content

Commit

Permalink
For touchlab#305 - Use Compose Multiplatform to show the UI from :sha…
Browse files Browse the repository at this point in the history
…red on iOS
  • Loading branch information
Mugurell committed Jul 21, 2023
1 parent c0f6928 commit dec16b1
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 69 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ androidx-lifecycle = "2.6.1"

junit = "4.13.2"

coroutines = "1.7.0"
coroutines = "1.7.2"
kotlinx-datetime = "0.4.0"
ktor = "2.3.2"

Expand Down
36 changes: 12 additions & 24 deletions ios/KaMPKitiOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
objects = {

/* Begin PBXBuildFile section */
0AE285002A6AD6B7000B6B60 /* ComposeContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE284FF2A6AD6B7000B6B60 /* ComposeContentView.swift */; };
0AE285022A6AD7BD000B6B60 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE285012A6AD7BD000B6B60 /* ContentView.swift */; };
0AE285042A6AD7D0000B6B60 /* IOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE285032A6AD7D0000B6B60 /* IOSApp.swift */; };
3DFF917C64A18A83DA010EE1 /* Pods_KaMPKitiOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B859F3FB23133D22AB9DD835 /* Pods_KaMPKitiOS.framework */; };
461C74AA2788F5F3004B1FFC /* CombineAdapters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 461C74A92788F5F3004B1FFC /* CombineAdapters.swift */; };
46A5B5EF26AF54F7002EFEAA /* BreedListScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46A5B5EE26AF54F7002EFEAA /* BreedListScreen.swift */; };
46A5B60826B04921002EFEAA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 46A5B60626B04920002EFEAA /* Main.storyboard */; };
46B5284D249C5CF400A7725D /* Koin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46B5284C249C5CF400A7725D /* Koin.swift */; };
F1465F0123AA94BF0055F7C3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1465F0023AA94BF0055F7C3 /* AppDelegate.swift */; };
F1465F0A23AA94BF0055F7C3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F1465F0923AA94BF0055F7C3 /* Assets.xcassets */; };
F1465F0D23AA94BF0055F7C3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F1465F0B23AA94BF0055F7C3 /* LaunchScreen.storyboard */; };
F1465F1823AA94C00055F7C3 /* KaMPKitiOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1465F1723AA94C00055F7C3 /* KaMPKitiOSTests.swift */; };
Expand All @@ -37,16 +36,15 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
0AE284FF2A6AD6B7000B6B60 /* ComposeContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposeContentView.swift; sourceTree = "<group>"; };
0AE285012A6AD7BD000B6B60 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
0AE285032A6AD7D0000B6B60 /* IOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IOSApp.swift; sourceTree = "<group>"; };
1DFCC00C8DAA719770A18D1A /* Pods-KaMPKitiOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-KaMPKitiOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-KaMPKitiOS/Pods-KaMPKitiOS.release.xcconfig"; sourceTree = "<group>"; };
2A1ED6A4A2A53F5F75C58E5F /* Pods-KaMPKitiOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-KaMPKitiOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-KaMPKitiOS/Pods-KaMPKitiOS.release.xcconfig"; sourceTree = "<group>"; };
461C74A92788F5F3004B1FFC /* CombineAdapters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CombineAdapters.swift; sourceTree = "<group>"; };
46A5B5EE26AF54F7002EFEAA /* BreedListScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BreedListScreen.swift; sourceTree = "<group>"; };
46A5B60726B04920002EFEAA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
46B5284C249C5CF400A7725D /* Koin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Koin.swift; sourceTree = "<group>"; };
B859F3FB23133D22AB9DD835 /* Pods_KaMPKitiOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_KaMPKitiOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
ED1F782AF3705197012D0C33 /* Pods-KaMPKitiOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-KaMPKitiOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-KaMPKitiOS/Pods-KaMPKitiOS.debug.xcconfig"; sourceTree = "<group>"; };
F1465EFD23AA94BF0055F7C3 /* KaMPKitiOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KaMPKitiOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
F1465F0023AA94BF0055F7C3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
F1465F0923AA94BF0055F7C3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
F1465F0C23AA94BF0055F7C3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
F1465F0E23AA94BF0055F7C3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -129,14 +127,13 @@
F1465EFF23AA94BF0055F7C3 /* KaMPKitiOS */ = {
isa = PBXGroup;
children = (
F1465F0023AA94BF0055F7C3 /* AppDelegate.swift */,
46A5B60626B04920002EFEAA /* Main.storyboard */,
46B5284C249C5CF400A7725D /* Koin.swift */,
F1465F0923AA94BF0055F7C3 /* Assets.xcassets */,
F1465F0B23AA94BF0055F7C3 /* LaunchScreen.storyboard */,
F1465F0E23AA94BF0055F7C3 /* Info.plist */,
46A5B5EE26AF54F7002EFEAA /* BreedListScreen.swift */,
461C74A92788F5F3004B1FFC /* CombineAdapters.swift */,
0AE284FF2A6AD6B7000B6B60 /* ComposeContentView.swift */,
0AE285012A6AD7BD000B6B60 /* ContentView.swift */,
0AE285032A6AD7D0000B6B60 /* IOSApp.swift */,
);
path = KaMPKitiOS;
sourceTree = "<group>";
Expand Down Expand Up @@ -266,7 +263,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
46A5B60826B04921002EFEAA /* Main.storyboard in Resources */,
F1465F0D23AA94BF0055F7C3 /* LaunchScreen.storyboard in Resources */,
F1465F0A23AA94BF0055F7C3 /* Assets.xcassets in Resources */,
);
Expand Down Expand Up @@ -354,9 +350,9 @@
buildActionMask = 2147483647;
files = (
46B5284D249C5CF400A7725D /* Koin.swift in Sources */,
461C74AA2788F5F3004B1FFC /* CombineAdapters.swift in Sources */,
46A5B5EF26AF54F7002EFEAA /* BreedListScreen.swift in Sources */,
F1465F0123AA94BF0055F7C3 /* AppDelegate.swift in Sources */,
0AE285002A6AD6B7000B6B60 /* ComposeContentView.swift in Sources */,
0AE285022A6AD7BD000B6B60 /* ContentView.swift in Sources */,
0AE285042A6AD7D0000B6B60 /* IOSApp.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -392,14 +388,6 @@
/* End PBXTargetDependency section */

/* Begin PBXVariantGroup section */
46A5B60626B04920002EFEAA /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
46A5B60726B04920002EFEAA /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
F1465F0B23AA94BF0055F7C3 /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
Expand Down
34 changes: 0 additions & 34 deletions ios/KaMPKitiOS/AppDelegate.swift

This file was deleted.

24 changes: 24 additions & 0 deletions ios/KaMPKitiOS/ComposeContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// ComposeContentView.swift
// KaMPKitiOS
//
// Created by Petru on 7/21/23.
// Copyright © 2023 Touchlab. All rights reserved.
//

import Foundation
import shared
import SwiftUI

struct ComposeContentView: UIViewControllerRepresentable {
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {
// no-op
}

func makeUIViewController(context: Context) -> some UIViewController {
MainViewControllerKt.MainViewController(
logger: koin.loggerWithTag(tag: "ViewController"),
viewModel: KotlinDependencies.shared.getBreedViewModel().viewModel
)
}
}
16 changes: 16 additions & 0 deletions ios/KaMPKitiOS/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// ContentView.swift
// KaMPKitiOS
//
// Created by Petru on 7/21/23.
// Copyright © 2023 Touchlab. All rights reserved.
//

import SwiftUI
import shared

struct ContentView: View {
var body: some View {
ComposeContentView()
}
}
23 changes: 23 additions & 0 deletions ios/KaMPKitiOS/IOSApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// iOSApp.swift
// KaMPKitiOS
//
// Created by Petru on 7/21/23.
// Copyright © 2023 Touchlab. All rights reserved.
//

import SwiftUI

@main
struct IOSApp: App {

init() {
startKoin()
}

var body: some Scene {
WindowGroup {
ContentView()
}
}
}
6 changes: 3 additions & 3 deletions ios/KaMPKitiOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<string>LaunchScreen.storyboard</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UIStatusBarStyle</key>
<string></string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
12 changes: 6 additions & 6 deletions ios/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ kotlin {
summary = "Common library for the KaMP starter kit"
homepage = "https://github.com/touchlab/KaMPKit"
framework {
isStatic = false // SwiftUI preview requires dynamic framework
// Below line is needed for Compose Multiplatform, see https://github.com/JetBrains/compose-multiplatform/issues/3178
isStatic = true
linkerOpts("-lsqlite3")
export(libs.touchlab.kermit.simple)
export(libs.moko.resources)
Expand Down
14 changes: 14 additions & 0 deletions shared/src/commonMain/kotlin/co/touchlab/kampkit/Koin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,18 @@ internal inline fun <reified T> Scope.getWith(vararg params: Any?): T {
// Simple function to clean up the syntax a bit
fun KoinComponent.injectLogger(tag: String): Lazy<Logger> = inject { parametersOf(tag) }

/**
* Get any instance of `T` if available in the dependencies graph.
*
* @param tag Optional name of allowing to get a specific
*/
inline fun <reified T: Any> injectInstance(tag: String? = null): T {
return object : KoinComponent {
val value: T by when (tag) {
null -> inject()
else -> inject { parametersOf(tag) }
}
}.value
}

expect val platformModule: Module
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package co.touchlab.kampkit.ui

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.ui.window.ComposeUIViewController
import co.touchlab.kampkit.injectInstance
import co.touchlab.kampkit.models.BreedViewModel
import co.touchlab.kampkit.ui.theme.KaMPKitTheme
import co.touchlab.kermit.Logger
import platform.UIKit.UIApplication
import platform.UIKit.UIScreen
import platform.UIKit.UIUserInterfaceStyle

fun MainViewController(logger: Logger, viewModel: BreedViewModel) = ComposeUIViewController {
val isDarkThemeEnabled =
UIScreen.mainScreen.traitCollection.userInterfaceStyle == UIUserInterfaceStyle.UIUserInterfaceStyleDark

KaMPKitTheme(isDarkThemeEnabled, false) {
MainScreen(viewModel, logger)
}
}

0 comments on commit dec16b1

Please sign in to comment.