react-native-anchored-menu 0.0.13 → 0.0.14

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-anchored-menu",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "Headless anchored context menu / popover for React Native (iOS/Android) with stable measurement (default view host).",
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,11 +49,11 @@ export function AnchoredMenuProvider({
49
49
  };
50
50
  storeRef.current = {
51
51
  getSnapshot: () => snapshot,
52
- subscribe: (listener) => {
52
+ subscribe: (listener: () => void) => {
53
53
  listeners.add(listener);
54
54
  return () => listeners.delete(listener);
55
55
  },
56
- _setSnapshot: (next) => {
56
+ _setSnapshot: (next: MenuState) => {
57
57
  snapshot = next;
58
58
  listeners.forEach((l) => l());
59
59
  },
@@ -9,7 +9,7 @@ import type { MenuState } from "../types";
9
9
  * const isOpen = useAnchoredMenuState(s => s.isOpen)
10
10
  */
11
11
  export function useAnchoredMenuState<T = MenuState>(
12
- selector: (state: MenuState) => T = ((s) => s) as any
12
+ selector: (state: MenuState) => T = ((s: MenuState) => s) as (state: MenuState) => T
13
13
  ): T {
14
14
  const store = useContext(AnchoredMenuStateContext);
15
15
  if (!store) throw new Error("AnchoredMenuProvider is missing");
@@ -1,5 +1,5 @@
1
1
  import React, { useContext, useEffect, useMemo, useRef, useState } from "react";
2
- import { Keyboard, Modal, Platform, Pressable, View } from "react-native";
2
+ import { Keyboard, Modal, Platform, Pressable, View, LayoutChangeEvent } from "react-native";
3
3
  import {
4
4
  AnchoredMenuActionsContext,
5
5
  AnchoredMenuStateContext,
@@ -44,7 +44,7 @@ export function ModalHost() {
44
44
  const [menuSize, setMenuSize] = useState<MenuSize>({ width: 0, height: 0 });
45
45
  const [keyboardHeight, setKeyboardHeight] = useState(0);
46
46
  const measureCacheRef = useRef(new Map<string, MeasureCache>());
47
- const remeasureTimeoutRef = useRef<NodeJS.Timeout | null>(null);
47
+ const remeasureTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
48
48
 
49
49
  useEffect(() => {
50
50
  if (!req) {
@@ -235,7 +235,7 @@ export function ModalHost() {
235
235
  ref={hostRef}
236
236
  collapsable={false}
237
237
  style={{ flex: 1 }}
238
- onLayout={(e) => {
238
+ onLayout={(e: LayoutChangeEvent) => {
239
239
  const { width, height } = e.nativeEvent.layout;
240
240
  if (width !== hostSize.width || height !== hostSize.height) {
241
241
  setHostSize({ width, height });
@@ -255,7 +255,7 @@ export function ModalHost() {
255
255
  }}
256
256
  pointerEvents={needsInitialMeasure ? "none" : "auto"}
257
257
  onStartShouldSetResponder={() => true}
258
- onLayout={(e) => {
258
+ onLayout={(e: LayoutChangeEvent) => {
259
259
  const { width, height } = e.nativeEvent.layout;
260
260
  if (width !== menuSize.width || height !== menuSize.height) {
261
261
  setMenuSize({ width, height });
@@ -1,5 +1,5 @@
1
1
  import React, { useContext, useEffect, useMemo, useRef, useState } from "react";
2
- import { Keyboard, Pressable, View } from "react-native";
2
+ import { Keyboard, Pressable, View, LayoutChangeEvent } from "react-native";
3
3
  import {
4
4
  AnchoredMenuActionsContext,
5
5
  AnchoredMenuStateContext,
@@ -51,7 +51,7 @@ export function ViewHost() {
51
51
  const [menuSize, setMenuSize] = useState<MenuSize>({ width: 0, height: 0 });
52
52
  const [keyboardHeight, setKeyboardHeight] = useState(0);
53
53
  const measureCacheRef = useRef(new Map<string, MeasureCache>());
54
- const remeasureTimeoutRef = useRef<NodeJS.Timeout | null>(null);
54
+ const remeasureTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
55
55
 
56
56
  useEffect(() => {
57
57
  if (!req) {
@@ -238,12 +238,12 @@ export function ViewHost() {
238
238
  elevation: 9999,
239
239
  }}
240
240
  pointerEvents="box-none"
241
- onLayout={(e) => {
242
- const { width, height } = e.nativeEvent.layout;
243
- if (width !== hostSize.width || height !== hostSize.height) {
244
- setHostSize({ width, height });
245
- }
246
- }}
241
+ onLayout={(e: LayoutChangeEvent) => {
242
+ const { width, height } = e.nativeEvent.layout;
243
+ if (width !== hostSize.width || height !== hostSize.height) {
244
+ setHostSize({ width, height });
245
+ }
246
+ }}
247
247
  >
248
248
  {/* Tap outside to dismiss */}
249
249
  <Pressable style={{ flex: 1 }} onPress={actions.close}>
@@ -260,7 +260,7 @@ export function ViewHost() {
260
260
  }}
261
261
  pointerEvents={needsInitialMeasure ? "none" : "auto"}
262
262
  onStartShouldSetResponder={() => true}
263
- onLayout={(e) => {
263
+ onLayout={(e: LayoutChangeEvent) => {
264
264
  const { width, height } = e.nativeEvent.layout;
265
265
  if (width !== menuSize.width || height !== menuSize.height) {
266
266
  setMenuSize({ width, height });
@@ -1,5 +1,5 @@
1
1
  import { InteractionManager, UIManager, findNodeHandle } from "react-native";
2
- import type { AnchorMeasurement, AnchorMargins, AnchorRefObject } from "../types";
2
+ import type { AnchorMeasurement, AnchorRefObject } from "../types";
3
3
 
4
4
  const raf = (): Promise<number> => new Promise((r) => requestAnimationFrame(r));
5
5
 
@@ -10,8 +10,10 @@ async function measureInWindowOnce(
10
10
  (target as { current?: number | null })?.current ?? target
11
11
  );
12
12
  if (!node) return null;
13
- return await new Promise((resolve) => {
14
- UIManager.measureInWindow(node, (x, y, width, height) => {
13
+ return await new Promise<AnchorMeasurement>((resolve) => {
14
+ // UIManager.measureInWindow callback signature varies by RN version
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ (UIManager.measureInWindow as any)(node, (x: number, y: number, width: number, height: number) => {
15
17
  resolve({ pageX: x, pageY: y, width, height });
16
18
  });
17
19
  });