Skip to content

Commit e4e3fd9

Browse files
committed
fix: correctly handle lifecycle
1 parent 90d63d1 commit e4e3fd9

File tree

2 files changed

+7
-240
lines changed

2 files changed

+7
-240
lines changed

src/mapbox.android.ts

+1-234
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ export class MapboxView extends MapboxViewBase {
413413

414414
if (!this.nativeMapView && ((this.config && this.config.accessToken) || (this.settings && this.settings.accessToken))) {
415415
this.mapbox = new Mapbox();
416-
416+
// this.mapbox.onResume();
417417
// the NativeScript contentview class extends from Observable to provide the notify method
418418
// which is the glue that joins this code with whatever callbacks are set in the Mapbox XML
419419
// tag describing the map.
@@ -4305,239 +4305,6 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
43054305
}
43064306
});
43074307
} // end of addLineAnnotation
4308-
4309-
// -------------------------------------------------------------------------------------
4310-
4311-
private async testLineAnnotation(nativeMapView) {
4312-
const geojson = {
4313-
type: 'FeatureCollection',
4314-
features: [
4315-
{
4316-
type: 'Feature',
4317-
geometry: {
4318-
type: 'LineString',
4319-
coordinates: this.getTestCoords(),
4320-
},
4321-
properties: {
4322-
'line-color': 'white',
4323-
'line-width': '8',
4324-
'line-dash-array': [2, 4, 2, 1],
4325-
},
4326-
},
4327-
],
4328-
};
4329-
4330-
const dashArray = Array.create('java.lang.Float', geojson.features[0].properties['line-dash-array'].length);
4331-
4332-
for (let i = 0; i < geojson.features[0].properties['line-dash-array'].length; i++) {
4333-
dashArray[i] = new java.lang.Float(geojson.features[0].properties['line-dash-array'][i]);
4334-
}
4335-
4336-
const line = await this.addLineAnnotation(geojson, nativeMapView);
4337-
4338-
this.lineManager.setLineDashArray(dashArray);
4339-
}
4340-
4341-
// -----------------------------------------------------------------------------------------
4342-
4343-
getTestCoords() {
4344-
return [
4345-
[-76.926164, 39.019062],
4346-
[-76.9261, 39.019168],
4347-
[-76.926013, 39.019257],
4348-
[-76.925905, 39.019328],
4349-
[-76.925777, 39.01938],
4350-
[-76.925632, 39.019408],
4351-
[-76.925481, 39.019405],
4352-
[-76.925337, 39.019372],
4353-
[-76.925209, 39.019313],
4354-
[-76.925104, 39.019234],
4355-
[-76.925026, 39.019136],
4356-
[-76.92501, 39.018851],
4357-
[-76.925054, 39.018724],
4358-
[-76.925139, 39.018616],
4359-
[-76.925252, 39.018528],
4360-
[-76.925387, 39.018465],
4361-
[-76.925539, 39.018433],
4362-
[-76.925694, 39.018422],
4363-
[-76.925857, 39.018426],
4364-
[-76.926027, 39.018437],
4365-
[-76.927847, 39.018652],
4366-
[-76.930178, 39.019155],
4367-
[-76.932151, 39.019811],
4368-
[-76.934475, 39.02073],
4369-
[-76.938543, 39.022225],
4370-
[-76.941642, 39.022854],
4371-
[-76.944704, 39.023275],
4372-
[-76.94638, 39.024124],
4373-
[-76.948033, 39.02576],
4374-
[-76.948497, 39.027019],
4375-
[-76.948306, 39.028576],
4376-
[-76.947345, 39.03015],
4377-
[-76.945672, 39.031692],
4378-
[-76.943317, 39.033067],
4379-
[-76.941067, 39.034591],
4380-
[-76.938712, 39.036849],
4381-
[-76.937134, 39.039019],
4382-
[-76.934067, 39.043621],
4383-
[-76.931722, 39.047206],
4384-
[-76.929912, 39.050756],
4385-
[-76.928589, 39.053624],
4386-
[-76.927063, 39.056683],
4387-
[-76.925731, 39.058167],
4388-
[-76.924575, 39.059077],
4389-
[-76.922749, 39.06007],
4390-
[-76.920061, 39.061071],
4391-
[-76.918383, 39.061644],
4392-
[-76.915324, 39.062765],
4393-
[-76.913071, 39.0638],
4394-
[-76.910303, 39.065627],
4395-
[-76.908491, 39.067117],
4396-
[-76.907337, 39.068725],
4397-
[-76.90608, 39.071488],
4398-
[-76.905077, 39.073318],
4399-
[-76.904587, 39.074003],
4400-
[-76.9044, 39.074114],
4401-
[-76.904184, 39.074189],
4402-
[-76.903946, 39.074212],
4403-
[-76.903712, 39.074192],
4404-
[-76.903464, 39.074145],
4405-
[-76.903301, 39.07403],
4406-
[-76.903158, 39.073875],
4407-
[-76.903071, 39.073696],
4408-
[-76.903039, 39.073516],
4409-
[-76.903065, 39.073338],
4410-
[-76.903149, 39.073168],
4411-
[-76.903282, 39.073021],
4412-
[-76.903465, 39.072896],
4413-
[-76.903679, 39.072819],
4414-
[-76.903903, 39.072786],
4415-
[-76.904124, 39.072797],
4416-
[-76.904329, 39.072851],
4417-
[-76.904518, 39.07294],
4418-
[-76.904706, 39.073029],
4419-
[-76.904855, 39.073158],
4420-
[-76.906221, 39.074084],
4421-
[-76.908129, 39.074828],
4422-
[-76.910401, 39.075078],
4423-
[-76.913482, 39.074758],
4424-
[-76.924829, 39.073772],
4425-
[-76.930687, 39.073591],
4426-
[-76.936115, 39.073664],
4427-
[-76.945228, 39.074826],
4428-
[-76.948338, 39.075918],
4429-
[-76.954834, 39.079209],
4430-
[-76.958566, 39.081175],
4431-
[-76.962182, 39.082907],
4432-
[-76.964617, 39.083332],
4433-
[-76.967407, 39.083191],
4434-
[-76.969484, 39.083412],
4435-
[-76.971742, 39.08417],
4436-
[-76.976687, 39.086114],
4437-
[-76.983025, 39.088788],
4438-
[-76.985704, 39.089512],
4439-
[-76.988488, 39.089779],
4440-
[-76.991281, 39.08959],
4441-
[-76.997539, 39.088687],
4442-
[-77.001787, 39.088312],
4443-
[-77.008541, 39.087897],
4444-
[-77.013845, 39.087128],
4445-
[-77.020459, 39.085992],
4446-
[-77.023236, 39.085835],
4447-
[-77.025211, 39.086389],
4448-
[-77.02675, 39.087508],
4449-
[-77.02771, 39.089008],
4450-
[-77.028146, 39.090903],
4451-
[-77.029034, 39.093259],
4452-
[-77.030437, 39.094859],
4453-
[-77.032618, 39.096362],
4454-
[-77.035143, 39.097464],
4455-
[-77.038513, 39.098369],
4456-
[-77.04213, 39.099532],
4457-
[-77.044851, 39.100887],
4458-
[-77.047813, 39.102913],
4459-
[-77.050996, 39.105187],
4460-
[-77.055267, 39.108274],
4461-
[-77.058337, 39.110646],
4462-
[-77.061623, 39.113689],
4463-
[-77.064504, 39.115979],
4464-
[-77.066908, 39.117065],
4465-
[-77.069589, 39.117678],
4466-
[-77.08194, 39.120455],
4467-
[-77.087705, 39.123085],
4468-
[-77.091849, 39.124533],
4469-
[-77.096482, 39.12562],
4470-
[-77.10105, 39.12621],
4471-
[-77.106463, 39.126419],
4472-
[-77.113894, 39.126642],
4473-
[-77.118437, 39.12699],
4474-
[-77.120607, 39.127777],
4475-
[-77.122318, 39.129042],
4476-
[-77.124218, 39.131225],
4477-
[-77.126393, 39.133643],
4478-
[-77.128644, 39.135491],
4479-
[-77.131388, 39.136958],
4480-
[-77.138116, 39.139101],
4481-
[-77.140084, 39.138936],
4482-
[-77.141828, 39.138163],
4483-
[-77.143102, 39.136928],
4484-
[-77.144688, 39.135612],
4485-
[-77.146269, 39.135118],
4486-
[-77.147972, 39.13511],
4487-
[-77.149904, 39.135622],
4488-
[-77.155834, 39.13733],
4489-
[-77.158453, 39.137591],
4490-
[-77.161087, 39.137398],
4491-
[-77.163593, 39.136765],
4492-
[-77.166115, 39.135549],
4493-
[-77.167949, 39.13405],
4494-
[-77.171853, 39.129988],
4495-
[-77.175581, 39.12612],
4496-
[-77.179622, 39.122026],
4497-
[-77.180894, 39.121131],
4498-
[-77.18119, 39.121005],
4499-
[-77.181495, 39.120898],
4500-
[-77.181806, 39.120804],
4501-
[-77.182127, 39.120726],
4502-
[-77.182461, 39.120671],
4503-
[-77.182803, 39.120637],
4504-
[-77.183148, 39.120626],
4505-
[-77.183494, 39.120636],
4506-
[-77.183839, 39.120665],
4507-
[-77.184182, 39.120715],
4508-
[-77.18452, 39.120787],
4509-
[-77.184852, 39.120878],
4510-
[-77.185494, 39.121106],
4511-
[-77.189478, 39.12277],
4512-
[-77.191456, 39.123177],
4513-
[-77.194133, 39.123137],
4514-
[-77.197993, 39.123036],
4515-
[-77.198559, 39.123151],
4516-
[-77.198828, 39.123246],
4517-
[-77.199081, 39.123364],
4518-
[-77.199314, 39.123501],
4519-
[-77.199519, 39.123656],
4520-
[-77.199701, 39.123827],
4521-
[-77.199863, 39.124012],
4522-
[-77.200012, 39.124209],
4523-
[-77.201714, 39.126527],
4524-
[-77.203814, 39.128927],
4525-
[-77.206368, 39.131478],
4526-
[-77.208734, 39.134112],
4527-
[-77.210918, 39.137302],
4528-
[-77.21266, 39.14068],
4529-
[-77.214526, 39.145223],
4530-
[-77.21551, 39.146948],
4531-
[-77.217811, 39.149987],
4532-
[-77.220639, 39.152707],
4533-
[-77.224698, 39.155944],
4534-
[-77.228768, 39.158858],
4535-
[-77.233073, 39.161274],
4536-
[-77.237891, 39.163827],
4537-
[-77.240401, 39.165853],
4538-
[-77.242376, 39.168174],
4539-
];
4540-
}
45414308
} // end of class Mapbox
45424309

45434310
export class Layer implements LayerCommon {

src/mapbox.common.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -940,25 +940,25 @@ export abstract class MapboxViewCommonBase extends ContentView implements Mapbox
940940
return this.mapbox.getLayers(nativeMap);
941941
}
942942
destroy(): Promise<any> {
943-
return this.mapbox.destroy(this.getNativeMapView());
943+
return this.mapbox && this.mapbox.destroy(this.getNativeMapView());
944944
}
945945
onStart(): Promise<any> {
946-
return this.mapbox.onStart(this.getNativeMapView());
946+
return this.mapbox && this.mapbox.onStart(this.getNativeMapView());
947947
}
948948
onResume(nativeMap?: any): Promise<any> {
949-
return this.mapbox.onResume(this.getNativeMapView());
949+
return this.mapbox && this.mapbox.onResume(this.getNativeMapView());
950950
}
951951
onPause(nativeMap?: any): Promise<any> {
952-
return this.mapbox.onPause(this.getNativeMapView());
952+
return this.mapbox && this.mapbox.onPause(this.getNativeMapView());
953953
}
954954
onStop(nativeMap?: any): Promise<any> {
955-
return this.mapbox.onStop(this.getNativeMapView());
955+
return this.mapbox && this.mapbox.onStop(this.getNativeMapView());
956956
}
957957
onLowMemory(nativeMap?: any): Promise<any> {
958958
return this.mapbox.onLowMemory(this.getNativeMapView());
959959
}
960960
onDestroy(nativeMap?: any): Promise<any> {
961-
return this.mapbox.onDestroy(this.getNativeMapView());
961+
return this.mapbox && this.mapbox.onDestroy(this.getNativeMapView());
962962
}
963963
}
964964

0 commit comments

Comments
 (0)