• x

    Xavier Lian

    2 years ago
    I’m trying to flesh out some architecture for MVVM, but I’m not entirely sure how to bind viewmodels (VMs) to views. My questions are best asked through an example. So here’s a simple VM:
    class MyVM(
        private val vmDidSummonLoadingScreen: () -> Unit,
        private val vmDidDismissLoadingScreen: () -> Unit
    )
    {
        fun doAFlip() 
        {
            vmDidSummonLoadingScreen()
            startSuperLongAsyncTask {
                vmDidDismissLoadingScreen()
            }
        }
    }
    Here’s some example UI in Android
    class FMMain: Fragment()
    {
        val loadingScreenVw: View get() = fm_main_vw_loading_screen	//From XML
    
        val vm: MyVM by lazy {                                //Problem a1
            MyVM(
                vmDidSummonLoadingScreen = {                  //Problem a0
                    loadingScreenVw.visibility = View.VISIBLE
                },
                vmDidDismissLoadingScreen = {                 //Problem a0
                    loadingScreenVw.visibility = View.GONE
                }
            )
        }
    
        override fun onCreate(...)
        {
            super.onCreate(...)
            vm.doAFlip()
        }
    }
    Problems: a0: The lambdas will leak the instance of FMMain since the lambdas reference a property of FMMain thereby implicitly capturing it. a1: Assuming the lambdas don’t leak, when the device rotates, the UI dies and so does the VM. There is the Android Component Library ViewModel class that solves this, but that can’t be used in the shared module. iOS is excluded because this architecture works pretty well since Swift has [weak self] to prevent strong captures. So my questions are: 1: How does one release lambda captures? 1.1: If not possible, what is the best way to let the UI layer know that an event happened in the VM without using any external libs/dependencies (just idomatic kotlin)? 2: Only in Android, I am considering wrapping my VM with an object that inherits from Android’s Architecture Components’ ViewModel (possibly generic idk if I can do that yet). Is there a better alternative in your opinion? 3. In your opinion, should VMs be injected into Fragments, or should Fragments instantiate and own their own VMs?
    x
    alex009
    +1
    7 replies
    Copy to Clipboard
  • n

    napperley

    2 years ago
    Is it possible to generate reference documentation for a MPP library?
    n
    y
    +1
    3 replies
    Copy to Clipboard
  • Big Chungus

    Big Chungus

    2 years ago
    When using maven-publish plugin with MPP project, how do i publish transitive dependencies metadata? e.g.: I have module A and core module B that depends on A. I publish both and include module B to some project, but module A is not added as module B dependency to that project
    Big Chungus
    ian.shaun.thomas
    2 replies
    Copy to Clipboard
  • Nikky

    Nikky

    2 years ago
    does anyone know of a multiplatform UI abstraction layer? in particular something that allows me to create the same tabs, textfields, dropdowns, etc in html/js and tornadofx ? (and potentially android/iOS later)
    Nikky
    Dominaezzz
    6 replies
    Copy to Clipboard
  • k

    Konstantin Petrukhnov

    2 years ago
    What is suggested way of creating singletons that will work on ios/jvm?
    k
    s
    +2
    22 replies
    Copy to Clipboard
  • Kris Wong

    Kris Wong

    2 years ago
    man I can't believe I waited this long to switch my MPP build scripts to Kotlin DSL. so much nicer.
    Kris Wong
    1 replies
    Copy to Clipboard
  • kpgalligan

    kpgalligan

    2 years ago
    Any good multiplatform examples with Kotlin dsl instead of Groovy? I’ve been holding off on the conversion but it’s probably time.
    kpgalligan
    Kris Wong
    +4
    11 replies
    Copy to Clipboard
  • Kris Wong

    Kris Wong

    2 years ago
    has anyone had issues with this:
    apply(plugin = "com.android.library")
    in build scripts written in Kotlin DSL?
    Kris Wong
    alex009
    +1
    24 replies
    Copy to Clipboard
  • Sujit

    Sujit

    2 years ago
    Is there a blog post or sample app utilizing gradle kotlin DSL to publish KMP library (android and iOS) to bintray?
    Sujit
    Kris Wong
    +4
    15 replies
    Copy to Clipboard
  • ankushg

    ankushg

    2 years ago
    Also -- just wanted to confirm that
    @OptionalExpectation
    only works for annotations at the moment, and doesn't automatically create no-op implementations for interfaces, right?
    ankushg
    Dominaezzz
    2 replies
    Copy to Clipboard