Skip to content

Commit 50535f6

Browse files
authored
feat: add presentMenu and closeMenu calls for overflowMenuPressHandler (#220)
* chore: update deps * docs: update manually closing menu * feat: add `presentMenu` and `closeMenu` calls for overflowMenuPressHandlerDropdownMenu * chore: update node in CI
1 parent fdae287 commit 50535f6

18 files changed

+1190
-935
lines changed

.github/actions/setup/action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ runs:
55
using: composite
66
steps:
77
- name: Setup Node.js
8-
uses: actions/setup-node@v3
8+
uses: actions/setup-node@v4
99
with:
10-
node-version-file: .nvmrc
10+
node-version: 'lts/*'
1111

1212
- name: Get yarn cache directory path
1313
id: yarn-cache-dir-path

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v3
15+
uses: actions/checkout@v4
1616

1717
- name: Setup
1818
uses: ./.github/actions/setup
@@ -27,7 +27,7 @@ jobs:
2727
runs-on: ubuntu-latest
2828
steps:
2929
- name: Checkout
30-
uses: actions/checkout@v3
30+
uses: actions/checkout@v4
3131

3232
- name: Setup
3333
uses: ./.github/actions/setup
@@ -39,7 +39,7 @@ jobs:
3939
runs-on: ubuntu-latest
4040
steps:
4141
- name: Checkout
42-
uses: actions/checkout@v3
42+
uses: actions/checkout@v4
4343

4444
- name: Setup
4545
uses: ./.github/actions/setup

.nvmrc

-1
This file was deleted.

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ You can fully customize what it renders inside of the `PlatformPressable` using
258258

259259
## Recipes
260260

261+
#### Closing the overflow menu from `overflowMenuPressHandlerDropdownMenu` manually
262+
263+
`overflowMenuPressHandlerDropdownMenu` supports rendering custom items in the menu. In your item's onPress handler, you can call `closeMenu` to close the menu manually.
264+
265+
```ts
266+
const { closeMenu } = useOverflowMenu();
267+
```
268+
261269
#### Customizing the overflow menu
262270

263271
The default handler for overflow menu on iOS is `overflowMenuPressHandlerActionSheet`.

example/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { registerRootComponent } from 'expo';
2+
3+
import App from './App';
4+
5+
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
6+
// It also ensures that whether you load the app in Expo Go or in a native build,
7+
// the environment is set up appropriately
8+
registerRootComponent(App);

example/package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
"@react-navigation/native": "^6.1.6",
1616
"@react-navigation/native-stack": "^6.9.12",
1717
"@react-navigation/stack": "^6.3.16",
18-
"expo": "~49.0.13",
19-
"expo-splash-screen": "~0.20.5",
20-
"expo-status-bar": "~1.6.0",
18+
"expo": "~50.0.6",
19+
"expo-splash-screen": "~0.26.4",
20+
"expo-status-bar": "~1.11.1",
2121
"react": "18.2.0",
2222
"react-dom": "18.2.0",
23-
"react-native": "0.72.5",
24-
"react-native-gesture-handler": "~2.12.0",
25-
"react-native-safe-area-context": "4.6.3",
26-
"react-native-screens": "~3.22.0",
23+
"react-native": "0.73.4",
24+
"react-native-gesture-handler": "~2.14.0",
25+
"react-native-safe-area-context": "4.8.2",
26+
"react-native-screens": "~3.29.0",
2727
"react-native-web": "~0.19.6"
2828
},
2929
"devDependencies": {
3030
"@babel/core": "^7.20.0",
31-
"@expo/webpack-config": "^19.0.0",
31+
"@expo/webpack-config": "~19.0.1",
3232
"babel-loader": "^8.1.0",
3333
"babel-plugin-module-resolver": "^4.1.0"
3434
},

example/src/screens/HomeScreen.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function HomeScreen({ navigation }: ScreenProps<'HomeScreen'>) {
3333
const { toggleTheme } = React.useContext(ThemeContext);
3434

3535
return (
36-
<ScrollView>
36+
<ScrollView contentContainerStyle={{ rowGap: 10 }}>
3737
<Text style={{ margin: 15 }}>Explore possible usages with:</Text>
3838
<Button
3939
onPress={() => _navigateTo('UsageWithIcons')}
@@ -47,6 +47,10 @@ export function HomeScreen({ navigation }: ScreenProps<'HomeScreen'>) {
4747
onPress={() => _navigateTo('UsageWithCustomOverflow')}
4848
title="Custom overflow menu action"
4949
/>
50+
<Button
51+
onPress={() => _navigateTo('UsageNativeMenu')}
52+
title="Native menu overflow"
53+
/>
5054
<Button
5155
onPress={() => _navigateTo('UsageWithOverflowComplex')}
5256
title="Overflow menu - all handlers"
@@ -67,10 +71,7 @@ export function HomeScreen({ navigation }: ScreenProps<'HomeScreen'>) {
6771
onPress={() => _navigateTo('UsageCustom')}
6872
title="Custom elements"
6973
/>
70-
<Button
71-
onPress={() => _navigateTo('UsageNativeMenu')}
72-
title="Native menu overflow"
73-
/>
74+
7475
<Button
7576
onPress={toggleTheme}
7677
title="Toggle Theme (ripple, text and icon color changes)"

example/src/screens/UsageWithOverflowComplex.tsx

+15-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
overflowMenuPressHandlerDropdownMenu,
1111
HiddenItemProps,
1212
OnOverflowMenuPressParams,
13+
useOverflowMenu,
1314
} from 'react-navigation-header-buttons';
1415
import type { ScreenProps } from '../NavTypes';
1516
import { Button } from '../components/PaddedButton';
@@ -30,10 +31,22 @@ const handlers = {
3031
overflowMenuPressHandlerActionSheet,
3132
overflowMenuPressHandlerPopupMenu,
3233
custom: function custom(obj: OnOverflowMenuPressParams) {
33-
alert('you custom function will receive:' + Object.keys(obj));
34+
alert('you custom function will receive:' + Object.keys(obj).join(', '));
3435
},
3536
};
3637

38+
const CustomViewInOverflow = () => {
39+
const { closeMenu } = useOverflowMenu();
40+
return (
41+
<View style={{ backgroundColor: 'orange', maxWidth: 200 }}>
42+
<Text onPress={closeMenu}>
43+
custom view that will only be considered for
44+
overflowMenuPressHandlerDropdownMenu
45+
</Text>
46+
</View>
47+
);
48+
};
49+
3750
export function UsageWithOverflowComplex({
3851
navigation,
3952
}: ScreenProps<'UsageWithOverflowComplex'>) {
@@ -64,12 +77,7 @@ export function UsageWithOverflowComplex({
6477
onPress={() => alert('hidden4')}
6578
/>,
6679
]}
67-
<View style={{ backgroundColor: 'orange', maxWidth: 200 }}>
68-
<Text>
69-
custom view that will only be considered for
70-
overflowMenuPressHandlerDropdownMenu
71-
</Text>
72-
</View>
80+
<CustomViewInOverflow />
7381
</OverflowMenu>
7482
),
7583
});

0 commit comments

Comments
 (0)