-
Notifications
You must be signed in to change notification settings - Fork 22
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 #544 from kiwicom/coupon-component
Add `Coupon` component
- Loading branch information
Showing
14 changed files
with
415 additions
and
41 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
105 changes: 105 additions & 0 deletions
105
catalog/src/main/java/kiwi/orbit/compose/catalog/screens/CouponScreen.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,105 @@ | ||
package kiwi.orbit.compose.catalog.screens | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.rememberScrollState | ||
import androidx.compose.foundation.verticalScroll | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberCoroutineScope | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.testTag | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import kiwi.orbit.compose.catalog.AppTheme | ||
import kiwi.orbit.compose.catalog.semantics.SubScreenSemantics | ||
import kiwi.orbit.compose.icons.Icons | ||
import kiwi.orbit.compose.ui.controls.Coupon | ||
import kiwi.orbit.compose.ui.controls.Scaffold | ||
import kiwi.orbit.compose.ui.controls.Text | ||
import kiwi.orbit.compose.ui.controls.ToastHostState | ||
import kiwi.orbit.compose.ui.controls.TopAppBar | ||
import kotlinx.coroutines.launch | ||
|
||
@Composable | ||
internal fun CouponScreen( | ||
onNavigateUp: () -> Unit, | ||
) { | ||
val toastHostState = remember { ToastHostState() } | ||
val coroutineScope = rememberCoroutineScope() | ||
|
||
Scaffold( | ||
modifier = Modifier.testTag(SubScreenSemantics.Tag), | ||
topBar = { | ||
TopAppBar( | ||
title = { Text("Coupon") }, | ||
onNavigateUp = onNavigateUp, | ||
) | ||
}, | ||
toastHostState = toastHostState, | ||
) { contentPadding -> | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.verticalScroll(rememberScrollState()) | ||
.padding(contentPadding), | ||
) { | ||
CouponScreenInner( | ||
onCouponCopied = { | ||
coroutineScope.launch { | ||
toastHostState.showToast("Copied to clipboard!") { Icons.Copy } | ||
} | ||
}, | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun CouponScreenInner( | ||
onCouponCopied: () -> Unit, | ||
) { | ||
Column( | ||
modifier = Modifier.padding(16.dp), | ||
verticalArrangement = Arrangement.spacedBy(16.dp), | ||
) { | ||
Row( | ||
horizontalArrangement = Arrangement.spacedBy(4.dp), | ||
) { | ||
Text( | ||
text = "Your coupon:", | ||
modifier = Modifier.alignByBaseline(), | ||
) | ||
Coupon( | ||
code = "hxt3b81f", | ||
onCopied = null, | ||
modifier = Modifier.alignByBaseline(), | ||
) | ||
} | ||
Row( | ||
horizontalArrangement = Arrangement.spacedBy(4.dp), | ||
) { | ||
Text( | ||
text = "Copy your coupon:", | ||
modifier = Modifier.alignByBaseline(), | ||
) | ||
Coupon( | ||
code = "hxt3b81f", | ||
onCopied = onCouponCopied, | ||
modifier = Modifier.alignByBaseline(), | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun CouponScreenPreview() { | ||
AppTheme { | ||
CouponScreen(onNavigateUp = {}) | ||
} | ||
} |
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.