Sunil Kumar
12/28/2023, 8:17 AMtargets
.filterIsInstance<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>()
.filter { it.konanTarget.family == org.jetbrains.kotlin.konan.target.Family.IOS }
.forEach {
it.binaries.framework {
export("com.arkivanov.decompose:decompose:3.0.0-alpha04")
export("com.arkivanov.essenty:lifecycle:1.3.0")
}
}
But while i am opening the iOS app in XCode, its not able to resolve RootComponent and all other decompose library classesSunil Kumar
12/28/2023, 8:40 AMerror: Following dependencies exported in the debugFramework binary are not specified as API-dependencies of a corresponding source set:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':shared:linkDebugFrameworkIosSimulatorArm64'.
> Following dependencies exported in the debugFramework binary are not specified as API-dependencies of a corresponding source set:
Files: [/Users/sunil/.gradle/caches/modules-2/files-2.1/com.arkivanov.essenty/lifecycle-iossimulatorarm64/1.3.0/661134f843b9fde5208c897822a737541fc5b758/lifecycle.klib]
Files: [/Users/sunil/.gradle/caches/modules-2/files-2.1/com.arkivanov.essenty/lifecycle-iossimulatorarm64/1.3.0/661134f843b9fde5208c897822a737541fc5b758/lifecycle.klib]
Please add them in the API-dependencies and rerun the build.
Arkadii Ivanov
12/28/2023, 9:47 AMSunil Kumar
12/28/2023, 9:59 AM/Users/sunil/AndroidStudioProjects/KMPProjectWithoutSharedUi/iosApp/iosApp/RootView.swift:13:15: error: cannot find type 'RootComponent' in scope
let root: RootComponent
^~~~~~~~~~~~~
/Users/sunil/AndroidStudioProjects/KMPProjectWithoutSharedUi/iosApp/iosApp/RootView.swift:16:9: error: cannot find 'StackView' in scope
StackView(
^~~~~~~~~
/Users/sunil/AndroidStudioProjects/KMPProjectWithoutSharedUi/iosApp/iosApp/RootView.swift:17:25: error: cannot find 'StateValue' in scope
stackValue: StateValue(root.stack),
^~~~~~~~~~
/Users/sunil/AndroidStudioProjects/KMPProjectWithoutSharedUi/iosApp/iosApp/RootView.swift:28:65: error: cannot find 'ListView' in scope
case let child as RootComponentChild.ListChild: ListView(child.component)
^~~~~~~~
/Users/sunil/AndroidStudioProjects/KMPProjectWithoutSharedUi/iosApp/iosApp/RootView.swift:29:68: error: cannot find 'DetailsView' in scope
case let child as RootComponentChild.DetailsChild: DetailsView(child.component)
^~~~~~~~~~~
warning: Run script build phase 'Compile Kotlin' will be run during every build because it does not specify any outputs. To address this warning, either add output dependencies to the script phase, or configure it to run in every build by unchecking "Based on dependency analysis" in the script phase. (in target 'iosApp' from project 'iosApp')
** BUILD FAILED **
Still Its not able to resolve decompose in ios projectArkadii Ivanov
12/28/2023, 10:05 AMSunil Kumar
12/28/2023, 10:29 AMSunil Kumar
12/28/2023, 10:38 AMArkadii Ivanov
12/28/2023, 10:49 AMswitch
on stack.active.instance
. Or write something your own.Sunil Kumar
12/28/2023, 11:44 AMSunil Kumar
12/29/2023, 4:51 AMstruct RootView: View {
let root: RootComponent
var body: some View {
StackView(
stackValue: StateValue(root.stack),
getTitle: {
switch $0 {
case is RootComponentChild.ListChild: return "List"
case is RootComponentChild.DetailChild: return "Details"
default: return ""
}
},
onBack: { toIndex in
root.onBackClicked()
},
childContent: {
switch $0 {
case let child as RootComponentChild.ListChild: ListView(child.component)
case let child as RootComponentChild.DetailChild: DetailView(child.component)
default: EmptyView()
}
}
)
}
}
and this is my RootComponent from shared module:-
package root
import com.arkivanov.decompose.ComponentContext
import com.arkivanov.decompose.router.stack.ChildStack
import com.arkivanov.decompose.router.stack.StackNavigation
import com.arkivanov.decompose.router.stack.childStack
import com.arkivanov.decompose.router.stack.pop
import com.arkivanov.decompose.router.stack.push
import com.arkivanov.decompose.value.Value
import data.RandomUser
import detail.DefaultDetailComponent
import detail.DetailComponent
import kotlinx.serialization.Serializable
import list.DefaultListComponent
import list.ListComponent
interface RootComponent {
val stack: Value<ChildStack<*, Child>>
fun onBackClicked()
// Defines all possible child components
sealed class Child {
class ListChild(val component: ListComponent) : Child()
class DetailChild(val component: DetailComponent) : Child()
}
}
class DefaultRootComponent(
componentContext: ComponentContext,
) : RootComponent, ComponentContext by componentContext {
private val navigation = StackNavigation<Config>()
override val stack: Value<ChildStack<*, RootComponent.Child>> =
childStack(
source = navigation,
serializer = Config.serializer(),
initialConfiguration = Config.List, // The initial child component is List
handleBackButton = true, // Automatically pop from the stack on back button presses
childFactory = ::child,
)
//This will decide which component to show according to currently pushed config
private fun child(config: Config, componentContext: ComponentContext): RootComponent.Child =
when (config) {
is Config.List -> RootComponent.Child.ListChild(listComponent(componentContext))
is Config.Details -> RootComponent.Child.DetailChild(
detailComponent(
componentContext,
config
)
)
}
private fun listComponent(componentContext: ComponentContext): ListComponent =
DefaultListComponent(
componentContext = componentContext,
onItemSelected = { item: RandomUser -> // Supply dependencies and callbacks
println("push detail")
navigation.push(Config.Details(item = item)) // Push the details component
},
)
private fun detailComponent(componentContext: ComponentContext, config: Config.Details): DetailComponent =
DefaultDetailComponent(
componentContext = componentContext,
item = config.item, // Supply arguments from the configuration
onBack = ::onBackClicked, // Pop the details component
)
override fun onBackClicked() {
navigation.pop()
}
@Serializable // kotlin-serialize plugin must be applied if you are targeting Android
private sealed interface Config {
@Serializable
data object List : Config
@Serializable
data class Details(val item: RandomUser) : Config
}
}
And i can see in logs, while clicking on list item, its printing log "push detail" before navigation.push which i have printed in onItemSelected callback. But view is not changing in StackView in iOS app. @Arkadii Ivanov Any idea what can be the issueArkadii Ivanov
12/29/2023, 9:46 AMSunil Kumar
12/29/2023, 11:10 AMArkadii Ivanov
12/29/2023, 11:15 AMSunil Kumar
12/29/2023, 12:00 PMArkadii Ivanov
12/29/2023, 12:10 PMSunil Kumar
12/29/2023, 12:14 PMSunil Kumar
12/29/2023, 12:44 PMself.cancellation = value.observe { [weak self] value, _ in self?.value = value } as? Cancellation
I have attached the errors screenshot.
And i corrected them like this:-
self.cancellation = value.observe(\.value) { [weak self] newValue, _ in
self?.value = newValue as! T
} as? any Cancellation
Not sure if this is correct or not, As i have only basic knowledge in iOS
SO not sure if this issue can be causing the navigation state changes to be not detectedSunil Kumar
12/29/2023, 12:49 PMArkadii Ivanov
12/29/2023, 12:50 PMSunil Kumar
12/29/2023, 12:51 PM3.0.0-alpha04
Arkadii Ivanov
12/29/2023, 12:52 PMArkadii Ivanov
12/29/2023, 12:56 PMSunil Kumar
12/29/2023, 1:20 PMArkadii Ivanov
12/29/2023, 1:26 PMSunil Kumar
12/29/2023, 1:36 PMArkadii Ivanov
12/29/2023, 1:39 PMArkadii Ivanov
12/29/2023, 1:39 PMArkadii Ivanov
12/29/2023, 1:39 PMArkadii Ivanov
12/29/2023, 1:41 PMSunil Kumar
12/29/2023, 1:43 PMArkadii Ivanov
12/29/2023, 1:44 PMSunil Kumar
12/29/2023, 1:45 PMSunil Kumar
12/29/2023, 1:46 PMArkadii Ivanov
12/29/2023, 1:51 PMArkadii Ivanov
12/29/2023, 1:53 PMSunil Kumar
12/29/2023, 1:55 PMArkadii Ivanov
12/29/2023, 2:02 PMArkadii Ivanov
12/29/2023, 2:02 PMArkadii Ivanov
12/29/2023, 2:02 PMArkadii Ivanov
12/29/2023, 2:03 PMSunil Kumar
12/29/2023, 2:36 PM