esrieact 0.4.5 → 0.5.0

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.
@@ -0,0 +1,14 @@
1
+ import React from "react";
2
+ import EsriZoomWidget from "@arcgis/core/widgets/Zoom";
3
+ /**
4
+ * A Zoom Widget component
5
+ *
6
+ * ArcGIS JS API Source Components:
7
+ * - [Zoom](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Zoom.html)
8
+ */
9
+ export declare const Zoom: React.ForwardRefExoticComponent<__esri.ZoomProperties & {
10
+ children?: React.ReactNode;
11
+ } & {
12
+ events?: {} | ((widgetInstance: __esri.Widget) => {}) | undefined;
13
+ position?: string | __esri.UIAddPosition | undefined;
14
+ } & React.RefAttributes<EsriZoomWidget>>;
@@ -0,0 +1,16 @@
1
+ import React from "react";
2
+ import EsriZoomWidget from "@arcgis/core/widgets/Zoom";
3
+ import { createWidgetComponent } from ".";
4
+ const createWidget = (properties) => {
5
+ return new EsriZoomWidget(properties);
6
+ };
7
+ /**
8
+ * A Zoom Widget component
9
+ *
10
+ * ArcGIS JS API Source Components:
11
+ * - [Zoom](https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Zoom.html)
12
+ */
13
+ export const Zoom = React.forwardRef((properties, ref) => {
14
+ // @ts-expect-error internal mismatch of arcgis types?
15
+ return createWidgetComponent(createWidget, ref, properties);
16
+ });
@@ -20,6 +20,7 @@ export function createWidgetComponent(createWidget, ref, { children, events, pos
20
20
  const { view } = useMap();
21
21
  const parentWidgetContext = useContext(WidgetContext);
22
22
  const childrenRef = useRef(null);
23
+ const addedToViewUiRef = useRef(false);
23
24
  const instance = useMemo(() => {
24
25
  return createWidget({ ...properties, view, position });
25
26
  }, []);
@@ -31,6 +32,7 @@ export function createWidgetComponent(createWidget, ref, { children, events, pos
31
32
  else {
32
33
  if (!properties.container) {
33
34
  view.ui.add(instance, position);
35
+ addedToViewUiRef.current = true;
34
36
  }
35
37
  }
36
38
  }
@@ -41,7 +43,10 @@ export function createWidgetComponent(createWidget, ref, { children, events, pos
41
43
  if (parentWidgetContext instanceof Expand) {
42
44
  parentWidgetContext.content = "";
43
45
  }
44
- view.ui.remove(instance);
46
+ if (addedToViewUiRef.current && view) {
47
+ view.ui.remove(instance);
48
+ addedToViewUiRef.current = false;
49
+ }
45
50
  };
46
51
  }, [instance, view, parentWidgetContext]);
47
52
  useImperativeHandle(ref, () => instance);
@@ -9,3 +9,4 @@ export * from "./LayerList";
9
9
  export * from "./Legend";
10
10
  export * from "./SearchBar";
11
11
  export * from "./Sketch";
12
+ export * from "./Zoom";
@@ -9,3 +9,4 @@ export * from "./LayerList";
9
9
  export * from "./Legend";
10
10
  export * from "./SearchBar";
11
11
  export * from "./Sketch";
12
+ export * from "./Zoom";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "esrieact",
3
3
  "private": false,
4
- "version": "0.4.5",
4
+ "version": "0.5.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [