File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
app/src/main/java/com/kylecorry/preparedness_feed/ui Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments