-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): add show method to MenuView component (#954)
* feat(android): add show method to MenuView component * refactor(types): re-export MenuComponentRef type * docs: update README with ref usage example
- Loading branch information
1 parent
02592ae
commit 205c4bb
Showing
7 changed files
with
106 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,38 @@ | ||
import { HostComponent, requireNativeComponent } from 'react-native'; | ||
import type { NativeMenuComponentProps } from './types'; | ||
import { | ||
findNodeHandle, | ||
HostComponent, | ||
requireNativeComponent, | ||
UIManager, | ||
} from 'react-native'; | ||
import type { MenuComponentRef, NativeMenuComponentProps } from './types'; | ||
import React, { forwardRef, useImperativeHandle, useRef } from 'react'; | ||
|
||
const MenuComponent = requireNativeComponent( | ||
const NativeMenuComponent = requireNativeComponent( | ||
'MenuView' | ||
) as HostComponent<NativeMenuComponentProps>; | ||
|
||
const MenuComponent = forwardRef<MenuComponentRef, NativeMenuComponentProps>( | ||
(props, ref) => { | ||
const nativeRef = useRef(null); | ||
|
||
useImperativeHandle( | ||
ref, | ||
() => ({ | ||
show: () => { | ||
if (nativeRef.current) { | ||
const node = findNodeHandle(nativeRef.current); | ||
const command = | ||
UIManager.getViewManagerConfig('MenuView').Commands.show; | ||
|
||
UIManager.dispatchViewManagerCommand(node, command, undefined); | ||
} | ||
}, | ||
}), | ||
[nativeRef] | ||
); | ||
|
||
return <NativeMenuComponent {...props} ref={nativeRef} />; | ||
} | ||
); | ||
|
||
export default MenuComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters