Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.view.View
import com.facebook.react.bridge.*
import com.facebook.react.common.MapBuilder
//import com.facebook.react.common.MapBuilder

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls remove instead of commenting

import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.annotations.ReactProp
import com.facebook.react.viewmanagers.RNMBXImagesManagerInterface
Expand All @@ -15,7 +15,7 @@ import com.mapbox.maps.ImageStretches
import com.rnmapbox.rnmbx.components.AbstractEventEmitter
import com.rnmapbox.rnmbx.events.constants.EventKeys
import com.rnmapbox.rnmbx.events.constants.eventMapOf
import com.rnmapbox.rnmbx.rncompat.dynamic.*
//import com.rnmapbox.rnmbx.rncompat.dynamic.*
import com.rnmapbox.rnmbx.utils.ImageEntry
import com.rnmapbox.rnmbx.utils.Logger
import com.rnmapbox.rnmbx.utils.ResourceUtils
Expand Down Expand Up @@ -249,10 +249,14 @@ class RNMBXImagesManager(private val mContext: ReactApplicationContext) :
Logger.e("RNMBXImages", "each element of strech should be an array but was: ${array.getDynamic(i)}")
} else {
val pair = array.getArray(i)
if (pair.size() != 2 || pair.getType(0) != ReadableType.Number || pair.getType(1) != ReadableType.Number) {
Logger.e("RNMBXImages", "each element of stretch should be pair of 2 integers but was ${pair}")
if (pair != null) {
Comment thread
ShahilMangroliya marked this conversation as resolved.
if (pair.size() != 2 || pair.getType(0) != ReadableType.Number || pair.getType(1) != ReadableType.Number) {
Logger.e("RNMBXImages", "each element of stretch should be pair of 2 integers but was ${pair}")
}
result.add(ImageStretches(pair.getDouble(0).toFloat(), pair.getDouble(1).toFloat()))
} else {
Logger.e("RNMBXImages", "each element of stretch should be an array but was null")
}
result.add(ImageStretches(pair.getDouble(0).toFloat(), pair.getDouble(1).toFloat()))
}
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import android.widget.FrameLayout
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.lifecycle.ViewTreeLifecycleOwner
import androidx.lifecycle.setViewTreeLifecycleOwner
import com.facebook.react.bridge.*
import com.mapbox.android.gestures.*
import com.mapbox.bindgen.Value
Expand Down Expand Up @@ -76,6 +76,7 @@ import com.rnmapbox.rnmbx.v11compat.ornamentsettings.*
import org.json.JSONException
import org.json.JSONObject


fun <T> MutableList<T>.removeIf21(predicate: (T) -> Boolean): Boolean {
var removed = false
val iterator = this.iterator()
Expand Down Expand Up @@ -131,11 +132,11 @@ class RNMBXLifeCycle {
}
}

override fun getLifecycle(): Lifecycle {
return lifecycleRegistry
}
override val lifecycle: Lifecycle
get() = lifecycleRegistry

}
ViewTreeLifecycleOwner.set(view, lifecycleOwner);
view.setViewTreeLifecycleOwner(lifecycleOwner)
}
lifecycleOwner?.handleLifecycleEvent(Lifecycle.Event.ON_START)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import java.util.HashMap

fun ReadableArray.forEachString(action: (String) -> Unit) {
for (i in 0 until size()) {
action(getString(i))
getString(i)?.let { action(it) } ?: Logger.d("RNMBXMapViewManager", "Skipping null string at index $i")
}
}

fun ReadableArray.asArrayString(): Array<String> {
val result = Array<String>(size()) {
getString(it)
getString(it).toString()
}
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ class RNMBXStyleValue(config: ReadableMap) {
val result = ArrayList<Double>(arr!!.size())
for (i in 0 until arr.size()) {
val item = arr.getMap(i)
result.add(item.getDouble("value"))
if (item != null) {
result.add(item.getDouble("value"))
} else {
Logger.e("RNMBXStyleValue", "getFloatArray: null value for item: $i")
}
}
return result
}
Expand All @@ -104,7 +108,7 @@ class RNMBXStyleValue(config: ReadableMap) {
val result = ArrayList<String>(arr!!.size())
for (i in 0 until arr.size()) {
val item = arr.getMap(i)
val value = item.getString("value")
val value = item?.getString("value")
if (value != null) {
result.add(value)
} else {
Expand All @@ -121,9 +125,11 @@ class RNMBXStyleValue(config: ReadableMap) {
val result = WritableNativeMap()
for (i in 0 until keyValues!!.size()) {
val keyValue = keyValues.getArray(i)
val stringKey = keyValue.getMap(0).getString("value")
val stringKey = keyValue?.getMap(0)?.getString("value")
val value = WritableNativeMap()
value.merge(keyValue.getMap(1))
if (keyValue != null) {
keyValue.getMap(1)?.let { value.merge(it) }
}
result.putMap(stringKey!!, value)
}
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class RNMBXShapeSourceManager(private val mContext: ReactApplicationContext, val
)
ReadableType.Boolean -> Expression.literal(expressions.getBoolean(iExp))
ReadableType.Number -> Expression.literal(expressions.getDouble(iExp))
else -> Expression.literal(expressions.getString(iExp))
else -> expressions.getString(iExp)?.let { Expression.literal(it) }!!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a log here as well?

}
builder.add(argument)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReadableType
import com.facebook.react.uimanager.annotations.ReactProp
import com.rnmapbox.rnmbx.components.AbstractEventEmitter
import com.rnmapbox.rnmbx.utils.Logger

abstract class RNMBXTileSourceManager<T : RNMBXTileSource<*>> internal constructor(
reactApplicationContext: ReactApplicationContext
Expand Down Expand Up @@ -41,7 +42,7 @@ abstract class RNMBXTileSourceManager<T : RNMBXTileSource<*>> internal construct
val urls: MutableList<String> = ArrayList()
for (i in 0 until tileUrlTemplates.asArray().size()) {
if (tileUrlTemplates.asArray().getType(0) == ReadableType.String) {
urls.add(tileUrlTemplates.asArray().getString(i))
tileUrlTemplates.asArray().getString(i)?.let { urls.add(it) } ?: Logger.d("RNMBXTileSource", "Skipping null URL template at index $i")
}
}
source!!.tileUrlTemplates = urls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.mapbox.turf.TurfMeasurement
import com.mapbox.turf.TurfMisc
import com.rnmapbox.rnmbx.NativeRNMBXChangeLineOffsetsShapeAnimatorModuleSpec
import com.rnmapbox.rnmbx.utils.ViewRefTag
import com.rnmapbox.rnmbx.utils.Logger

class ChangeLineOffsetsShapeAnimator(tag: Tag, _lineString: LineString, startOffset: Double, endOffset: Double): ShapeAnimatorCommon(tag) {
private var lineString = _lineString
Expand Down Expand Up @@ -210,8 +211,13 @@ private fun buildLineString(_coordinates: ReadableArray): LineString {

for (i in 0 until _coordinates.size()) {
val arr = _coordinates.getArray(i)
val coord = Point.fromLngLat(arr.getDouble(0), arr.getDouble(1))
coordinates = coordinates.plus(coord)

val coord = arr?.let { Point.fromLngLat(arr.getDouble(0), it.getDouble(1)) }
if(coord != null) {
coordinates = coordinates.plus(coord)
} else {
Logger.e("RNMBXChangeLineOffsetsShapeAnimatorModule", "buildLineString: null coordinate for item: $i")
}
}

return LineString.fromLngLats(coordinates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.ReadableType
import com.mapbox.bindgen.Value
import com.rnmapbox.rnmbx.rncompat.dynamic.*
import com.rnmapbox.rnmbx.utils.Logger

fun ReadableMap.toValueHashMap(): HashMap<String, Value> {
var result = hashMapOf<String, Value>()
Expand Down Expand Up @@ -33,15 +34,18 @@ fun ReadableArray.toValue(): Value {
var result = ArrayList<Value>(size())

for (i in 0 until size()) {
result.add(
when (getType(i)) {
ReadableType.Null -> Value.nullValue()
ReadableType.Boolean -> Value.valueOf(getBoolean(i))
ReadableType.Number -> Value.valueOf(getDouble(i))
ReadableType.String -> Value.valueOf(getString(i))
ReadableType.Array -> getArray(i).toValue()
ReadableType.Map -> getMap(i).toValue()
})
ReadableType.String -> getString(i)?.let { Value.valueOf(it) } ?: Logger.d("ReadableArray", "Skipping null string at index $i")
ReadableType.Array -> getArray(i)?.toValue()
ReadableType.Map -> getMap(i)?.toValue()
}?.let {
result.add(
it as Value
)
}
}
return Value.valueOf(result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ fun ReadableArray.toJsonArray() : JsonArray {
val result = JsonArray(size())
for (i in 0 until size()) {
when (getType(i)) {
ReadableType.Map -> result.add(getMap(i).toJsonObject())
ReadableType.Array -> result.add(getArray(i).toJsonArray())
ReadableType.Map -> result.add(getMap(i)?.toJsonObject())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls log here as well

ReadableType.Array -> result.add(getArray(i)?.toJsonArray())
ReadableType.Null -> result.add(null as JsonElement?)
ReadableType.Number -> result.add(getDouble(i))
ReadableType.String -> result.add(getString(i))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fun ReadableMap.forEach(action: (String, Any) -> Unit) {
val iterator = this.entryIterator
while (iterator.hasNext()) {
val next = iterator.next()
action(next.key, next.value)
next.value?.let { action(next.key, it) } ?: Logger.d("ReadableMap", "Skipping null value for key: ${next.key}")
}
}
fun ReadableMap.getIfDouble(key: String): Double? {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.rnmapbox.rnmbx.rncompat.readable_map
import com.facebook.react.bridge.ReadableMap

fun ReadableMap.getEntryIterator(): Iterator<Map. Entry<String, Any>>
fun ReadableMap.getEntryIterator(): Iterator<Map.Entry<String, Any?>>
{
return this.entryIterator
}