-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contact details: add nested scrolling
The contact details top section now scrolls up first, followed by any content on the selected tab. This involves the experimental context receivers feature for better encapsulation.
- Loading branch information
1 parent
c05a965
commit 80723f3
Showing
4 changed files
with
69 additions
and
17 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
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
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/teobaranga/monica/util/compose/ParentFirstNestedScrollModifier.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,33 @@ | ||
package com.teobaranga.monica.util.compose | ||
|
||
import androidx.compose.foundation.lazy.LazyListState | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.composed | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection | ||
import androidx.compose.ui.input.nestedscroll.NestedScrollSource | ||
import androidx.compose.ui.input.nestedscroll.nestedScroll | ||
|
||
/** | ||
* Modifier useful for nested lazy lists where the parent (the list associated with the [state]) should scroll | ||
* before any children. | ||
*/ | ||
fun Modifier.nestedScrollParentFirst(state: LazyListState): Modifier { | ||
return this | ||
.composed { | ||
val nestedScrollConnection = remember { | ||
object : NestedScrollConnection { | ||
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset { | ||
if (available.y < 0) { | ||
val consumed = state.dispatchRawDelta(-available.y) | ||
return Offset.Zero.copy(y = -consumed) | ||
} else { | ||
return Offset.Zero | ||
} | ||
} | ||
} | ||
} | ||
nestedScroll(nestedScrollConnection) | ||
} | ||
} |