Skip to content

Commit ef7c1e0

Browse files
authored
fix(android): Fix marker images disappearing after CodePush update (#179)
* fix(android): Support file:// and content:// URIs for marker images after CodePush - Add support for file:// and content:// URI formats in rnAssetUri - Fix marker image loading logic to properly handle CodePush bundle URIs - Update drawable resource condition to exclude URI-formatted rnAssetUri * refactor(android): Rename httpUri to assetUri for better clarity - Rename httpUri variable to assetUri to reflect that it handles multiple URI formats - The variable now correctly represents file://, content://, http://, and https:// URIs - Improves code readability and consistency with rnAssetUri naming
1 parent 443d8d4 commit ef7c1e0

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

android/src/main/java/com/mjstudio/reactnativenavermap/util/image/GetOverlayImage.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,22 @@ internal fun getOverlayImage(
5252

5353
val rnAssetUri = map["rnAssetUri"]?.toString() ?: ""
5454
// rnAssetUri starts with http if dev environment(metro server)
55-
val httpUri = map["httpUri"]?.toString() ?: if (rnAssetUri.startsWith("http")) rnAssetUri else ""
55+
// Also handle file:// and content:// URIs (e.g., from CodePush bundles)
56+
val isUriFormat = rnAssetUri.startsWith("http") ||
57+
rnAssetUri.startsWith("file://") ||
58+
rnAssetUri.startsWith("content://")
59+
val assetUri = map["httpUri"]?.toString() ?: if (isUriFormat) rnAssetUri else ""
5660
val assetName = map["assetName"]?.toString() ?: ""
5761
val reuseIdentifier = map["reuseIdentifier"]?.toString() ?: ""
5862

5963
/**
6064
* http, https, asset, file all works
6165
*/
62-
if (httpUri.isNotEmpty()) {
63-
val key = reuseIdentifier.ifEmpty { httpUri }
66+
if (assetUri.isNotEmpty()) {
67+
val key = reuseIdentifier.ifEmpty { assetUri }
6468
val imageRequest =
6569
ImageRequestBuilder
66-
.newBuilderWithSource(Uri.parse(httpUri))
70+
.newBuilderWithSource(Uri.parse(assetUri))
6771
.build()
6872
val dataSource =
6973
Fresco
@@ -110,8 +114,10 @@ internal fun getOverlayImage(
110114
return
111115
}
112116

113-
if (rnAssetUri.isNotEmpty() || assetName.isNotEmpty()) {
114-
val name = rnAssetUri.ifEmpty { assetName }
117+
// Only use drawable resource if rnAssetUri is not a URI format (file://, content://, http://, https://)
118+
// and assetName is provided, or if rnAssetUri is empty and assetName is provided
119+
if (assetName.isNotEmpty() || (rnAssetUri.isNotEmpty() && !isUriFormat)) {
120+
val name = if (assetName.isNotEmpty()) assetName else rnAssetUri
115121
val key = reuseIdentifier.ifEmpty { name }
116122
callback(
117123
OverlayImage.fromResource(getDrawableWithName(context, name)).also {

0 commit comments

Comments
 (0)