I want to create an application that is like googl...
# compose
с
I want to create an application that is like google calendar one day view. So I have a scroll state for different hours in a day and one line that represents the current time. This line is created with Stateflow and it is dynamic. I want the following user experience with the latter: • when the app is launched to scroll directly to that line • when the user scrolls down or up - at a certain time this line to be focused again How can I achieve it? Currently app looks like below pictures(in the second is the suspect line):
🧵 2
🧵 3
f
🧵 Please stick to a thread for longer messages 👇 https://kotlinlang.slack.com/archives/CJLTWPH7S/p1615303547114200
👍🏽 1
с
ok
🙏 1
Code from MainActivity:
Copy code
class MainActivity : ComponentActivity() {
    private lateinit var viewModel: LineViewModel

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        viewModel = ViewModelProvider(this).get(LineViewModel::class.java)
        viewModel.verticalPosition.watch {
            setContent {
                JetpackComposeTheme {
                    Surface(color = MaterialTheme.colors.background) {
                        Schedule(events = sampleEvents, linePosition = it)
                    }
                }
            }
        }
    }
}
Then with that code I create the line:
Copy code
@Composable
fun Schedule(
    events: List<Event>,
    linePosition: Float,
    modifier: Modifier = Modifier,
    minDate: LocalDate = LocalDate.now(),
    hourHeight: Dp = 128.dp,
) {
    val verticalScrollState = rememberScrollState()


    val positionedEvents = remember(events) {
        arrangeEvents(splitEvents(events.sortedBy(Event::start))).filter {
            it.end > LocalTime.MIN && it.start < LocalTime.MAX
        }
    }


    BoxWithConstraints(modifier = modifier) {
        Column(modifier = modifier) {
            Row(modifier = Modifier.weight(1f)) {
                ScheduleSidebar(
                    hourHeight = hourHeight,
                    modifier = Modifier
                        .verticalScroll(verticalScrollState)
                        .drawBehind {
                            drawLine(
                                Color(0xFFEA4336),
                                start = Offset(
                                    x = 0f,
                                    linePosition * hourHeight.toPx()
                                ),
                                end = Offset(
                                    size.maxDimension,
                                    linePosition * hourHeight.toPx()
                                ),
                                strokeWidth = 4.dp.toPx()
                            )
                        }.zIndex(1f)
                )
                EventsLocation(
                    positionedEvents = positionedEvents, minDate = minDate,
                    verticalScrollState = verticalScrollState,
                )
            }
        }
    }
}
f
Thank you 👌