-
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.
Merge pull request #3 from stslex/dev
init Build system
- Loading branch information
Showing
39 changed files
with
469 additions
and
298 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 |
---|---|---|
@@ -1,9 +1,36 @@ | ||
import androidx.compose.runtime.Composable | ||
import com.stslex.core.core.coreModule | ||
import com.stslex.core.ui.theme.AppTheme | ||
import com.stslex.feature.home.di.homeModule | ||
import di.appModule | ||
import org.koin.compose.KoinApplication | ||
import org.koin.dsl.KoinAppDeclaration | ||
|
||
@Composable | ||
fun App() { | ||
AppTheme { | ||
InitialApp() | ||
SetupKoin { | ||
AppTheme { | ||
InitialApp() | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun SetupKoin( | ||
content: @Composable () -> Unit | ||
) { | ||
KoinApplication( | ||
application = setupModules(), | ||
content = content | ||
) | ||
} | ||
|
||
private fun setupModules(): KoinAppDeclaration = { | ||
modules( | ||
listOf( | ||
appModule, | ||
coreModule, | ||
homeModule, | ||
) | ||
) | ||
} |
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,7 +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 com.stslex.feature.home.HomeScreen | ||
import androidx.compose.ui.Modifier | ||
import cafe.adriel.voyager.navigator.Navigator | ||
import com.stslex.feature.home.ui.HomeScreen | ||
|
||
@Composable | ||
fun InitialApp() { | ||
HomeScreen() | ||
} | ||
fun InitialApp( | ||
modifier: Modifier = Modifier | ||
) { | ||
Scaffold( | ||
modifier = modifier | ||
.fillMaxSize() | ||
.background(MaterialTheme.colorScheme.background) | ||
) { paddingValues -> | ||
Box( | ||
modifier = Modifier.fillMaxSize() | ||
.padding(paddingValues) | ||
) { | ||
Navigator(HomeScreen) | ||
} | ||
} | ||
} |
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()) | ||
) | ||
} | ||
} |
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
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
27 changes: 27 additions & 0 deletions
27
core/ui/src/androidMain/kotlin/com/stslex/core/ui/base/ViewModel.android.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,27 @@ | ||
package com.stslex.core.ui.base | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.CoroutineScope | ||
import org.koin.androidx.compose.koinViewModel | ||
import org.koin.androidx.viewmodel.dsl.viewModel | ||
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 com.stslex.core.ui.base.ViewModel as VM | ||
|
||
actual open class ViewModel : ViewModel() { | ||
|
||
actual val scope: CoroutineScope | ||
get() = viewModelScope | ||
} | ||
|
||
actual inline fun <reified T : VM> Module.viewModelDefinition( | ||
qualifier: Qualifier?, | ||
noinline definition: Definition<T>, | ||
): KoinDefinition<T> = viewModel(qualifier = qualifier, definition = definition) | ||
|
||
@Composable | ||
actual inline fun <reified T : VM> getViewModel(): T = koinViewModel() |
36 changes: 36 additions & 0 deletions
36
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 |
---|---|---|
@@ -0,0 +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 open class ViewModel() { | ||
|
||
val scope: CoroutineScope | ||
} | ||
|
||
expect inline fun <reified T : ViewModel> Module.viewModelDefinition( | ||
qualifier: Qualifier? = null, | ||
noinline definition: Definition<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
Oops, something went wrong.