Skip to content

Instantly share code, notes, and snippets.

🚀
Remote

Ahmed Rizwan ahmedrizwan

🚀
Remote
View GitHub Profile
View NumbersPanel.kt
@Composable()
fun NumbersPanel(alpha: Int) {
Stack {
Row(modifier = Modifier.fillMaxSize()) {
numberColumns.forEach { numberColumn ->
Column(modifier = Modifier.weight(1f)) {
numberColumn.forEach { text ->
MainContentButton(text)
}
}
View DimOverlay.kt
@Composable
fun DimOverlay(alpha: Int) {
Box(modifier = Modifier.fillMaxSize(), backgroundColor = Color(50, 50, 50, alpha))
}
View TopView.kt
@Composable
fun TopView(
boxHeight: Dp,
drag: Drag
) {
val position = drag.position
val flingConfig = drag.flingConfig
val yOffset = with(DensityAmbient.current) { position.value.toDp() }
val scrollerPosition = ScrollerPosition()
// scroll the history list to bottom when dragging the top panel
View Content.kt
// Top drag
val topStart = -(constraints.maxHeight.value / 1.4f)
val topMax = 0.dp
val topMin = -(boxHeight / 1.4f)
val (topMinPx, topMaxPx) = with(DensityAmbient.current) {
topMin.toPx().value to topMax.toPx().value
}
val topFlingConfig = AnchorsFlingConfig(listOf(topMinPx, topMaxPx))
val topPosition = animatedFloat(topStart) // for dragging state
topPosition.setBounds(topMinPx, topMaxPx)
View SideView.kt
@Composable()
fun SideView(
boxHeight: Dp,
drag: Drag
) {
val position = drag.position
val flingConfig = drag.flingConfig
val yOffset = with(DensityAmbient.current) { position.value.toDp() }
val toggleAsset = state { R.drawable.ic_keyboard_arrow_left_24 }
Box(
View Content.kt
// Side drag
val sideMin = 90.dp
val sideMax = boxWidth - 30.dp
val (sideMinPx, sideMaxPx) = with(DensityAmbient.current) {
sideMin.toPx().value to sideMax.toPx().value
}
val sideFlingConfig = AnchorsFlingConfig(listOf(sideMinPx, sideMaxPx))
val sidePosition = animatedFloat(sideMaxPx)
sidePosition.setBounds(sideMinPx, sideMaxPx)
View Drag.kt
class Drag(
val position: AnimatedFloat,
val flingConfig: FlingConfig
)
@ahmedrizwan
ahmedrizwan / MainActivity.kt
Last active May 27, 2020
Jetpack Compose Calculator
View MainActivity.kt
setContent {
MaterialTheme(colors = lightThemeColors) {
WithConstraints { constraints, _ ->
val boxHeight = with(DensityAmbient.current) { constraints.maxHeight.toDp() }
val boxWidth = with(DensityAmbient.current) { constraints.maxWidth.toDp() }
Content(
constraints = constraints,
boxHeight = boxHeight,
boxWidth = boxWidth
)
View UIState.kt
sealed class UIState<out R> {
object Loading : UIState<Nothing>()
object Retrying : UIState<Nothing>()
object SwipeRefreshing : UIState<Nothing>()
data class Success<T>(val data: T) : UIState<T>()
data class Failure(val exception: Exception) : UIState<Nothing>()
data class SwipeRefreshFailure(val exception: Exception) : UIState<Nothing>()
}
View Action.kt
sealed class Action {
object Load : Action()
object SwipeRefresh : Action()
object Retry : Action()
}
You can’t perform that action at this time.