Attempt to fix native crash in mapbox

I bet they don't like the view going away
pull/40/head
geeksville 2020-06-10 12:49:05 -07:00
rodzic c57704013f
commit 12c5edb0b7
1 zmienionych plików z 24 dodań i 16 usunięć

Wyświetl plik

@ -132,6 +132,7 @@ class MapFragment : ScreenFragment("Map"), Logging {
var mapView: MapView? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@ -141,8 +142,12 @@ class MapFragment : ScreenFragment("Map"), Logging {
mapView = v
v.onCreate(savedInstanceState)
mapView?.let { v ->
// Each time the pane is shown start fetching new map info (we do this here instead of
// onCreate because getMapAsync can die in native code if the view goes away)
v.getMapAsync { map ->
if (view != null) { // it might have gone away by now
// val markerIcon = BitmapFactory.decodeResource(context.resources, R.drawable.ic_twotone_person_pin_24)
val markerIcon =
requireActivity().getDrawable(R.drawable.ic_twotone_person_pin_24)!!
@ -155,6 +160,7 @@ class MapFragment : ScreenFragment("Map"), Logging {
}
model.nodeDB.nodes.observe(viewLifecycleOwner, Observer { nodes ->
if (view != null)
onNodesChanged(map, nodes.values)
})
@ -163,6 +169,8 @@ class MapFragment : ScreenFragment("Map"), Logging {
}
}
}
}
}
override fun onPause() {
mapView?.onPause()