diff --git a/src/UIMenuView.ios.tsx b/src/UIMenuView.ios.tsx index e5b69411..58550976 100644 --- a/src/UIMenuView.ios.tsx +++ b/src/UIMenuView.ios.tsx @@ -1,5 +1,5 @@ import type * as React from "react"; -import { forwardRef, useImperativeHandle } from "react"; +import { forwardRef, useImperativeHandle, useRef } from "react"; import UIMenuNativeComponent from "./NativeModuleSpecs/UIMenuNativeComponent"; import type { MenuComponentRef } from "./types"; @@ -8,23 +8,27 @@ type NativeProps = Omit< "ref" >; +type NativeRef = React.ComponentRef; + +const show = () => { + if (__DEV__) { + console.warn( + "MenuView: show() is only supported on Android and does nothing on iOS.", + ); + } +}; + const MenuComponent = forwardRef( (props, ref) => { + const nativeRef = useRef(null); + useImperativeHandle( ref, - () => ({ - show: () => { - if (__DEV__) { - console.warn( - "MenuView: show() is only supported on Android and does nothing on iOS.", - ); - } - }, - }), + () => Object.assign(nativeRef.current as NativeRef, { show }), [], ); - return ; + return ; }, );