You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/llms-full.txt
+34Lines changed: 34 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -9638,6 +9638,40 @@ dependencies {
9638
9638
9639
9639
## Usage
9640
9640
9641
+
### Manual usage
9642
+
9643
+
This is the core functionality - it’s totally up to you how you want to use it. Just don’t forget to dispose its callback (`removeListener`) when you don’t need it anymore.
9644
+
9645
+
You can use Compose states, RxJava/Kotlin, or anything else you prefer.
9646
+
9647
+
Here we’re using a coroutines Flow wrapper just for demonstration.
9648
+
9649
+
```kt
9650
+
val isSystemDarkFlow: Flow<Boolean> = callbackFlow<Boolean> {
9651
+
val listener: Consumer<Boolean> = { isDark: Boolean ->
9652
+
trySend(isDark)
9653
+
}
9654
+
9655
+
val darkModeDetector = getPlatformDarkModeDetector()
9656
+
9657
+
// emit initial value
9658
+
trySend(darkModeDetector.isDark())
9659
+
9660
+
// listen to dark mode change events
9661
+
darkModeDetector.registerListener(listener)
9662
+
awaitClose {
9663
+
darkModeDetector.removeListener(listener)
9664
+
}
9665
+
}
9666
+
isSystemDarkFlow.collect {
9667
+
println("dark mode changes, isDark: $it")
9668
+
}
9669
+
```
9670
+
9671
+
### In compose
9672
+
9673
+
There is already a composable function available out of the box, which you can use it in your compose applications.
0 commit comments