11import React from 'react'
22import { StyleProp , ViewStyle } from 'react-native'
33import { Touchable } from '@frogpond/touchable'
4- import { ContextMenuButton } from 'react-native-ios-context-menu'
4+ import { ContextMenuButton , MenuState } from 'react-native-ios-context-menu'
55import { upperFirst } from 'lodash'
66
77interface ContextMenuProps {
@@ -12,6 +12,7 @@ interface ContextMenuProps {
1212 isMenuPrimaryAction ?: boolean
1313 onPress ?: ( ) => void
1414 onPressMenuItem : ( menuKey : string ) => void | Promise < void >
15+ selectedAction ?: string
1516 title : string
1617}
1718
@@ -27,20 +28,25 @@ export const ContextMenu = React.forwardRef<
2728 isMenuPrimaryAction,
2829 onPress,
2930 onPressMenuItem,
31+ selectedAction,
3032 title,
3133 } = props
3234
3335 let menuItems = React . useMemo ( ( ) => {
34- return actions . map ( ( option ) => ( {
35- actionKey : option ,
36- actionTitle : upperFirst ( option ) ,
37- } ) )
38- } , [ actions ] )
36+ return actions . map ( ( option ) => {
37+ const menuState : MenuState = selectedAction === option ? 'on' : 'off'
38+ return {
39+ actionKey : option ,
40+ actionTitle : upperFirst ( option ) ,
41+ menuState,
42+ }
43+ } )
44+ } , [ actions , selectedAction ] )
3945
4046 return (
4147 < ContextMenuButton
4248 ref = { ref }
43- enableContextMenu = { ! disabled ?? false }
49+ enableContextMenu = { ! disabled }
4450 isMenuPrimaryAction = { isMenuPrimaryAction ?? false }
4551 menuConfig = { {
4652 menuTitle : title ?? '' ,
0 commit comments