Skip to content

Commit dee809b

Browse files
committed
enable checkmark for selected item on context menu
1 parent 6d699ca commit dee809b

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

modules/context-menu/index.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import {StyleProp, ViewStyle} from 'react-native'
33
import {Touchable} from '@frogpond/touchable'
4-
import {ContextMenuButton} from 'react-native-ios-context-menu'
4+
import {ContextMenuButton, MenuState} from 'react-native-ios-context-menu'
55
import {upperFirst} from 'lodash'
66

77
interface 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 ?? '',

source/views/transportation/bus/components/day-picker.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ export const DayPickerHeader = ({
193193
onDaySelect(selectedDayData.day)
194194
}
195195
}}
196+
selectedAction={selectedLabel}
196197
title="Pick a schedule"
197198
>
198199
<View style={[styles.headerButtonContainer, {borderColor: accentColor}]}>

0 commit comments

Comments
 (0)