Skip to content

Commit bd1dd98

Browse files
gadcamclaude
andauthored
fix(android): accept null lineMetrics, clusterProperties and hitbox on ShapeSource (#4454)
Unsetting these props sends null to the manager, which threw from Dynamic.asBoolean()/asMap(). Null now clears the stored value so the Mapbox default applies (default 44x44 hitbox for hitbox). Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 4d4284c commit bd1dd98

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXShapeSource.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class RNMBXShapeSource(context: Context, private val mManager: RNMBXShapeSourceM
178178
mClusterMinPoints = clusterMinPoints
179179
}
180180

181-
fun setClusterProperties(clusterProperties: HashMap<String, Any>) {
181+
fun setClusterProperties(clusterProperties: HashMap<String, Any>?) {
182182
mClusterProperties = clusterProperties
183183
}
184184

@@ -198,7 +198,7 @@ class RNMBXShapeSource(context: Context, private val mManager: RNMBXShapeSourceM
198198
mTolerance = tolerance
199199
}
200200

201-
fun setLineMetrics(lineMetrics: Boolean) {
201+
fun setLineMetrics(lineMetrics: Boolean?) {
202202
mLineMetrics = lineMetrics
203203
}
204204

‎android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXShapeSourceManager.kt‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ class RNMBXShapeSourceManager(private val mContext: ReactApplicationContext, val
125125

126126
@ReactProp(name = "clusterProperties")
127127
override fun setClusterProperties(source: RNMBXShapeSource, map: Dynamic) {
128+
if (map.isNull) {
129+
source.setClusterProperties(null)
130+
return
131+
}
128132
val mapValue = map.asMap()
129133
if (mapValue == null) {
130134
Logger.e(LOG_TAG, "clusterProperties map is null")
@@ -189,7 +193,7 @@ class RNMBXShapeSourceManager(private val mContext: ReactApplicationContext, val
189193

190194
@ReactProp(name = "lineMetrics")
191195
override fun setLineMetrics(source: RNMBXShapeSource, lineMetrics: Dynamic) {
192-
source.setLineMetrics(lineMetrics.asBoolean())
196+
source.setLineMetrics(if (lineMetrics.isNull) null else lineMetrics.asBoolean())
193197
}
194198

195199
@ReactProp(name = "hasPressListener")
@@ -199,6 +203,10 @@ class RNMBXShapeSourceManager(private val mContext: ReactApplicationContext, val
199203

200204
@ReactProp(name = "hitbox")
201205
override fun setHitbox(source: RNMBXShapeSource, map: Dynamic) {
206+
if (map.isNull) {
207+
source.setHitbox(null)
208+
return
209+
}
202210
val mapValue = map.asMap()
203211
if (mapValue == null) {
204212
Logger.e(LOG_TAG, "hitbox map is null")

‎android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXSource.kt‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ abstract class RNMBXSource<T : Source?>(context: Context?) : AbstractMapFeature(
8989
mHasPressListener = hasPressListener
9090
}
9191

92-
fun setHitbox(map: ReadableMap) {
92+
fun setHitbox(map: ReadableMap?) {
93+
if (map == null) {
94+
mTouchHitbox = null
95+
return
96+
}
9397
val hitbox: MutableMap<String, Double> = HashMap()
9498
hitbox["width"] = map.getDouble("width")
9599
hitbox["height"] = map.getDouble("height")

0 commit comments

Comments
 (0)