https://github.com/evant/compose-shown
Provides a callback for when a @Composable is shown to the user
https://github.com/evant/compose-shown
Last synced: about 1 year ago
JSON representation
Provides a callback for when a @Composable is shown to the user
- Host: GitHub
- URL: https://github.com/evant/compose-shown
- Owner: evant
- License: mit
- Created: 2021-05-03T02:19:22.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-06-21T22:41:12.000Z (almost 3 years ago)
- Last Synced: 2025-04-01T14:45:52.638Z (about 1 year ago)
- Language: Kotlin
- Homepage:
- Size: 97.7 KB
- Stars: 66
- Watchers: 4
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Compose-Shown
Provides a callback for when a `@Composable` is shown to the user. This can be useful for 'pageview'
analytics. It will re-fire when the activity is paused and resumed and _not_ re-fire on rotation.
## Usage
Simply add the `onShown` modifier to the composable you want to track.
```kotlin
Text("Hello", modifier = Modifier.onShown {
// fire pageview analytics event
})
```
You can also optionally pass keys, this will cause it to re-fire when the key changes. Say, for
example, you want to re-send when the search query changes.
```kotlin
SearchResults(modifier = Modifier.onShown(query) {
// fire when shown and when the query changes.
}, results)
```