-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial setup for Navigation and Store
- Loading branch information
Showing
23 changed files
with
253 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import cafe.adriel.voyager.navigator.Navigator | ||
import com.stslex.core.ui.navigation.AppNavigator | ||
import com.stslex.core.ui.navigation.AppScreen | ||
import com.stslex.feature.home.ui.HomeScreen | ||
import com.stslex.feature.home.ui.SecondScreen | ||
|
||
class AppNavigatorImpl( | ||
private val navigator: Lazy<Navigator> | ||
) : AppNavigator { | ||
|
||
override fun navigate( | ||
screen: AppScreen | ||
) { | ||
when (screen) { | ||
AppScreen.Home -> navigator.value.push(HomeScreen) | ||
is AppScreen.SecondScreen -> navigator.value.push(SecondScreen(screen.text)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.stslex.feature.home.HomeScreen | ||
import com.stslex.feature.home.di.homeModule | ||
import org.koin.core.context.startKoin | ||
import cafe.adriel.voyager.navigator.Navigator | ||
import com.stslex.feature.home.ui.HomeScreen | ||
|
||
@Composable | ||
fun InitialApp() { | ||
fun InitialApp( | ||
modifier: Modifier = Modifier | ||
) { | ||
Scaffold( | ||
modifier = Modifier | ||
modifier = modifier | ||
.fillMaxSize() | ||
.background(MaterialTheme.colorScheme.background) | ||
) { paddingValues -> | ||
HomeScreen() | ||
Box( | ||
modifier = Modifier.fillMaxSize() | ||
.padding(paddingValues) | ||
) { | ||
Navigator(HomeScreen) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package di | ||
|
||
import AppNavigatorImpl | ||
import com.stslex.core.ui.navigation.AppNavigator | ||
import org.koin.dsl.module | ||
|
||
val appModule = module { | ||
single<AppNavigator> { | ||
AppNavigatorImpl( | ||
lazyOf(get()) | ||
) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
core/core/src/commonMain/kotlin/com/stslex/core/core/CoreModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.stslex.core.core | ||
|
||
import org.koin.core.module.dsl.singleOf | ||
import org.koin.dsl.module | ||
|
||
val coreModule = module { | ||
singleOf<AppDispatcher>(::AppDispatcherImpl) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 21 additions & 2 deletions
23
core/ui/src/commonMain/kotlin/com/stslex/core/ui/base/ViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,36 @@ | ||
package com.stslex.core.ui.base | ||
|
||
import androidx.compose.runtime.Composable | ||
import cafe.adriel.voyager.navigator.LocalNavigator | ||
import cafe.adriel.voyager.navigator.currentOrThrow | ||
import kotlinx.coroutines.CoroutineScope | ||
import org.koin.compose.getKoin | ||
import org.koin.core.definition.Definition | ||
import org.koin.core.definition.KoinDefinition | ||
import org.koin.core.module.Module | ||
import org.koin.core.qualifier.Qualifier | ||
import org.koin.dsl.module | ||
|
||
expect class ViewModel { | ||
expect open class ViewModel() { | ||
|
||
val scope: CoroutineScope | ||
} | ||
|
||
expect inline fun <reified T : ViewModel> Module.viewModelDefinition( | ||
qualifier: Qualifier? = null, | ||
noinline definition: Definition<T> | ||
): KoinDefinition<T> | ||
): KoinDefinition<T> | ||
|
||
@Composable | ||
expect inline fun <reified T : ViewModel> getViewModel(): T | ||
|
||
@Composable | ||
inline fun <reified VM : ViewModel> rememberStore(): VM { | ||
val navigator = LocalNavigator.currentOrThrow | ||
val module = module { single { navigator } } | ||
getKoin().loadModules( | ||
modules = listOf(module), | ||
allowOverride = true, | ||
) | ||
return getViewModel() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
core/ui/src/commonMain/kotlin/com/stslex/core/ui/navigation/AppNavigator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.stslex.core.ui.navigation | ||
|
||
interface AppNavigator { | ||
|
||
fun navigate(screen: AppScreen) | ||
} |
8 changes: 8 additions & 0 deletions
8
core/ui/src/commonMain/kotlin/com/stslex/core/ui/navigation/AppScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.stslex.core.ui.navigation | ||
|
||
sealed interface AppScreen { | ||
|
||
data object Home : AppScreen | ||
|
||
data class SecondScreen(val text: String) : AppScreen | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 9 additions & 4 deletions
13
feature/home/src/commonMain/kotlin/com/stslex/feature/home/di/HomeModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
package com.stslex.feature.home.di | ||
|
||
import com.stslex.feature.home.domain.HomeInteractor | ||
import com.stslex.feature.home.domain.HomeInteractorImpl | ||
import com.stslex.core.ui.base.viewModelDefinition | ||
import com.stslex.feature.home.navigation.HomeScreenRouter | ||
import com.stslex.feature.home.navigation.HomeScreenRouterImpl | ||
import com.stslex.feature.home.ui.store.HomeScreenStore | ||
import org.koin.dsl.module | ||
|
||
val homeModule = module { | ||
single<HomeInteractor> { HomeInteractorImpl() } | ||
} | ||
viewModelDefinition { HomeScreenStore(get(), get()) } | ||
factory<HomeScreenRouter> { | ||
HomeScreenRouterImpl(get()) | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
feature/home/src/commonMain/kotlin/com/stslex/feature/home/domain/HomeInteractor.kt
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
feature/home/src/commonMain/kotlin/com/stslex/feature/home/navigation/HomeScreenRouter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.stslex.feature.home.navigation | ||
|
||
import com.stslex.core.ui.navigation.AppNavigator | ||
import com.stslex.core.ui.navigation.AppScreen | ||
import com.stslex.core.ui.navigation.Router | ||
import com.stslex.feature.home.ui.store.HomeScreenStoreComponent.Navigation | ||
|
||
interface HomeScreenRouter : Router<Navigation> | ||
|
||
class HomeScreenRouterImpl( | ||
private val navigator: AppNavigator | ||
) : HomeScreenRouter { | ||
|
||
override fun invoke(event: Navigation) { | ||
when (event) { | ||
is Navigation.SecondScreen -> navigator.navigate(AppScreen.SecondScreen(event.text)) | ||
} | ||
} | ||
} |
Oops, something went wrong.