-
Notifications
You must be signed in to change notification settings - Fork 132
[Woo Pos] Compose navigation template #11512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kidinov
merged 11 commits into
trunk
from
11495-woo-pos-add-compose-navigation-dependency-setup-template-for-recording-the-navigation-graph-read-firstly-about-good-practices
May 16, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d1ec44e
navigation-compose dependency
kidinov e37662e
Scaleton for compose navigation
kidinov fd843da
Checkout screen for testing
kidinov 208cb59
Better naming
kidinov 2333937
Navigation to checkout screen
kidinov 2ccb769
Mock of the checkout screen
kidinov f53e3c7
Fixed detekt complains
kidinov 67c023a
WooPosPreview annotation
kidinov c363725
Merge branch 'trunk' into 11495-woo-pos-add-compose-navigation-depend…
kidinov f19c30d
Fixed detekt complains
kidinov 1a5983d
Changed version of :hilt-navigation-compose used to keep using the cu…
kidinov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
20 changes: 20 additions & 0 deletions
20
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/cart/WooPosCartNavigation.kt
This file contains hidden or 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,20 @@ | ||
package com.woocommerce.android.ui.woopos.cart | ||
|
||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.compose.composable | ||
|
||
internal const val CART_ROUTE = "cart" | ||
|
||
internal fun NavGraphBuilder.cartScreen( | ||
onCheckoutClick: () -> Unit | ||
) { | ||
composable(CART_ROUTE) { | ||
val viewModel: WooPosCartViewModel = hiltViewModel() | ||
|
||
WooPosCartScreen( | ||
viewModel = viewModel, | ||
onCheckoutClick = onCheckoutClick | ||
) | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/cart/WooPosCartScreen.kt
This file contains hidden or 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 @@ | ||
package com.woocommerce.android.ui.woopos.cart | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import com.woocommerce.android.ui.woopos.util.WooPosPreview | ||
|
||
@Composable | ||
@Suppress("UNUSED_PARAMETER") | ||
fun WooPosCartScreen( | ||
viewModel: WooPosCartViewModel, | ||
onCheckoutClick: () -> Unit, | ||
) { | ||
WooPosCartScreen( | ||
onButtonClicked = onCheckoutClick | ||
) | ||
} | ||
|
||
@Composable | ||
private fun WooPosCartScreen(onButtonClicked: () -> Unit) { | ||
Box( | ||
Modifier.fillMaxSize(), | ||
contentAlignment = Alignment.Center | ||
) { | ||
Column { | ||
Text( | ||
text = "Cart", | ||
style = MaterialTheme.typography.h3, | ||
color = MaterialTheme.colors.primary, | ||
) | ||
Button(onClick = onButtonClicked) { | ||
Text("Checkout") | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@WooPosPreview | ||
fun WooPosCartScreenPreview() { | ||
WooPosCartScreen(onButtonClicked = {}) | ||
} |
11 changes: 11 additions & 0 deletions
11
WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/cart/WooPosCartViewModel.kt
This file contains hidden or 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,11 @@ | ||
package com.woocommerce.android.ui.woopos.cart | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import com.woocommerce.android.viewmodel.ScopedViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class WooPosCartViewModel @Inject constructor( | ||
savedStateHandle: SavedStateHandle, | ||
) : ScopedViewModel(savedStateHandle) |
25 changes: 25 additions & 0 deletions
25
...ce/src/main/kotlin/com/woocommerce/android/ui/woopos/checkout/WooPosCheckoutNavigation.kt
This file contains hidden or 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,25 @@ | ||
package com.woocommerce.android.ui.woopos.checkout | ||
|
||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.navigation.NavController | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.compose.composable | ||
|
||
private const val CHECKOUT_ROUTE = "checkout" | ||
|
||
fun NavController.navigateToCheckoutScreen() { | ||
navigate(CHECKOUT_ROUTE) | ||
} | ||
|
||
fun NavGraphBuilder.checkoutScreen( | ||
onBackClick: () -> Unit | ||
) { | ||
composable(CHECKOUT_ROUTE) { | ||
val viewModel: WooPosCheckoutViewModel = hiltViewModel() | ||
|
||
WooPosCheckoutScreen( | ||
viewModel = viewModel, | ||
onBackClick = onBackClick | ||
) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...mmerce/src/main/kotlin/com/woocommerce/android/ui/woopos/checkout/WooPosCheckoutScreen.kt
This file contains hidden or 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,45 @@ | ||
package com.woocommerce.android.ui.woopos.checkout | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import com.woocommerce.android.ui.woopos.util.WooPosPreview | ||
|
||
@Composable | ||
@Suppress("UNUSED_PARAMETER") | ||
fun WooPosCheckoutScreen(viewModel: WooPosCheckoutViewModel, onBackClick: () -> Unit) { | ||
WooPosCheckoutScreen( | ||
onBackClick = onBackClick | ||
) | ||
} | ||
|
||
@Composable | ||
private fun WooPosCheckoutScreen(onBackClick: () -> Unit) { | ||
Box( | ||
Modifier.fillMaxSize(), | ||
contentAlignment = Alignment.Center | ||
) { | ||
Column { | ||
Text( | ||
text = "Checkout", | ||
style = MaterialTheme.typography.h3, | ||
color = MaterialTheme.colors.primary, | ||
) | ||
Button(onClick = onBackClick) { | ||
Text("To Cart") | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@WooPosPreview | ||
fun WooPosCheckoutScreenPreview() { | ||
WooPosCheckoutScreen(onBackClick = {}) | ||
} |
11 changes: 11 additions & 0 deletions
11
...rce/src/main/kotlin/com/woocommerce/android/ui/woopos/checkout/WooPosCheckoutViewModel.kt
This file contains hidden or 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,11 @@ | ||
package com.woocommerce.android.ui.woopos.checkout | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import com.woocommerce.android.viewmodel.ScopedViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class WooPosCheckoutViewModel @Inject constructor( | ||
savedStateHandle: SavedStateHandle, | ||
) : ScopedViewModel(savedStateHandle) |
This file contains hidden or 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
.../src/main/kotlin/com/woocommerce/android/ui/woopos/root/navigation/WooPosMainFlowGraph.kt
This file contains hidden or 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.woocommerce.android.ui.woopos.root.navigation | ||
|
||
import androidx.navigation.NavController | ||
import androidx.navigation.NavGraphBuilder | ||
import androidx.navigation.compose.navigation | ||
import com.woocommerce.android.ui.woopos.cart.CART_ROUTE | ||
import com.woocommerce.android.ui.woopos.cart.cartScreen | ||
import com.woocommerce.android.ui.woopos.checkout.checkoutScreen | ||
import com.woocommerce.android.ui.woopos.checkout.navigateToCheckoutScreen | ||
|
||
const val MAIN_GRAPH_ROUTE = "main-graph" | ||
|
||
fun NavGraphBuilder.checkoutGraph( | ||
navController: NavController | ||
) { | ||
navigation( | ||
startDestination = CART_ROUTE, | ||
route = MAIN_GRAPH_ROUTE, | ||
) { | ||
cartScreen( | ||
onCheckoutClick = navController::navigateToCheckoutScreen | ||
) | ||
checkoutScreen( | ||
onBackClick = navController::popBackStack | ||
) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...n/kotlin/com/woocommerce/android/ui/woopos/root/navigation/WooPosNavigationTransitions.kt
This file contains hidden or 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,18 @@ | ||
package com.woocommerce.android.ui.woopos.root.navigation | ||
|
||
import androidx.compose.animation.AnimatedContentTransitionScope | ||
import androidx.compose.animation.EnterTransition | ||
import androidx.compose.animation.ExitTransition | ||
import androidx.compose.animation.fadeIn | ||
import androidx.compose.animation.fadeOut | ||
import androidx.navigation.NavBackStackEntry | ||
|
||
fun AnimatedContentTransitionScope<NavBackStackEntry>.screenSlideIn(): EnterTransition = | ||
slideIntoContainer(AnimatedContentTransitionScope.SlideDirection.Start) | ||
|
||
fun screenFadeOut(): ExitTransition = fadeOut() | ||
|
||
fun screenFadeIn(): EnterTransition = fadeIn() | ||
|
||
fun AnimatedContentTransitionScope<NavBackStackEntry>.screenSlideOut(): ExitTransition = | ||
slideOutOfContainer(AnimatedContentTransitionScope.SlideDirection.End) |
23 changes: 23 additions & 0 deletions
23
...merce/src/main/kotlin/com/woocommerce/android/ui/woopos/root/navigation/WooPosRootHost.kt
This file contains hidden or 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,23 @@ | ||
package com.woocommerce.android.ui.woopos.root.navigation | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.navigation.compose.NavHost | ||
import androidx.navigation.compose.rememberNavController | ||
|
||
@Composable | ||
fun WooPosRootHost() { | ||
val rootController = rememberNavController() | ||
|
||
NavHost( | ||
navController = rootController, | ||
startDestination = MAIN_GRAPH_ROUTE, | ||
enterTransition = { screenSlideIn() }, | ||
exitTransition = { screenFadeOut() }, | ||
popEnterTransition = { screenFadeIn() }, | ||
popExitTransition = { screenSlideOut() }, | ||
) { | ||
checkoutGraph( | ||
navController = rootController, | ||
) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../src/main/kotlin/com/woocommerce/android/ui/woopos/util/WooPosComposePreviewAnnotation.kt
This file contains hidden or 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,26 @@ | ||
@file:Suppress("MatchingDeclarationName", "Filename") | ||
|
||
package com.woocommerce.android.ui.woopos.util | ||
|
||
import android.content.res.Configuration | ||
import androidx.compose.ui.tooling.preview.Devices | ||
import androidx.compose.ui.tooling.preview.Preview | ||
|
||
@Retention(AnnotationRetention.BINARY) | ||
@Target( | ||
AnnotationTarget.ANNOTATION_CLASS, | ||
AnnotationTarget.FUNCTION | ||
) | ||
@Preview( | ||
name = "Tablet Big", | ||
device = Devices.TABLET, | ||
showSystemUi = true, | ||
uiMode = Configuration.UI_MODE_NIGHT_YES or Configuration.UI_MODE_TYPE_NORMAL | ||
) | ||
@Preview( | ||
name = "Tablet Small", | ||
showSystemUi = true, | ||
device = "spec:width=440dp,height=920dp,dpi=420,isRound=false,chinSize=0dp,orientation=landscape", | ||
uiMode = Configuration.UI_MODE_TYPE_NORMAL | ||
) | ||
annotation class WooPosPreview |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to keep in mind that now even if it's just 1 screen, we still need to separate parts of the screen in easily reusable components (so probably products and cart will have their own VM, screen etc) so if potential phone support will come we can use another NavHost here and reuse the same screens
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Good point. Also kind of makes those classes simpler since they will be focused on doing one thing.