Hello. I'm try to using scrollAway for moving time...
# compose-wear
b
Hello. I'm try to using scrollAway for moving timetext with scalingLazyColumn. I used wear-compose 1.1.2, so I still used scrollAway modifier extension. I think there are cases where scrollAway doesn't work as intended. In logic, the
yPx
value is obtained with
-it.Offset
, Using this yPx value, progress is measured by
(scrollParams.yPx / maxScrollOut.toPx()).coerceIn(0f, 1f)
. Since coerceIn is used here, if the offset of the initial value is a positive number, yPx becomes a negative number, and progress returns 0f by coerceIn, so timetext is displayed normally while the screen has just been drawn. However, the problem is when the index 1 item's offset is a negative number. If the initial offset is negative, yPx will be positive, and
positive yPx / maxScrollOut.toPx()
is performed, it will return something greater than 0. In other words, timeText is already moved to the top while the screen has just been drawn, so I cannot see the timetext. From experience, it seems that the above issue occurs when
index 1 item
is very short height and located at the top. In this case, To make
scrollAway
work normally, and to make timeText move when the item with index1 moves, what is the best way? I thinks select index 2 or 3 item, which is returns the positive offset, and apply the offset between the index 2 or 3 item and item 1 to scrollAway? Or is there something I'm missing?
y
This is kind of expected. You have two options
1) tune the config values initial index, offset of the modifier to match where the ScalingLazyColumn
It can be tricky because auto centering, and some other params affect that initial placement But you can grab the values in devel.
2) Horologist has a ScalingLazyColumn override that positions the first item just below the time text, and lines up the time text
b
@yschimke Thanks for replying. First way is wokring. However as you said, there are many things to consider, so it seems like the cost will be high in a situation when I need to apply it to multiple screens. So I'm trying the second method, but after applying it, a negative offset is still occured. Is something wrong with my work? I just create belowTimeText State and set up to scaffold timetext and horologist scalingLazyColumn but still get negative offset and need to set index 2 or 3 item for a
scrollaway
.
Copy code
val tempBelowTimeTextState = ScalingLazyColumn.belowTimeText().create
Scaffold(
     timeText = {
          Text(
               modifier = Modifier.fillMaxWidth(),
               .scrollAway(scrollState = tempBelowTimeTextState.state)),
               text = "testTime"
            )
     }
){
     ScalingLazyColumn(
          columnStae = tempBelowTimeTextState
     ){
          SOME ITME
     }
}
y
There is a scrollAway offload that takes the ScalingLazyColumnState https://github.com/google/horologist/blob/main/compose-layout/src/main/java/com/google/android/horologist/compose/layout/ScrollAway.kt#L105, so remove the .state from the current param.
b
Thanks a lot. That scrollAway works perfect! 👍
y
One thing to be aware of, it's quite likely Horologist 0.4.x is bumping you up to wear compose 1.2 beta
b
Ok I understand. Thank you for your advice.
@yschimke I have question about rotary of horologist scalingLazyColumn. Horologist scalingLazyColumn have to need RotaryMode and by this parameter scalingLazyColumn create own focusRequester. Can I requset this focusRequester manually?
I have a pager, which have two screens, and each screen have different rotary action. Orginally I have different two focusRequster, and I request each focusRequster with pagerState change for working each screen's rotary action. I thinks
rememberActiveFocusRequester
does not request focus when pager scrolled. So I thinks I need to way of focus request manually on horologist scalingLazyColumn or I can trigger onFocusChange manually. Am I right? Or is there a better way?
y
Basically you want to use HierarchicalFocusCoorsinator to teach it about your pager
b
Thanks for information. I will check about HierarchicalFocusCoorsinator.