-
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.
Closes #63
- Loading branch information
Showing
16 changed files
with
149 additions
and
197 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
87 changes: 37 additions & 50 deletions
87
...onMain/kotlin/nl/tiebe/otarium/ui/home/elo/children/assignments/AssignmentsChildScreen.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,72 +1,59 @@ | ||
package nl.tiebe.otarium.ui.home.elo.children.assignments | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.WindowInsets | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.DismissDirection | ||
import androidx.compose.material.DismissValue | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.SwipeToDismiss | ||
import androidx.compose.material.rememberDismissState | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TopAppBar | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import com.arkivanov.decompose.ExperimentalDecomposeApi | ||
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.Children | ||
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.fade | ||
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.plus | ||
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.predictiveback.predictiveBackAnimation | ||
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.scale | ||
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.stackAnimation | ||
import com.arkivanov.decompose.extensions.compose.jetbrains.subscribeAsState | ||
import com.arkivanov.decompose.router.stack.pop | ||
import nl.tiebe.otarium.MR | ||
import nl.tiebe.otarium.logic.root.home.children.elo.children.assignments.AssignmentsChildComponent | ||
import nl.tiebe.otarium.ui.home.elo.children.assignments.assignment.AssignmentScreen | ||
import nl.tiebe.otarium.ui.home.elo.children.assignments.assignment.AssignmentScreenTopAppBar | ||
import nl.tiebe.otarium.ui.home.elo.children.assignments.listscreen.AssignmentListScreen | ||
import kotlinx.coroutines.launch | ||
import nl.tiebe.otarium.utils.ui.getLocalizedString | ||
|
||
@OptIn(ExperimentalMaterialApi::class) | ||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
internal fun AssignmentsChildScreen(component: AssignmentsChildComponent) { | ||
val screen = component.childStack.subscribeAsState() | ||
val scope = rememberCoroutineScope() | ||
|
||
Box(modifier = Modifier.padding(start = 5.dp, end = 5.dp)) { | ||
when (val child = screen.value.items[0].instance) { | ||
is AssignmentsChildComponent.Child.Assignment -> AssignmentScreen(child.component) | ||
is AssignmentsChildComponent.Child.AssignmentList -> AssignmentListScreen(child.component) | ||
} | ||
|
||
|
||
for (item in screen.value.items.subList(1, screen.value.items.size)) { | ||
val state = rememberDismissState() | ||
|
||
component.onBack.value = { | ||
scope.launch { | ||
state.animateTo(DismissValue.DismissedToEnd) | ||
} | ||
} | ||
fun AssignmentsTopBar(component: AssignmentsChildComponent) { | ||
when (val instance = component.childStack.subscribeAsState().value.active.instance) { | ||
is AssignmentsChildComponent.Child.AssignmentList -> TopAppBar(title = { Text(getLocalizedString(MR.strings.assignments)) }, windowInsets = WindowInsets(0)) | ||
is AssignmentsChildComponent.Child.Assignment -> AssignmentScreenTopAppBar(instance.component, component) | ||
} | ||
} | ||
|
||
//pop on finish | ||
if (state.isDismissed(DismissDirection.StartToEnd)) { | ||
component.navigation.pop() | ||
} | ||
|
||
SwipeToDismiss( | ||
state = state, | ||
background = { | ||
}, | ||
directions = setOf(DismissDirection.StartToEnd) | ||
) { | ||
Surface(Modifier.fillMaxSize()) { | ||
when (val child = item.instance) { | ||
is AssignmentsChildComponent.Child.Assignment -> AssignmentScreen(child.component) | ||
is AssignmentsChildComponent.Child.AssignmentList -> AssignmentListScreen(child.component) | ||
} | ||
@OptIn(ExperimentalDecomposeApi::class) | ||
@Composable | ||
internal fun AssignmentsChildScreen(component: AssignmentsChildComponent) { | ||
Box(modifier = Modifier.padding(start = 5.dp, end = 5.dp)) { | ||
Children( | ||
component.childStack.subscribeAsState().value, | ||
animation = predictiveBackAnimation( | ||
backHandler = component.backHandler, | ||
animation = stackAnimation(fade() + scale()), // Your usual animation here | ||
onBack = component::back, | ||
) | ||
) { child -> | ||
Surface(Modifier.fillMaxSize()) { | ||
when (val instance = child.instance) { | ||
is AssignmentsChildComponent.Child.Assignment -> AssignmentScreen(instance.component) | ||
is AssignmentsChildComponent.Child.AssignmentList -> AssignmentListScreen(instance.component) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
Box(modifier = Modifier.padding(start = 5.dp, end = 5.dp)) { | ||
|
||
} | ||
|
||
} |
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.