Created
January 2, 2024 07:33
-
-
Save muhammedesadcomert/8a9b650d13d8d9b2dee7264414d79c39 to your computer and use it in GitHub Desktop.
Get the first position of a Composable.
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
@Composable | |
fun Modifier.onFirstPlacement(onFirstPlacement: (LayoutCoordinates) -> Unit): Modifier { | |
var isFirstPlacement by remember { mutableStateOf(true) } | |
var currentPosition by remember { mutableStateOf(Offset.Zero) } | |
return onPlaced { | |
if (isFirstPlacement) { | |
onFirstPlacement(it) | |
if (currentPosition == it.positionInWindow()) { | |
isFirstPlacement = false | |
} else { | |
currentPosition = it.positionInWindow() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment