-
-
Notifications
You must be signed in to change notification settings - Fork 85
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 #650 from arkivanov/pages-sample-2
Added Pages sample tab
- Loading branch information
Showing
10 changed files
with
187 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/build | ||
/build | ||
saved_state.dat |
70 changes: 70 additions & 0 deletions
70
...le/shared/compose/src/commonMain/kotlin/com/arkivanov/sample/shared/pages/PagesContent.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,70 @@ | ||
package com.arkivanov.sample.shared.pages | ||
|
||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.PaddingValues | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.OutlinedButton | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.ArrowBack | ||
import androidx.compose.material.icons.filled.ArrowForward | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.arkivanov.decompose.ExperimentalDecomposeApi | ||
import com.arkivanov.decompose.extensions.compose.jetbrains.pages.Pages | ||
import com.arkivanov.decompose.extensions.compose.jetbrains.pages.PagesScrollAnimation | ||
import com.arkivanov.sample.shared.customnavigation.KittenContent | ||
|
||
@OptIn(ExperimentalFoundationApi::class, ExperimentalDecomposeApi::class) | ||
@Composable | ||
fun PagesContent(component: PagesComponent, modifier: Modifier = Modifier) { | ||
Box(modifier = modifier) { | ||
Pages( | ||
pages = component.pages, | ||
onPageSelected = component::selectPage, | ||
modifier = Modifier.fillMaxSize(), | ||
scrollAnimation = PagesScrollAnimation.Default, | ||
) { _, page -> | ||
KittenContent( | ||
component = page, | ||
textStyle = MaterialTheme.typography.h6, | ||
modifier = Modifier.fillMaxSize(), | ||
) | ||
} | ||
|
||
Row( | ||
modifier = Modifier.align(Alignment.BottomCenter).padding(bottom = 16.dp), | ||
horizontalArrangement = Arrangement.spacedBy(16.dp), | ||
) { | ||
OutlinedButton( | ||
onClick = component::selectPrev, | ||
modifier = Modifier.size(48.dp), | ||
contentPadding = PaddingValues(0.dp), | ||
) { | ||
Icon( | ||
imageVector = Icons.Default.ArrowBack, | ||
contentDescription = "Previous", | ||
) | ||
} | ||
|
||
OutlinedButton( | ||
onClick = component::selectNext, | ||
modifier = Modifier.size(48.dp), | ||
contentPadding = PaddingValues(0.dp), | ||
) { | ||
Icon( | ||
imageVector = Icons.Default.ArrowForward, | ||
contentDescription = "Next", | ||
) | ||
} | ||
} | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
...d/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/pages/DefaultPagesComponent.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,44 @@ | ||
package com.arkivanov.sample.shared.pages | ||
|
||
import com.arkivanov.decompose.ComponentContext | ||
import com.arkivanov.decompose.ExperimentalDecomposeApi | ||
import com.arkivanov.decompose.router.pages.ChildPages | ||
import com.arkivanov.decompose.router.pages.Pages | ||
import com.arkivanov.decompose.router.pages.PagesNavigation | ||
import com.arkivanov.decompose.router.pages.childPages | ||
import com.arkivanov.decompose.router.pages.select | ||
import com.arkivanov.decompose.router.pages.selectNext | ||
import com.arkivanov.decompose.router.pages.selectPrev | ||
import com.arkivanov.decompose.value.Value | ||
import com.arkivanov.sample.shared.customnavigation.DefaultKittenComponent | ||
import com.arkivanov.sample.shared.customnavigation.KittenComponent | ||
import com.arkivanov.sample.shared.customnavigation.KittenComponent.ImageType | ||
import kotlinx.serialization.serializer | ||
|
||
@OptIn(ExperimentalDecomposeApi::class) | ||
class DefaultPagesComponent( | ||
componentContext: ComponentContext, | ||
) : PagesComponent, ComponentContext by componentContext { | ||
|
||
private val nav = PagesNavigation<ImageType>() | ||
|
||
override val pages: Value<ChildPages<*, KittenComponent>> = | ||
childPages( | ||
source = nav, | ||
serializer = serializer<ImageType>(), | ||
initialPages = { Pages(items = ImageType.entries, selectedIndex = 0) }, | ||
childFactory = { imageType, ctx -> DefaultKittenComponent(ctx, imageType) }, | ||
) | ||
|
||
override fun selectPage(index: Int) { | ||
nav.select(index = index) | ||
} | ||
|
||
override fun selectNext() { | ||
nav.selectNext() | ||
} | ||
|
||
override fun selectPrev() { | ||
nav.selectPrev() | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...e/shared/shared/src/commonMain/kotlin/com/arkivanov/sample/shared/pages/PagesComponent.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,16 @@ | ||
package com.arkivanov.sample.shared.pages | ||
|
||
import com.arkivanov.decompose.ExperimentalDecomposeApi | ||
import com.arkivanov.decompose.router.pages.ChildPages | ||
import com.arkivanov.decompose.value.Value | ||
import com.arkivanov.sample.shared.customnavigation.KittenComponent | ||
|
||
interface PagesComponent { | ||
|
||
@OptIn(ExperimentalDecomposeApi::class) | ||
val pages: Value<ChildPages<*, KittenComponent>> | ||
|
||
fun selectPage(index: Int) | ||
fun selectNext() | ||
fun selectPrev() | ||
} |
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