Giter Site home page Giter Site logo

mangaku's Introduction

MangaKu


MovieCatalogue

๐Ÿค– Introduction

MangaKu App Powered by Kotlin Multiplatform Mobile, Jetpack Compose, and SwiftUI

Module

  • core: data and domain layer
  • iosApp: ios presentation layer
  • androidApp: android presentation layer
  • buildSrc: androidApp and core dependencies

Table of Contents

๐Ÿฆพ Features

A few things you can do with MangaKu:

  • View Popular Manga
  • Easily search for any Manga
  • See Manga Detail
  • Save your favorite manga

โš ๏ธ This project have no concern about backward compatibility, and only support the very latest or experimental api's for both android and ios โš ๏ธ

๐Ÿš— Installation

  • Follow the KMM Guide by Jetbrains for getting started building a project with KMM.
  • Install Kotlin Multiplatform Mobile plugin in Android Studio
  • Clone or download the repo
  • Rebuild Project
  • To run in iOS, Open Xcode and pod install inside iosApp folder to install shared module and ios dependencies

๐Ÿ“ธ Screenshot

๐Ÿ’ก Libraries

core:

iosApp:

androidApp:

๐Ÿ’จ Domain to Presentation

In Android, Because both core and androidApp written in Kotlin, we can simply collect flow :

private fun getTrendingManga() = viewModelScope.launch {
  _trendingManga.value = Result.loading()
  browseUseCase.getManga()
   .catch { cause: Throwable ->
     _trendingManga.value = Result.failed(cause)
   }
   .collect { result ->
     if (result.isNotEmpty())
     _trendingManga.value = Result.success(result)
   }
 }

But in iOS, we have to deal with swift, here i'm using createPublisher() from KMPNativeCoroutines to collect flow as Publisher in Combine :

func fetchTrendingManga() {
  trendingManga = .loading
  createPublisher(for: browseUseCase.getTrendingMangaNative())
   .receive(on: DispatchQueue.main)
   .sink { completion in
     switch completion {
       case .finished: ()
       case .failure(let error):
         self.trendingManga = .error(error: error)
       }
    } receiveValue: { value in
        self.trendingManga = .success(data: value)
    }.store(in: &cancellables)
}

or even better, you can use asyncFunction / asyncResult / asyncStream function to collect coroutine flow as new swift's concurrency features, checkout branch feat/experimenting-swift-new concurrency to see the example

combining two powerful concurrency feature from both native framework, how cool is that !?

func fetchTrendingManga() {
    Task {
      trendingManga = .loading
      do {
        let nativeFlow = try await asyncFunction(for: browseUseCase.getTrendingMangaNative())
        let stream = asyncStream(for: nativeFlow)
        for try await data in stream {
          trendingManga = .success(data: data)
        }
      } catch {
        trendingManga = .error(error: error)
      }
    }
  }

learn more: https://github.com/rickclephas/KMP-NativeCoroutines

๐Ÿš€ Expect and Actual

in KMM, there is a negative case when there's no support to share code for some feature in both ios and android, and it's expensive to write separately in each module

so the solution is โœจexpect and actualโœจ, we can write expect inside commonMain and write "actual" implementation with actual inside androidMain and iosMain and then each module will use expect

example:

commonMain/utils/DateFormatter.kt

expect fun formatDate(dateString: String, format: String): String

androidMain/utils/DateFormatter.kt

SimpleDateFormat

actual fun formatDate(dateString: String, format: String): String {
    val date = SimpleDateFormat(Constants.formatFromApi).parse(dateString)
    val dateFormatter = SimpleDateFormat(format, Locale.getDefault())
    return dateFormatter.format(date ?: Date())
}

iosMain/utils/DateFormatter.kt

NSDateFormatter

actual fun formatDate(dateString: String, format: String): String {
    val dateFormatter = NSDateFormatter().apply {
	dateFormat = Constants.formatFromApi
     }

    val formatter = NSDateFormatter().apply {
	dateFormat = format
	locale = NSLocale(localeIdentifier = "id_ID")
     }

    return formatter.stringFromDate(dateFormatter.dateFromString(dateString) ?: NSDate())
}

yes, we can use Foundation same as what we use in Xcode

๐Ÿ› Project Structure

core:

  • data
    • mapper
    • repository
    • source
      • local
        • entity
      • remote
        • response
  • di
  • domain
    • model
    • repository
    • usecase
      • browse
      • detail
      • mymanga
      • search
  • utils

androidApp:

  • ui
    • composables
    • home
      • composables
    • favorite
    • search
    • detail
  • di
  • utils

iosApp:

  • Dependency
  • App
  • Main
  • Resources
  • ReusableView
  • Extensions
  • Utils
  • Features
    • Browse
      • Navigator
      • Views
    • Search
    • Detail
    • MyManga

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.