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 var mapView: MapView? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
@ -141,25 +142,32 @@ class MapFragment : ScreenFragment("Map"), Logging {
mapView = v mapView = v
v.onCreate(savedInstanceState) v.onCreate(savedInstanceState)
v.getMapAsync { map -> 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 ->
// val markerIcon = BitmapFactory.decodeResource(context.resources, R.drawable.ic_twotone_person_pin_24) if (view != null) { // it might have gone away by now
val markerIcon = // val markerIcon = BitmapFactory.decodeResource(context.resources, R.drawable.ic_twotone_person_pin_24)
requireActivity().getDrawable(R.drawable.ic_twotone_person_pin_24)!! val markerIcon =
requireActivity().getDrawable(R.drawable.ic_twotone_person_pin_24)!!
map.setStyle(Style.OUTDOORS) { style -> map.setStyle(Style.OUTDOORS) { style ->
style.addSource(nodePositions) style.addSource(nodePositions)
style.addImage(markerImageId, markerIcon) style.addImage(markerImageId, markerIcon)
style.addLayer(nodeLayer) style.addLayer(nodeLayer)
style.addLayer(labelLayer) style.addLayer(labelLayer)
}
model.nodeDB.nodes.observe(viewLifecycleOwner, Observer { nodes ->
if (view != null)
onNodesChanged(map, nodes.values)
})
//map.uiSettings.isScrollGesturesEnabled = true
//map.uiSettings.isZoomGesturesEnabled = true
}
} }
model.nodeDB.nodes.observe(viewLifecycleOwner, Observer { nodes ->
onNodesChanged(map, nodes.values)
})
//map.uiSettings.isScrollGesturesEnabled = true
//map.uiSettings.isZoomGesturesEnabled = true
} }
} }
} }