-
Notifications
You must be signed in to change notification settings - Fork 18
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 #116 from Trendyol/MCHECKOUT-900/addShadowAndIndex…
…TextToPoints add shadow and index text to points and fit to screen
- Loading branch information
Showing
15 changed files
with
413 additions
and
15 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
68 changes: 68 additions & 0 deletions
68
...java/com/trendyol/uicomponents/timelineviewcompose/HorizontalTimelineWithIndexTextView.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,68 @@ | ||
package com.trendyol.uicomponents.timelineviewcompose | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.onGloballyPositioned | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import com.trendyol.uicomponents.timelineviewcompose.item.HorizontalTimelineWithIndexTextItem | ||
import com.trendyol.uicomponents.timelineviewcompose.model.FakeTimelineItemProvider | ||
import com.trendyol.uicomponents.timelineviewcompose.model.TimelineItem | ||
|
||
/*** | ||
* The line sizes are automatically calculated and set to fit the screen. | ||
* It accepts 'PointWithIndex' as an item. | ||
*/ | ||
@Composable | ||
fun HorizontalTimelineWithIndexTextView( | ||
items: List<TimelineItem.PointWithIndex>, | ||
modifier: Modifier = Modifier, | ||
onClick: (TimelineItem) -> Unit = {}, | ||
) { | ||
|
||
var availableWidth by remember { mutableStateOf(0) } | ||
val availableWidthPx = with(LocalDensity.current) { availableWidth.toDp() } | ||
|
||
Row( | ||
horizontalArrangement = Arrangement.Center, | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.onGloballyPositioned { availableWidth = it.size.width }) { | ||
items.forEachIndexed { index, item -> | ||
val lineWidthDp = | ||
((availableWidthPx - (item.pointConfig.getSizeWithBorder() * items.size)) / (items.size - 1)) | ||
val itemWidth = item.pointConfig.getSizeWithBorder() + lineWidthDp | ||
|
||
HorizontalTimelineWithIndexTextItem( | ||
item = item, | ||
itemIndex = index, | ||
isLastItem = items.isLastItem(index), | ||
onClick = { onClick(items[index]) }, | ||
itemIndexTextStyle = item.indexTextStyle, | ||
customLineWidth = itemWidth | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun List<TimelineItem>.isLastItem(index: Int): Boolean { | ||
return index == size - 1 | ||
} | ||
|
||
@Composable | ||
@Preview(showBackground = true) | ||
private fun TimelineViewVerticalPreview() { | ||
HorizontalTimelineWithIndexTextView( | ||
modifier = Modifier.padding(horizontal = 16.dp), | ||
items = FakeTimelineItemProvider.provideTimelineItemWithTextList() | ||
) | ||
} |
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: 87 additions & 0 deletions
87
...com/trendyol/uicomponents/timelineviewcompose/item/HorizontalTimelineWithIndexTextItem.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,87 @@ | ||
package com.trendyol.uicomponents.timelineviewcompose.item | ||
|
||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.layout.layoutId | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import androidx.constraintlayout.compose.ConstraintLayout | ||
import com.trendyol.uicomponents.timelineviewcompose.Line | ||
import com.trendyol.uicomponents.timelineviewcompose.TimelinePoint | ||
import com.trendyol.uicomponents.timelineviewcompose.model.FakeTimelineItemProvider | ||
import com.trendyol.uicomponents.timelineviewcompose.model.IndexTextLayoutId | ||
import com.trendyol.uicomponents.timelineviewcompose.model.LineLayoutId | ||
import com.trendyol.uicomponents.timelineviewcompose.model.PointLayoutId | ||
import com.trendyol.uicomponents.timelineviewcompose.model.TextLayoutId | ||
import com.trendyol.uicomponents.timelineviewcompose.model.TimelineItem | ||
import com.trendyol.uicomponents.timelineviewcompose.model.TimelineOrientation | ||
import com.trendyol.uicomponents.timelineviewcompose.model.getHorizontalWithIndexConstraintSet | ||
|
||
@Composable | ||
internal fun HorizontalTimelineWithIndexTextItem( | ||
modifier: Modifier = Modifier, | ||
item: TimelineItem.PointWithIndex, | ||
isLastItem: Boolean = false, | ||
itemIndex: Int, | ||
itemIndexTextStyle: TextStyle, | ||
customLineWidth : Dp = 0.dp, | ||
onClick: () -> Unit = {}, | ||
) { | ||
|
||
val itemWidth =item.pointConfig.getSizeWithBorder() + customLineWidth | ||
|
||
ConstraintLayout( | ||
constraintSet = getHorizontalWithIndexConstraintSet(item.contentMargin, itemWidth), | ||
modifier = modifier | ||
.width(customLineWidth) | ||
) { | ||
TimelinePoint( | ||
config = item.pointConfig, | ||
modifier = Modifier.layoutId(PointLayoutId), | ||
onClick = onClick, | ||
pointShadowConfig = item.pointShadowConfig | ||
) | ||
Text( | ||
text = item.text, | ||
style = item.textStyle, | ||
overflow = TextOverflow.Ellipsis, | ||
textAlign = TextAlign.Center, | ||
maxLines = 2, | ||
modifier = Modifier | ||
.width(itemWidth) | ||
.layoutId(TextLayoutId) | ||
) | ||
Text( | ||
text = (itemIndex + 1).toString(), | ||
modifier = Modifier.layoutId(IndexTextLayoutId), | ||
style = itemIndexTextStyle, | ||
) | ||
if (!isLastItem) { | ||
Line( | ||
itemIndex = itemIndex, | ||
config = item.lineConfig, | ||
orientation = TimelineOrientation.HORIZONTAL, | ||
modifier = Modifier.layoutId(LineLayoutId), | ||
customLineWidth = customLineWidth - item.pointConfig.borderWidth | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@Preview(showBackground = true) | ||
private fun HorizontalWithIndexTimelineItemPreview() { | ||
HorizontalTimelineWithIndexTextItem( | ||
item = FakeTimelineItemProvider.provideTimelineItemWithText(text = "Siparişiniz hazırlanıyor"), | ||
isLastItem = false, | ||
itemIndex = 0, | ||
itemIndexTextStyle = TextStyle(color = Color.White), | ||
) | ||
} |
Oops, something went wrong.