add back a fixed isViewVisible, @vfurman-gh would you mind reviewing?

This commit is contained in:
Kevin Hester
2021-02-08 12:19:35 +08:00
parent ffca8e5f47
commit 122dabefb0

View File

@@ -134,6 +134,12 @@ class MapFragment : ScreenFragment("Map"), Logging {
var mapView: MapView? = null
/**
* Mapbox native code can crash painfully if you ever call a mapbox view function while the view is not actively being show
*/
private val isViewVisible: Boolean
get() = !(mapView?.isDestroyed ?: true)
override fun onViewCreated(viewIn: View, savedInstanceState: Bundle?) {
super.onViewCreated(viewIn, savedInstanceState)
@@ -169,7 +175,8 @@ class MapFragment : ScreenFragment("Map"), Logging {
// Any times nodes change update our map
model.nodeDB.nodes.observe(viewLifecycleOwner, Observer { nodes ->
onNodesChanged(map, nodes.values)
if(isViewVisible)
onNodesChanged(map, nodes.values)
})
zoomToNodes(map)
}