feat: 全局返回顶部事件
This commit is contained in:
parent
0ae5dde3df
commit
2ce5dbb315
|
|
@ -5,6 +5,7 @@ import android.os.Bundle
|
|||
import android.os.Parcelable
|
||||
import android.widget.Toast
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
|
|
@ -106,6 +107,8 @@ abstract class BaseComposeActivity : BaseActivity() {
|
|||
is CommonUiEvent.Toast -> {
|
||||
Toast.makeText(this, event.message, event.length).show()
|
||||
}
|
||||
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -118,8 +121,17 @@ abstract class BaseComposeActivity : BaseActivity() {
|
|||
|
||||
|
||||
sealed interface CommonUiEvent : UiEvent {
|
||||
object ScrollToTop : CommonUiEvent
|
||||
|
||||
data class Toast(
|
||||
val message: CharSequence,
|
||||
val length: Int = android.widget.Toast.LENGTH_SHORT
|
||||
) : CommonUiEvent
|
||||
|
||||
@Composable
|
||||
fun BaseViewModel<*, *, *, *>.bindScrollToTopEvent(lazyListState: LazyListState) {
|
||||
onEvent<ScrollToTop> {
|
||||
lazyListState.scrollToItem(0, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -49,6 +49,7 @@ import com.huanchengfly.tieba.post.api.models.protos.ThreadInfo
|
|||
import com.huanchengfly.tieba.post.api.models.protos.personalized.DislikeReason
|
||||
import com.huanchengfly.tieba.post.api.models.protos.personalized.ThreadPersonalized
|
||||
import com.huanchengfly.tieba.post.arch.BaseComposeActivity
|
||||
import com.huanchengfly.tieba.post.arch.CommonUiEvent.ScrollToTop.bindScrollToTopEvent
|
||||
import com.huanchengfly.tieba.post.arch.ImmutableHolder
|
||||
import com.huanchengfly.tieba.post.arch.collectPartialAsState
|
||||
import com.huanchengfly.tieba.post.arch.onEvent
|
||||
|
|
@ -111,6 +112,7 @@ fun PersonalizedPage(
|
|||
onRefresh = { viewModel.send(PersonalizedUiIntent.Refresh) }
|
||||
)
|
||||
val lazyListState = rememberLazyListState()
|
||||
viewModel.bindScrollToTopEvent(lazyListState = lazyListState)
|
||||
var refreshCount by remember {
|
||||
mutableStateOf(0)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue