tchigher / GitHubUserFinderKMM

Kotlin Multiplatform Mobile sample project with Jetpack Compose and SwiftUI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GitHubUserFinderKMM

Kotlin Multiplatform Mobile sample project with Jetpack Compose and SwiftUI

Check this basic, simple KMM project with latest and greatest libraries. You can also easily learn and keep your knowledge up-to-date in both Jeptack Compose and SwiftUI.

iOS Swift Android Kotlin GitHub

Android iOS

About the project

  • List and detail screens
  • Simple paging functionality
  • MVVM
  • Linter & formatter (ktlint, swiftlint)
  • Dark mode
  • Error handling
  • GitHub API
  • CommonFlow

In this project the flow is running on the main thread and then invoking “main-safe” suspend functions provided by Ktor. https://johnoreilly.dev/posts/kotlinmultiplatform-swift-combine_publisher-flow/

fun <T> Flow<T>.asCommonFlow(): CommonFlow<T> = CommonFlow(this)

class CommonFlow<T>(private val origin: Flow<T>) : Flow<T> by origin {
   fun subscribe(block: (T) -> Unit): Closeable {
       val job = Job()
       onEach { block(it) }.launchIn(CoroutineScope(job + Dispatchers.Main))
       return object : Closeable {
           override fun close() {
               job.cancel()
           }
       }
   }
}
  • with custom ApplicationDispatcher
    internal actual val ApplicationDispatcher: CoroutineContext = Dispatchers.Default
    internal actual val ApplicationDispatcher: CoroutineContext =
     NsQueueDispatcher(dispatch_get_main_queue())
    
    internal class NsQueueDispatcher(
     private val dispatchQueue: dispatch_queue_t
    ) : CoroutineDispatcher() {
     override fun dispatch(context: CoroutineContext, block: Runnable) {
         dispatch_async(dispatchQueue) {
             block.run()
         }
       }
    }

Libraries

Check Dependencies.kt for more details

IDEs

  • Android Studio Chipmunk | 2021.2.1 Patch 1 | with KMM plugin
  • Xcode 13.2.1

What's next?

  • Testing (UI and integration tests)
  • Combine and AsyncStream extensions
  • Fancy animations
  • Shared ViewModels??? We’ll see 😜

KMM beta roadmap

About

Kotlin Multiplatform Mobile sample project with Jetpack Compose and SwiftUI


Languages

Language:Kotlin 78.8%Language:Swift 21.2%