-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major Update: iOS app now uses native NavigationLink and has default …
…navigation animation; added Desktop app
- Loading branch information
1 parent
d316316
commit 0323eab
Showing
66 changed files
with
1,198 additions
and
208 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
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
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 |
---|---|---|
|
@@ -3,5 +3,5 @@ plugins { | |
`kotlin-dsl` | ||
} | ||
repositories { | ||
jcenter() | ||
mavenCentral() | ||
} |
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
Empty file.
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,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="eu.baroncelli.dkmpsample.shared"/> |
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,48 @@ | ||
import org.jetbrains.compose.compose | ||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
id("org.jetbrains.compose") version Versions.jetbrainsCompose | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") | ||
} | ||
|
||
kotlin { | ||
jvm { | ||
compilations.all { | ||
kotlinOptions.jvmTarget = "11" | ||
} | ||
} | ||
sourceSets { | ||
all { | ||
languageSettings.apply { | ||
useExperimentalAnnotation("kotlinx.coroutines.ExperimentalCoroutinesApi") | ||
useExperimentalAnnotation("androidx.compose.ui.ExperimentalComposeUiApi") | ||
useExperimentalAnnotation("androidx.compose.foundation.ExperimentalFoundationApi") | ||
} | ||
} | ||
val jvmMain by getting { | ||
dependencies { | ||
implementation(project(":shared")) | ||
implementation(compose.desktop.currentOs) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
compose.desktop { | ||
application { | ||
mainClass = "MainKt" | ||
nativeDistributions { | ||
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) | ||
packageName = "jvm" | ||
packageVersion = "1.0.0" | ||
} | ||
} | ||
} |
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
desktopApp/src/jvmMain/kotlin/composables/MainComposable.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,15 @@ | ||
package eu.baroncelli.dkmpsample.desktop.composables.navigation | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.DKMPViewModel | ||
|
||
@Composable | ||
fun MainComposable(model: DKMPViewModel) { | ||
val appState by model.stateFlow.collectAsState() | ||
println("D-KMP-SAMPLE: recomposition Index: "+appState.recompositionIndex.toString()) | ||
val dkmpNav = appState.getNavigation(model) | ||
dkmpNav.Router() | ||
} | ||
|
38 changes: 38 additions & 0 deletions
38
desktopApp/src/jvmMain/kotlin/composables/navigation/Router.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,38 @@ | ||
package eu.baroncelli.dkmpsample.desktop.composables.navigation | ||
|
||
import androidx.compose.foundation.layout.BoxWithConstraints | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.saveable.rememberSaveableStateHolder | ||
import androidx.compose.ui.unit.dp | ||
import eu.baroncelli.dkmpsample.desktop.composables.navigation.templates.OnePane | ||
import eu.baroncelli.dkmpsample.desktop.composables.navigation.templates.TwoPane | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.* | ||
|
||
@Composable | ||
fun Navigation.Router() { | ||
|
||
val screenUIsStateHolder = rememberSaveableStateHolder() | ||
|
||
val twopaneWidthThreshold = 1000.dp | ||
BoxWithConstraints() { | ||
if (maxWidth < maxHeight || maxWidth<twopaneWidthThreshold) { | ||
OnePane(screenUIsStateHolder) | ||
} else { | ||
TwoPane(screenUIsStateHolder) | ||
} | ||
} | ||
|
||
screenStatesToRemove.forEach { | ||
screenUIsStateHolder.removeState(it.URI) | ||
println("D-KMP: removed UI screen "+it.URI) | ||
} | ||
|
||
/* | ||
if (!only1ScreenInBackstack) { | ||
BackHandler { // catching the back button to update the DKMPViewModel | ||
exitScreen() | ||
} | ||
} | ||
*/ | ||
|
||
} |
53 changes: 53 additions & 0 deletions
53
desktopApp/src/jvmMain/kotlin/composables/navigation/ScreenPicker.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,53 @@ | ||
package eu.baroncelli.dkmpsample.desktop.composables.navigation | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.runtime.Composable | ||
import eu.baroncelli.dkmpsample.desktop.composables.screens.countrydetail.CountryDetailScreen | ||
import eu.baroncelli.dkmpsample.desktop.composables.screens.countrieslist.CountriesListScreen | ||
import eu.baroncelli.dkmpsample.desktop.composables.screens.countrieslist.CountriesListTwoPaneDefaultDetail | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.Navigation | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.ScreenIdentifier | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.Screen.* | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.countrieslist.selectFavorite | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.countrydetail.CountryDetailParams | ||
|
||
|
||
@Composable | ||
fun Navigation.ScreenPicker( | ||
screenIdentifier: ScreenIdentifier | ||
) { | ||
|
||
when (screenIdentifier.screen) { | ||
|
||
CountriesList -> | ||
CountriesListScreen( | ||
countriesListState = stateProvider.get(screenIdentifier), | ||
onListItemClick = { navigate(CountryDetail, CountryDetailParams(countryName = it)) }, | ||
onFavoriteIconClick = { events.selectFavorite(countryName = it) }, | ||
) | ||
|
||
CountryDetail -> | ||
CountryDetailScreen( | ||
countryDetailState = stateProvider.get(screenIdentifier) | ||
) | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
|
||
@Composable | ||
fun Navigation.TwoPaneDefaultDetail( | ||
screenIdentifier: ScreenIdentifier | ||
) { | ||
|
||
when (screenIdentifier.screen) { | ||
|
||
CountriesList -> | ||
CountriesListTwoPaneDefaultDetail() | ||
|
||
else -> Box{} | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
desktopApp/src/jvmMain/kotlin/composables/navigation/bars/Level1BottomBar.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,39 @@ | ||
package eu.baroncelli.dkmpsample.desktop.composables.screens.countrieslist | ||
|
||
import androidx.compose.material.Icon | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.BottomAppBar | ||
import androidx.compose.material.BottomNavigationItem | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Menu | ||
import androidx.compose.material.icons.filled.Star | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.unit.sp | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.Navigation | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.ScreenIdentifier | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.Level1Navigation | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.countrieslist.CountriesListType | ||
|
||
|
||
// this is the bottom horizontal navigation bar for 1-Pane visualization | ||
// (used by small devices and in Portrait mode) | ||
|
||
@Composable | ||
fun Navigation.Level1BottomBar( | ||
selectedTab: ScreenIdentifier | ||
) { | ||
BottomAppBar(content = { | ||
BottomNavigationItem( | ||
icon = { Icon(Icons.Default.Menu, "ALL") }, | ||
label = { Text("All Countries", fontSize = 13.sp) }, | ||
selected = selectedTab.URI == Level1Navigation.AllCountries.screenIdentifier.URI, | ||
onClick = { navigateByLevel1Menu(Level1Navigation.AllCountries) } | ||
) | ||
BottomNavigationItem( | ||
icon = { Icon(Icons.Default.Star, "FAVORITES") }, | ||
label = { Text("Favourites", fontSize = 13.sp) }, | ||
selected = selectedTab.URI == Level1Navigation.FavoriteCountries.screenIdentifier.URI, | ||
onClick = { navigateByLevel1Menu(Level1Navigation.FavoriteCountries) } | ||
) | ||
}) | ||
} |
73 changes: 73 additions & 0 deletions
73
desktopApp/src/jvmMain/kotlin/composables/navigation/bars/Level1NavigationRail.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,73 @@ | ||
package eu.baroncelli.dkmpsample.desktop.composables.navigation.templates | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.material.* | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Menu | ||
import androidx.compose.material.icons.filled.Star | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.Navigation | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.ScreenIdentifier | ||
import eu.baroncelli.dkmpsample.shared.viewmodel.screens.Level1Navigation | ||
|
||
|
||
// this is the left vertical navigation bar for 2-Pane visualization | ||
// (used by bigger devices in landscape mode) | ||
|
||
@Composable | ||
fun Navigation.Level1NavigationRail( | ||
selectedTab: ScreenIdentifier | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.fillMaxHeight() | ||
.background(MaterialTheme.colors.primary), | ||
verticalArrangement = Arrangement.Center | ||
) { | ||
NavigationRailItem( | ||
icon = { Icon(Icons.Default.Menu, "ALL") }, | ||
label = { Text("All Countries", fontSize = 13.sp) }, | ||
selected = selectedTab.URI == Level1Navigation.AllCountries.screenIdentifier.URI, | ||
onClick = { navigateByLevel1Menu(Level1Navigation.AllCountries) } | ||
) | ||
NavigationRailItem( | ||
icon = { Icon(Icons.Default.Star, "FAVORITES") }, | ||
label = { Text("Favourites", fontSize = 13.sp) }, | ||
selected = selectedTab.URI == Level1Navigation.FavoriteCountries.screenIdentifier.URI, | ||
onClick = { navigateByLevel1Menu(Level1Navigation.FavoriteCountries) } | ||
) | ||
} | ||
} | ||
|
||
|
||
|
||
@Composable | ||
fun ColumnScope.NavigationRailItem(icon : @Composable () -> Unit , label : @Composable () -> Unit, selected : Boolean, onClick : () -> Unit) { | ||
CompositionLocalProvider( | ||
LocalContentColor provides if (selected) MaterialTheme.colors.background else MaterialTheme.colors.primaryVariant | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.clickable { onClick() } | ||
.padding(top = 25.dp, bottom = 25.dp) | ||
) { | ||
Column( | ||
modifier = Modifier | ||
.fillMaxWidth(), | ||
horizontalAlignment = Alignment.CenterHorizontally, | ||
) { | ||
icon() | ||
label() | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.