Skip to content

Commit 27713ff

Browse files
committed
Add icon hooks
1 parent cd22574 commit 27713ff

File tree

1 file changed

+42
-0
lines changed
  • app/src/main/java/com/kylecorry/preparedness_feed/ui

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.kylecorry.preparedness_feed.ui
2+
3+
import android.graphics.Bitmap
4+
import android.graphics.drawable.Icon
5+
import android.net.Uri
6+
import com.kylecorry.andromeda.core.ui.ReactiveComponent
7+
8+
object Hooks {
9+
10+
fun ReactiveComponent.useIcon(resourceId: Int): Icon {
11+
val context = useAndroidContext()
12+
return useMemo(resourceId, context) {
13+
Icon.createWithResource(context, resourceId)
14+
}
15+
}
16+
17+
fun ReactiveComponent.useIcon(bitmap: Bitmap): Icon {
18+
val context = useAndroidContext()
19+
return useMemo(bitmap, context) {
20+
Icon.createWithBitmap(bitmap)
21+
}
22+
}
23+
24+
fun ReactiveComponent.useIcon(path: String): Icon {
25+
val context = useAndroidContext()
26+
return useMemo(path, context) {
27+
if (path.contains("://")) {
28+
Icon.createWithContentUri(Uri.parse(path))
29+
} else {
30+
Icon.createWithFilePath(path)
31+
}
32+
}
33+
}
34+
35+
fun ReactiveComponent.useIcon(uri: Uri): Icon {
36+
val context = useAndroidContext()
37+
return useMemo(uri, context) {
38+
Icon.createWithContentUri(uri)
39+
}
40+
}
41+
42+
}

0 commit comments

Comments
 (0)