@ray-js/robot-map 0.0.9-beta.10 → 0.0.9-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/RobotMap.js +19 -1
  2. package/package.json +2 -2
package/lib/RobotMap.js CHANGED
@@ -9,7 +9,7 @@ import "core-js/modules/web.dom-collections.iterator.js";
9
9
  /* eslint-disable @typescript-eslint/no-empty-function */
10
10
  import React, { useCallback, useEffect, useRef, useState } from 'react';
11
11
  import createInvoke from '@ray-js/webview-invoke/native';
12
- import { createWebviewContext, WebView } from '@ray-js/ray';
12
+ import { createWebviewContext, usePageEvent, WebView } from '@ray-js/ray';
13
13
  import { isEqual } from 'lodash-es';
14
14
  import { MAP_API_METHODS, MAP_CALLBACK_METHODS } from '@ray-js/robot-map-sdk';
15
15
  import { nanoid } from 'nanoid/non-secure';
@@ -79,6 +79,14 @@ const RobotMap = _ref => {
79
79
  invoke.current.listener(event);
80
80
  }
81
81
  }, []);
82
+ const destroyApp = useCallback(trigger => {
83
+ try {
84
+ var _invoke$current;
85
+ (_invoke$current = invoke.current) === null || _invoke$current === void 0 || _invoke$current.bind('destroyApp')(trigger);
86
+ } catch (error) {
87
+ // Ignore teardown bridge failures during page exit.
88
+ }
89
+ }, []);
82
90
 
83
91
  // 事件分发函数 - 这个函数是稳定的,不会随渲染变化
84
92
  const eventDispatcher = useCallback(function (eventName) {
@@ -95,6 +103,9 @@ const RobotMap = _ref => {
95
103
  // 更新回调引用
96
104
  callbacksRef.current = callbacks;
97
105
  });
106
+ usePageEvent('onUnload', () => {
107
+ destroyApp('page.onUnload');
108
+ });
98
109
  useEffect(() => {
99
110
  webviewContext.current = createWebviewContext(webviewId);
100
111
  Object.defineProperty(webviewContext.current, 'platform', {
@@ -150,6 +161,13 @@ const RobotMap = _ref => {
150
161
  appLoggerBridgeRef.current(payload);
151
162
  });
152
163
  }, []);
164
+ useEffect(() => {
165
+ return () => {
166
+ destroyApp('component.unmount');
167
+ invoke.current = null;
168
+ webviewContext.current = null;
169
+ };
170
+ }, [destroyApp]);
153
171
  useEffect(() => {
154
172
  if (mapApi && map) {
155
173
  triggersRef.current.onReceiveMap(map);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/robot-map",
3
- "version": "0.0.9-beta.10",
3
+ "version": "0.0.9-beta.11",
4
4
  "description": "机器人地图组件",
5
5
  "main": "lib/index",
6
6
  "files": [
@@ -33,7 +33,7 @@
33
33
  "@ray-js/ray": "^1.7.39"
34
34
  },
35
35
  "dependencies": {
36
- "@ray-js/robot-map-sdk": "0.0.15-beta.10",
36
+ "@ray-js/robot-map-sdk": "0.0.15-beta.11",
37
37
  "clsx": "^1.2.1",
38
38
  "nanoid": "^5.1.6"
39
39
  },