-
-
Notifications
You must be signed in to change notification settings - Fork 847
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow Images/Image component in NativeUserLocation
- Loading branch information
Showing
42 changed files
with
1,173 additions
and
307 deletions.
There are no files selected for viewing
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
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
53 changes: 53 additions & 0 deletions
53
android/src/main/java/com/rnmapbox/rnmbx/components/images/ImageManager.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.rnmapbox.rnmbx.components.images | ||
|
||
import android.graphics.Bitmap | ||
import android.graphics.drawable.BitmapDrawable | ||
import com.rnmapbox.rnmbx.v11compat.Cancelable | ||
import com.mapbox.maps.Image | ||
import com.rnmapbox.rnmbx.v11compat.image.toMapboxImage | ||
|
||
/** | ||
ImageManager helps to resolve images defined by any of RNMBXImages component. | ||
*/ | ||
|
||
fun interface Resolver { | ||
fun resolved(name: String, image: Image) | ||
} | ||
class Subscription(val name:String, val resolver: Resolver, val manager: ImageManager): Cancelable { | ||
|
||
fun resolved(name: String, image: Image) { | ||
resolver.resolved(name, image) | ||
} | ||
override fun cancel() { | ||
manager.unsubscribe(this) | ||
} | ||
} | ||
|
||
class ImageManager { | ||
var subscriptions: MutableMap<String, MutableList<Subscription>> = hashMapOf() | ||
|
||
fun subscribe(name: String, resolved: Resolver) : Subscription { | ||
val list = subscriptions.getOrPut(name) { mutableListOf() } | ||
val result = Subscription(name, resolved, this) | ||
list.add(result) | ||
return result | ||
} | ||
fun unsubscribe(subscription: Subscription) { | ||
var list = subscriptions[subscription.name] | ||
list?.removeAll { it === subscription } | ||
} | ||
|
||
fun resolve(name: String, image: Image) { | ||
subscriptions[name]?.forEach { | ||
it.resolved(name, image) | ||
} | ||
} | ||
|
||
fun resolve(name: String, image: Bitmap) { | ||
resolve(name, image.toMapboxImage()) | ||
} | ||
|
||
fun resolve(name: String, image: BitmapDrawable) { | ||
resolve(name, image.bitmap) | ||
} | ||
} |
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
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
Oops, something went wrong.