Skip to content

Commit 0dc332e

Browse files
committed
优化显示细节 (#38)
1 parent 9e8f0e6 commit 0dc332e

1 file changed

Lines changed: 12 additions & 24 deletions

File tree

refresh/src/main/java/com/king/ultraswiperefresh/UltraSwipeRefresh.kt

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ fun UltraSwipeRefresh(
9898

9999
Box(modifier) {
100100
RefreshSubComposeLayout(
101-
refreshEnabled = refreshEnabled,
102-
loadMoreEnabled = loadMoreEnabled,
103101
headerIndicator = {
104102
headerIndicator(state)
105103
},
@@ -143,9 +141,9 @@ fun UltraSwipeRefresh(
143141
state.headerState == UltraSwipeHeaderState.Refreshing || state.footerState == UltraSwipeFooterState.Loading -> {
144142
coroutineScope.launch {
145143
state.isFinishing = true
146-
if (state.indicatorOffset > headerHeight) {
144+
if (state.headerState == UltraSwipeHeaderState.Refreshing) {
147145
state.animateOffsetTo(headerHeight.toFloat())
148-
} else if (state.indicatorOffset < -footerHeight) {
146+
} else if (state.footerState == UltraSwipeFooterState.Loading) {
149147
state.animateOffsetTo(-footerHeight.toFloat())
150148
}
151149
delay(finishDelayMillis)
@@ -180,9 +178,7 @@ fun UltraSwipeRefresh(
180178
}
181179
.zIndex(obtainZIndex(headerScrollMode))
182180
) {
183-
if (refreshEnabled) {
184-
headerIndicator(state)
185-
}
181+
headerIndicator(state)
186182
}
187183
Box(
188184
modifier = Modifier
@@ -192,9 +188,7 @@ fun UltraSwipeRefresh(
192188
}
193189
.zIndex(obtainZIndex(footerScrollMode))
194190
) {
195-
if (loadMoreEnabled) {
196-
footerIndicator(state)
197-
}
191+
footerIndicator(state)
198192
}
199193
Box(modifier = Modifier.graphicsLayer {
200194
translationY = obtainContentOffset(state, headerScrollMode, footerScrollMode)
@@ -358,27 +352,21 @@ private fun obtainZIndex(style: NestedScrollMode): Float {
358352
*/
359353
@Composable
360354
private fun RefreshSubComposeLayout(
361-
refreshEnabled: Boolean,
362-
loadMoreEnabled: Boolean,
363355
headerIndicator: @Composable () -> Unit,
364356
footerIndicator: @Composable () -> Unit,
365357
content: @Composable (headerHeight: Int, footerHeight: Int) -> Unit
366358
) {
367359
SubcomposeLayout { constraints: Constraints ->
368360

369-
val headerMeasurable = if (refreshEnabled) {
370-
subcompose(
371-
slotId = "headerIndicator",
372-
content = headerIndicator
373-
).firstOrNull()?.measure(constraints)
374-
} else null
361+
val headerMeasurable = subcompose(
362+
slotId = "headerIndicator",
363+
content = headerIndicator
364+
).firstOrNull()?.measure(constraints)
375365

376-
val footerMeasurable = if (loadMoreEnabled) {
377-
subcompose(
378-
slotId = "footerIndicator",
379-
content = footerIndicator
380-
).firstOrNull()?.measure(constraints)
381-
} else null
366+
val footerMeasurable = subcompose(
367+
slotId = "footerIndicator",
368+
content = footerIndicator
369+
).firstOrNull()?.measure(constraints)
382370

383371
val contentMeasurable = subcompose(
384372
slotId = "content",

0 commit comments

Comments
 (0)