https://kotlinlang.org logo
Join SlackCommunities
Powered by
# orbit-mvi
  • g

    Guilherme Delgado

    12/09/2023, 8:34 PM
    Hello guys! Do you plan to add wasm as a target? 😇
    m
    • 2
    • 3
  • j

    Jacob Rhoda

    01/19/2024, 4:16 PM
    Is there a way to have an intent be cancelled if another call to the intent comes in after it starts running? I am implementing a search text field and finding that it will execute a lot of requests.
    g
    a
    • 3
    • 6
  • j

    Jacob Rhoda

    01/22/2024, 7:13 PM
    I’m just curious, is there work ongoing in the background to support the iOS use-case better? I have been keeping an eye on things and haven’t seen much progress. Just curious where things are at.
    ➕ 2
  • m

    Mikolaj

    01/24/2024, 2:31 PM
    Hello! I am considering Transition from Orbit-MVI to Kotlin StateFlow in KMP Project. Initially, I incorporated the testing framework and side effects, but with time I tried to make things as simple as possible. I've reached a point where I use Orbit only for updating the data flow. Could you help me understand what I might lose by forgoing Orbit in this context?
    ➕ 1
    g
    m
    • 3
    • 4
  • m

    Mikolaj Leszczynski

    02/16/2024, 2:20 PM
    Hey all - sorry for the delayed response. I was on holiday. Since there have been a few questions regarding Orbit's iOS/KMP support here's the current context: 1. We have very limited time to work on Orbit due to work/family/health obligations so we are focusing on core functionality and KMP support. We are very careful about what features/projects we take on. 2. Please assume no further work will be done on the Orbit Swift plugin. We consider improved Swift support to be out of scope due to the amount of work required and the fact KMP support has now vastly improved and there are already some much better alternatives, such as the excellent SKIE project. 3. We will consider working on better KMP support where Orbit is still rough around the edges even after applying other patterns like KMP ViewModels, SKIE. Please file tickets with specific improvement ideas, since we have limited opportunities to explore KMP on our own. 4. We are aiming to provide some guidance around KMP extension projects to consider when using Orbit in iOS. In the meantime, here is a number of projects to consider: a. SKIE b. https://moko.icerock.dev c. https://github.com/rickclephas/KMP-NativeCoroutines d. https://github.com/rickclephas/KMM-ViewModel e. Thanks to @Guilherme Delgado for the last two. Note that we've done limited research ourselves, so please use your own judgement here. Hopefully this anwers your questions @Jacob Rhoda
    ❤️ 5
    👍 1
    g
    j
    • 3
    • 39
  • m

    Mikolaj Leszczynski

    02/21/2024, 11:02 AM
    https://android-review.googlesource.com/c/platform/frameworks/support/+/2965063
    🙏 3
    😲 1
    🎉 1
    🤯 1
  • m

    Mikolaj Leszczynski

    02/21/2024, 11:02 AM
    ☝️ Google making Android ViewModel's KMP
  • g

    Guilherme Delgado

    02/26/2024, 10:51 PM
    https://www.composables.com/state-of-compose
    👀 1
    ❤️ 1
  • g

    Guilherme Delgado

    02/26/2024, 10:51 PM
    Screenshot 2024-02-26 at 22.51.37.png
  • v

    vicky7230

    03/14/2024, 12:17 PM
    hi I am new to mvi orbit. Is there any doc which explains how intent, reduce work under the hood?
  • v

    vicky7230

    03/15/2024, 7:09 AM
    is
    reduce
    thread safe?
    👌 1
    a
    • 2
    • 4
  • v

    vicky7230

    03/16/2024, 10:45 AM
    Hi @Guilherme Delgado I read your article here: https://proandroiddev.com/managing-the-ui-state-by-using-a-finite-state-machine-and-mvi-architecture-36d84056c616 I am trying to implement same in my sample project
    g
    • 2
    • 9
  • g

    Guilherme Delgado

    05/09/2024, 3:14 PM
    Hello all 👋 Following recent news about Google officially supporting KMP in androidx.ViewModel and androidx.Lifecycle, I was wondering how OrbitMvi-Multiplatform could embrace this update in order to finally become KMP ready 🤔 Any hint @Mikolaj Leszczynski @appmattus about how difficult could this migration be?
  • g

    Guilherme Delgado

    05/09/2024, 3:15 PM
    Maybe just changing the libraries imports? 😅 it would be awesome
    m
    a
    • 3
    • 43
  • a

    appmattus

    05/12/2024, 5:07 PM
    Good job on the article @Guilherme Delgado :) I do quite like that definition of what it means to be native and had never quite found the right words to describe it myself. It’s definitely one of the reasons I like Kotlin native and having written a cryptographic hashing library and seeing no real difference in performance from the same algorithms in C highlighted this to me
    ❤️ 1
    K 1
    g
    c
    • 3
    • 3
  • k

    Kshitij Patil

    06/05/2024, 11:05 AM
    orbit uses
    runBlocking { }
    in it's
    intent { }
    extension function. runBlocking can throw
    InterruptedException
    when thread being used for executing the coroutine gets interrupted for some reason. This results in a runtime crash. Is there any way to get around this crash?
  • t

    twisterrob

    07/06/2024, 9:41 PM
    Release https://github.com/orbit-mvi/orbit-mvi/releases/tag/9.0.0 migration guide feedback
    m
    • 2
    • 14
  • s

    stefanus ayudha

    07/16/2024, 12:48 PM
    Hi, i create simple login screen using orbit mvi, how to prevent the whole screen recomposed when new state is emitted? In my case i update the state when user typing their email and password
  • s

    stefanus ayudha

    07/16/2024, 12:49 PM
    The Screen:
    Copy code
    @Composable
    fun LoginScreen(
        /** States **/
        viewModel: LoginViewModel = viewModel(),
        onSuccess: (LoginResult) -> Unit,
        onNavigateToRegistration: () -> Unit,
    ) {
        val context = LocalContext.current
        viewModel.collectSideEffect {
            when (it) {
                is LoginScreenEffect.LoginSuccess -> onSuccess.invoke(LoginResult())
                is LoginScreenEffect.ShowToastError -> Toast.makeText(
                    context,
                    it.message,
                    Toast.LENGTH_SHORT
                ).show()
            }
        }
    
        Box {
            Column(modifier = Modifier.fillMaxSize()) {
                Text(text = "Login Screen")
                val state by viewModel.collectAsState()
                val showLoading by remember(state.showLoginLoading) { derivedStateOf { state.showLoginLoading } }
                if (showLoading)
                    CircularProgressIndicator()
    
                Spacer(modifier = Modifier.weight(1f))
    
                val emailError by remember(state.emailError) { derivedStateOf { state.emailError } }
                val passwordError by remember(state.passwordError) { derivedStateOf { state.passwordError } }
                LoginForm(
                    emailError = emailError,
                    passwordError = passwordError,
                    onEmailInput = { viewModel.updateEmail(it) },
                    onPasswordInput = { viewModel.updatePassword(it) }
                )
    
                val enableButton by remember(state) { derivedStateOf { state.enableSubmitButton } }
                Button(
                    onClick = { viewModel.submitLogin() },
                    enabled = enableButton
                ) {
                    Text(text = "Login")
                }
    
                Spacer(modifier = Modifier.height(24.dp))
    
                Button(
                    onClick = { onNavigateToRegistration.invoke() },
                    colors = ButtonDefaults.filledTonalButtonColors()
                ) {
                    Text(text = "Go To Registration")
                }
    
                Spacer(modifier = Modifier.weight(1f))
            }
        }
    }
    
    @Composable
    fun LoginForm(
        emailError: String,
        passwordError: String,
        onEmailInput: (String) -> Unit,
        onPasswordInput: (String) -> Unit,
    ) {
        Column {
            var emailBuffer by remember { mutableStateOf("") }
            TextField(
                value = emailBuffer,
                onValueChange = {
                    emailBuffer = it
                    onEmailInput.invoke(it)
                },
                isError = emailError.isNotBlank(),
            )
            if (emailError.isNotBlank())
                Text(text = emailError, color = MaterialTheme.colorScheme.error)
    
            var passwordBuffer by remember { mutableStateOf("") }
            TextField(
                value = passwordBuffer,
                onValueChange = {
                    passwordBuffer = it
                    onPasswordInput.invoke(it)
                },
                isError = passwordError.isNotBlank()
            )
            if (passwordError.isNotBlank())
                Text(text = passwordError, color = MaterialTheme.colorScheme.error)
        }
    }
    The State:
    Copy code
    @Immutable
    @optics
    data class LoginScreenSate(
        val email: String = "",
        val password: String = "",
        val submitLoginDataState: VmState<LoginCredential> = VmIdle()
    ) {
        companion object
    
        val showLoginLoading: Boolean = submitLoginDataState is VmProcessing
        val emailError: String
            get() = when {
                !email.matches(EmailPattern.toRegex()) -> "Format Salah"
                else -> ""
            }
        val passwordError: String = when {
            password.length < 10 -> "Pasword kurang panjang"
            else -> ""
        }
        val enableSubmitButton =
            emailError.isBlank() && passwordError.isBlank() && submitLoginDataState.fold(ifProcessing = { false }) { true }
    }
    The ViewModel
    Copy code
    class LoginViewModel : ContainerHost<LoginScreenSate, LoginScreenEffect>, ViewModel() {
    
        override val container: Container<LoginScreenSate, LoginScreenEffect> =
            container(LoginScreenSate())
    
        fun updateEmail(email: String) = intent {
            reduce {
                val lens = LoginScreenSate.email::set
                lens(state, email)
            }
        }
    
        fun updatePassword(password: String) = intent {
            reduce {
                val lens = LoginScreenSate.password
                lens.set(state, password)
            }
        }
    
        fun submitLogin() = intent {
            val lens = LoginScreenSate.submitLoginDataState
    
            reduce { lens.set(state, VmProcessing()) }
    
            // do login stuff
            val loginResultState = runBlocking {
                delay(3000)
                VmSuccess(LoginCredential())
            }
    
            // assume success
            reduce { lens.set(state, loginResultState) }
    
            postSideEffect(LoginScreenEffect.LoginSuccess(loginResultState.data))
        }
    }
  • s

    stefanus ayudha

    07/16/2024, 12:50 PM
    when user typing, the email state will be forwarded to viewmodel. and everytime user typing the state is reduced. since the state is on top of LoginScreen function, the whole page is recomposed. how to prevent it?
    j
    • 2
    • 2
  • g

    Guilherme Delgado

    09/13/2024, 9:53 AM
    https://android-review.googlesource.com/c/platform/frameworks/support/+/3176247
    🎉 1
  • m

    Mikolaj Leszczynski

    10/01/2024, 9:46 AM
    orbit multiplatform Some exciting news to share today Orbit has been selected as one of the winners of the 2024 Kotlin Foundation grants. We'd like to take this opportunity to thank everyone in the Orbit community. We wouldn't be here without you all ❤️
    🙌 8
    👍 2
    K 4
    pepeparty 2
    ❤️ 4
    g
    j
    • 3
    • 2
  • a

    appmattus

    10/02/2024, 11:39 AM
    set the channel description: Discussions for the Orbit Multiplatform library
  • a

    appmattus

    10/02/2024, 1:56 PM
    As a follow up to the Kotlin Foundation announcement I wrote a brief article about some of the journey with Orbit - interesting to look back on the syntax of the earlier versions and how it has changed with time. https://appmattus.medium.com/6b949cf8133e
    👏 5
  • l

    Laurence Muller

    10/03/2024, 1:04 PM
    👋 Was wondering, what would it take to make orbit run in kotlin native (target
    macosX64
    &
    macosArm64
    )? Are there specific dependencies that need to be made compatible? I got a macos desktop app using compose that builds in kotlin native (not jvm) and would love to use orbit in it
    a
    • 2
    • 3
  • d

    dave08

    10/07/2024, 2:03 PM
    Just looking back at Orbit... and I'm wondering what's the advantage over just having a simple channel for side effects and a state flow for ui state in the view model?
    ➕ 1
    g
    m
    • 3
    • 2
  • d

    Daniel (danflo)

    10/25/2024, 6:46 PM
    How should the first data download with orbit-mvi be? Something like this

    https://www.youtube.com/watch?v=mNKQ9dc1knI▾

    https://proandroiddev.com/loading-initial-data-in-launchedeffect-vs-viewmodel-f1747c20ce62
    m
    • 2
    • 1
  • k

    Krzysiek Skorcz

    11/26/2024, 11:39 AM
    Hi, I have general question about architecting an app with Orbit-MVI. Do you typically define one State subclass (an instance) or many for different parts of your app? I see both pros and cons of using one vs many States. One of the pros for single State is that there are parts that can be shared among many views. How to implement Shared State that will live in application scope and be accessible from smaller scopes?
    m
    • 2
    • 1
  • s

    Sonu Sourav

    12/04/2024, 1:16 PM
    What happens if I execute the following lines inside viewmodel as below:
    Copy code
    fun example() {
                intent {
                    fun1()
                }
                Log.d("sonusourav","intent 1")
                intent {
                    fun2()
                }
                Log.d("sonusourav","intent 2")
    
                intent {
                    fun3()
                }
                Log.d("sonusourav","intent 3")
            }
    Will the three functions be launched in parallel like launch? Sorry if this is very naive question, couldn't found a clear answer for this written anywhere
    m
    v
    • 3
    • 5
  • s

    Stew Boling

    03/03/2025, 1:53 AM
    Is there any example code on how to subscribe to states and side-effects using a KMP ViewModel in Swift?
    g
    v
    a
    • 4
    • 8