Skip to content

Commit ec64c94

Browse files
committed
1.8
1 parent 8af0138 commit ec64c94

File tree

10 files changed

+104
-40
lines changed

10 files changed

+104
-40
lines changed

docs/docs/components/context-menu.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,27 @@ Android menu items do not currently support subtitles.
303303

304304
Used to group multiple items.
305305

306+
On iOS, items will visually group with a divider like `Group Item 1` and `Group Item 2` below:
307+
308+
<img src="/img/group.png" />
309+
310+
On iOS, you can use the `horizontal` prop render items like so:
311+
312+
<img width="400" alt="image" src="https://github.com/nandorojo/zeego/assets/13172299/6d927c98-c29d-4732-95ca-2bec725d487e" />
313+
314+
| Prop | Required | Default | Platforms |
315+
| ------------ | -------- | ------- | ------------------------ |
316+
| `children` | | | `web` , `ios`, `android` |
317+
| `horizontal` | | | `ios` |
318+
319+
To add a title to the group, pass a `Label` component inside of it:
320+
321+
```tsx
322+
<ContextMenu.Group>
323+
<ContextMenu.Label>Fernando</ContextMenu.Label>
324+
</ContextMenu.Group>
325+
```
326+
306327
<!-- On iOS, items will visually group with a divider like `Group Item 1` and `Group Item 2` below:
307328

308329
<img src="/img/group.png"></img> -->

docs/docs/components/dropdown-menu.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,23 @@ On iOS, items will visually group with a divider like `Group Item 1` and `Group
272272

273273
<img src="/img/group.png" />
274274

275+
On iOS, you can use the `horizontal` prop render items like so:
276+
277+
<img width="400" alt="image" src="https://github.com/nandorojo/zeego/assets/13172299/6d927c98-c29d-4732-95ca-2bec725d487e" />
278+
279+
| Prop | Required | Default | Platforms |
280+
| ------------ | -------- | ------- | ------------------------ |
281+
| `children` | | | `web` , `ios`, `android` |
282+
| `horizontal` | | | `ios` |
283+
284+
To add a title to the group, pass a `Label` component inside of it:
285+
286+
```tsx
287+
<DropdownMenu.Group>
288+
<DropdownMenu.Label>Fernando</DropdownMenu.Label>
289+
</DropdownMenu.Group>
290+
```
291+
275292
### CheckboxItem
276293

277294
Usage is similar to [`Item`](#item) with added checkbox features.

docs/docs/start.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ yarn add react-native-ios-context-menu react-native-ios-utilities
2828
yarn add @react-native-menu/menu
2929
```
3030

31-
If you're using an Expo Development Client, there are some additional steps:
31+
#### Expo SDK 49 or lower
32+
33+
If you're using an older version Expo Development Client, there are some additional steps:
3234

3335
```yarn
3436
npx expo install expo-build-properties
@@ -40,20 +42,20 @@ Next, add this to your app config's plugins array:
4042
export default {
4143
plugins: [
4244
[
43-
"expo-build-properties",
45+
'expo-build-properties',
4446
{
4547
android: {
4648
// these values were tested with Expo SDK 48
4749
compileSdkVersion: 33,
4850
targetSdkVersion: 33,
4951
minSdkVersion: 23,
50-
buildToolsVersion: "33.0.0",
51-
kotlinVersion: "1.6.20",
52+
buildToolsVersion: '33.0.0',
53+
kotlinVersion: '1.6.20',
5254
},
5355
},
5456
],
5557
],
56-
};
58+
}
5759
```
5860

5961
If you know your way around these, you may be able to adjust them. But if you get an error related to `react-native-menu` when building, please reference these properties.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"react-native": "0.64.2",
5555
"react-native-builder-bob": "^0.18.0",
5656
"release-it": "^14.2.2",
57-
"typescript": "^4.4",
57+
"typescript": "^5",
5858
"lerna": "^3.22.1"
5959
},
6060
"peerDependencies": {
@@ -122,7 +122,6 @@
122122
"@expo/config-plugins": "^5.0.0",
123123
"@expo/prebuild-config": "^5.0.1",
124124
"react": "18.0.0",
125-
"metro": "0.72.3",
126-
"typescript": "4.8.4"
125+
"metro": "0.72.3"
127126
}
128127
}

packages/zeego/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"react-native-builder-bob": "^0.18.0",
7575
"react-native-ios-utilities": "^4.3.2",
7676
"release-it": "^14.2.2",
77-
"typescript": "^4.4"
77+
"typescript": "^5"
7878
},
7979
"peerDependencies": {
8080
"@react-native-menu/menu": "*",

packages/zeego/src/menu/children.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,12 @@ export const pickChildren = <Props = any>(
8585
}
8686
}
8787

88-
export const isInstanceOfComponent = (
89-
element: React.ReactElement | React.ReactChild | undefined,
90-
targetElement: React.ElementType
91-
) => {
88+
type PropsFromElementType<T> = T extends React.ElementType<infer P> ? P : never
89+
90+
export const isInstanceOfComponent = <Props>(
91+
element: React.ReactElement | React.ReactText | undefined,
92+
targetElement: React.ComponentType<Props>
93+
): element is NonNullable<React.ReactElement<Props>> => {
9294
const matches =
9395
(element as any)?.type === targetElement ||
9496
(typeof (element as any)?.type == 'function' &&

packages/zeego/src/menu/create-ios-menu/index.ios.tsx

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import {
3333
ContextMenuButton,
3434
ContextMenuView,
3535
MenuActionConfig,
36+
MenuConfig,
37+
MenuElementAtrributes,
38+
MenuElementSize,
3639
} from 'react-native-ios-context-menu'
3740
import { create } from '../display-names'
3841
import type { ImageSystemConfig } from 'react-native-ios-context-menu/src/types/ImageItemConfig'
@@ -159,28 +162,12 @@ If you want to use a custom component as your <Content />, you can use the creat
159162
}, 'Label')
160163

161164
type MenuOption = 'destructive' | 'displayInline'
162-
type MenuAttribute = 'disabled' | 'destructive' | 'hidden'
165+
type MenuAttribute = keyof typeof MenuElementAtrributes
163166

164167
type MenuAttributes = MenuAttribute[]
165168
type MenuOptions = MenuOption[]
166169

167-
type MenuConfig = {
168-
menuTitle: string
169-
menuItems: (MenuItem | MenuConfig)[]
170-
menuAttributes?: MenuAttributes
171-
menuOptions?: MenuOptions
172-
icon?: MenuActionConfig['icon']
173-
}
174-
175-
type MenuItem = {
176-
actionKey: string
177-
actionTitle: string
178-
discoverabilityTitle?: string
179-
menuAttributes?: MenuAttributes
180-
menuOptions?: MenuOptions
181-
icon?: MenuActionConfig['icon']
182-
menuState?: 'on' | 'off' | 'mixed'
183-
}
170+
type MenuItem = MenuActionConfig
184171

185172
const Root = create((props: MenuRootProps) => {
186173
const trigger = pickChildren<MenuTriggerProps>(props.children, Trigger)
@@ -345,7 +332,7 @@ If you want to use a custom component as your <Content />, you can use the creat
345332
): ((MenuItem | MenuConfig) | null)[] => {
346333
return Children.map(flattenChildren(children), (_child, index) => {
347334
if (isInstanceOfComponent(_child, Item)) {
348-
const child = _child as ReactElement<MenuItemProps>
335+
const child = _child
349336

350337
const item = getItemFromChild(child, index)
351338
if (item) {
@@ -360,7 +347,7 @@ If you want to use a custom component as your <Content />, you can use the creat
360347
return finalItem
361348
}
362349
} else if (isInstanceOfComponent(_child, CheckboxItem)) {
363-
const child = _child as ReactElement<MenuCheckboxItemProps>
350+
const child = _child
364351

365352
const item = getItemFromChild(child, index)
366353
if (item) {
@@ -384,7 +371,7 @@ If you want to use a custom component as your <Content />, you can use the creat
384371
return finalItem
385372
}
386373
} else if (isInstanceOfComponent(_child, Sub)) {
387-
const child = _child as ReactElement<MenuRootProps>
374+
const child = _child
388375
const triggerItemChild = pickChildren<MenuSubTriggerProps>(
389376
child.props.children,
390377
SubTrigger
@@ -414,6 +401,7 @@ If you want to use a custom component as your <Content />, you can use the creat
414401
icon: triggerItem?.icon,
415402
menuItems: nestedItems,
416403
menuOptions,
404+
// @ts-expect-error
417405
menuAttributes: triggerItem.menuAttributes,
418406
}
419407
return menuConfig
@@ -427,10 +415,30 @@ If you want to use a custom component as your <Content />, you can use the creat
427415
filterNull
428416
)
429417

418+
const groupTitle = pickChildren<MenuLabelProps>(
419+
child.props.children,
420+
Label
421+
).targetChildren?.[0]?.props.children
422+
423+
let menuPreferredElementSize: MenuElementSize | undefined
424+
425+
if (child.props.horizontal) {
426+
const hasGroupItemWithText = groupItems.some((item) => {
427+
return item.type === 'action' && item.actionTitle
428+
})
429+
430+
if (hasGroupItemWithText) {
431+
menuPreferredElementSize = 'medium'
432+
} else {
433+
menuPreferredElementSize = 'small'
434+
}
435+
}
436+
430437
return {
431-
menuTitle: '',
438+
menuTitle: groupTitle || '',
432439
menuItems: groupItems,
433440
menuOptions: ['displayInline'],
441+
menuPreferredElementSize: menuPreferredElementSize,
434442
}
435443
}
436444
return null

packages/zeego/src/menu/types.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
import type {
99
ImageOptions,
1010
ImageSystemSymbolConfiguration,
11-
} from 'react-native-ios-context-menu/lib/typescript/types/ImageItemConfig'
11+
} from 'react-native-ios-context-menu/src/types/ImageItemConfig'
1212
import type { ComponentProps, SVGAttributes } from 'react'
1313

1414
import type { SFSymbol } from 'sf-symbols-typescript'
@@ -81,6 +81,12 @@ export type ContextMenuContentProps = Not<
8181
export type MenuGroupProps = {
8282
children: React.ReactNode
8383
style?: ViewStyle
84+
/**
85+
* iOS-only
86+
*
87+
* Makes the menu items be in a row. Defaults to `false`.
88+
*/
89+
horizontal?: boolean
8490
}
8591

8692
export type MenuItemProps = {
@@ -167,7 +173,7 @@ export type MenuSubTriggerProps = Omit<
167173
}
168174

169175
export type MenuSubProps = {
170-
children?: React.ReactNode
176+
children: React.ReactNode
171177
}
172178

173179
export type MenuSubContentProps = Not<MenuContentProps, 'side' | 'align'>

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"compilerOptions": {
33
"baseUrl": ".",
44
"paths": {
5-
"@zeego/*": ["./packages/*/src"],
65
"zeego": ["./packages/zeego/src"]
76
},
87
"allowUnreachableCode": false,
@@ -26,5 +25,5 @@
2625
"target": "esnext",
2726
"noEmit": true
2827
},
29-
"exclude": ["examples"]
28+
"exclude": ["examples", "node_modules", "../../node_modules/**/*"]
3029
}

yarn.lock

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18756,6 +18756,11 @@ react-native-ios-context-menu@2.3.2:
1875618756
dependencies:
1875718757
"@dominicstop/ts-event-emitter" "^1.1.0"
1875818758

18759+
react-native-ios-utilities@^4.3.2:
18760+
version "4.3.2"
18761+
resolved "https://registry.yarnpkg.com/react-native-ios-utilities/-/react-native-ios-utilities-4.3.2.tgz#5d9cf50b7388d2b72752aee9d51ce172b96c0fd6"
18762+
integrity sha512-pcQoix3ILMmHQkxkwBVVCWU0+q7BbVKCqJ5O/fLxe+PQQnJUCyZLFW7im9J4oUGYfxL7xAXal081lSBP9mWA4w==
18763+
1875918764
react-native-reanimated@~2.9.1:
1876018765
version "2.9.1"
1876118766
resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-2.9.1.tgz#d9a932e312c13c05b4f919e43ebbf76d996e0bc1"
@@ -21490,11 +21495,16 @@ typedarray@^0.0.6:
2149021495
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
2149121496
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
2149221497

21493-
typescript@4.8.4, typescript@^4.0.2, typescript@^4.4:
21498+
typescript@^4.0.2:
2149421499
version "4.8.4"
2149521500
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.4.tgz#c464abca159669597be5f96b8943500b238e60e6"
2149621501
integrity sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==
2149721502

21503+
typescript@^5:
21504+
version "5.3.3"
21505+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
21506+
integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==
21507+
2149821508
ua-parser-js@^0.7.30:
2149921509
version "0.7.31"
2150021510
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.31.tgz#649a656b191dffab4f21d5e053e27ca17cbff5c6"

0 commit comments

Comments
 (0)