can anyone please guide me or provide me resource ...
# multiplatform
k
can anyone please guide me or provide me resource on how to create a KMP project with native UI for Android and iOS, I am confused that should I share the viewmodel or should I keep that native also. And if I do keep my viewmodel native then will I be able to create native viewmodel for iOS equivalent to a viewmodel which contains functions like this -
Copy code
viewModelScope.launch {
    combine(
        currentLevelManager.currentLevel,
        prefRepository.userData
    ) { level, userData ->
        level to userData.userLocation
    }.collect { (level, location) ->
        val currentState = _uiState.value
        val shouldRefresh = currentState.postLevel != level || 
                           (currentState.postsFlow == null && location != null)
        
        if (shouldRefresh || currentState.postsFlow == null) {
            updateState {
                it.copy(
                    postLevel = level,
                    postsFlow = feedRepository.getPagedPosts(
                        level,
                        location,
                        forceRefresh = false // Use cache if available
                    ).cachedIn(viewModelScope)
                )
            }
            observeActiveIssues(level)
        }
    }
}
or should I refactor the viewmodel accordingly ? What is the standard way of having native UI in KMP ?
a
Hello there 🙂 It's a common practice to share viewmodels. If you prefer androidx.viewmodels - there is a great library that solves all the main headaches of managing common VMs on the ios side, allowing one to use native swift tools to interact with common VM. Alternatively - there is another great library aiming to solve the same problem more generally and that contains couple more features.
There is a documentation on that topic on the official documentation - https://kotlinlang.org/docs/multiplatform/compose-viewmodel.html