-
Notifications
You must be signed in to change notification settings - Fork 0
Windows Menu Support #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SeanBarker182
wants to merge
41
commits into
main
Choose a base branch
from
feature/windows-menu
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,335
−795
Open
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
8c660da
Simplify for example
SeanBarker182 ae2c078
fix: include modules that annotate with REACT_TURBO_MODULE
SeanBarker182 f0e9e97
Merge branch 'main' into feature/windows-menu
SeanBarker182 12c9590
use turbo module
SeanBarker182 9a2c3c8
Fix fabric imports
SeanBarker182 35f6eac
Add passthrough module
SeanBarker182 c687230
Group titlebar components
SeanBarker182 fb794cd
Code style fixes
SeanBarker182 a66f7c2
lint fix
SeanBarker182 d678ee7
Simplify module
SeanBarker182 d6a01be
Fix component registration
SeanBarker182 540d1d8
Fix memory leak issue that's caused by mounting and unmounting passt…
SeanBarker182 bdc9036
Merge branch 'feature/windows-menu' of https://github.com/infinitered…
SeanBarker182 d63a9e0
generate uuid
SeanBarker182 8e735a7
Add basic menu
SeanBarker182 0f06046
Add titlebar menu
SeanBarker182 3a1ae66
More stable useGlobal for windows
SeanBarker182 fa870f6
WIP: Add windows support for useMenuItem hook
SeanBarker182 0478fd9
Merge branch 'main' into feature/windows-menu
SeanBarker182 0745644
Rename IRMenuItemManager to IRSystemMenuManager for clarity
SeanBarker182 e3cc8ad
Fix native types
SeanBarker182 210bc9a
Break out platform implementations
SeanBarker182 10e6a51
improve and document the useGlobal windows hook
SeanBarker182 a5e2ac3
Remove RNW useKeyboard return
SeanBarker182 c9f3ea5
fix imports
SeanBarker182 fbd9f0f
rename
SeanBarker182 31456f5
Merge branch 'main' into feature/windows-menu
SeanBarker182 5f7f3bb
Use a content island to listen to keyboard
SeanBarker182 ff2c72d
Make shortcuts platform specific
SeanBarker182 29df030
accept an initialValue parameter
SeanBarker182 3127ce3
fix shortcut registration
SeanBarker182 b08e6a1
Merge branch 'feature/windows-menu' of https://github.com/infinitered…
SeanBarker182 9532238
update menu config
SeanBarker182 ad64da6
Update SystemMenu shortcuts to be platform-specific for macOS and Win…
SeanBarker182 69d737f
Fix linting issues
SeanBarker182 00d4f2c
Remove redundant shortcut formatting replacement in MenuDropdownItem …
SeanBarker182 e326df8
Add Windows setup script and update readme
jamonholmgren 22561ae
Lock react-native versions and only run postinstall on macos
jamonholmgren f0dd6fe
Autolinking stuff
jamonholmgren 064e5d7
Manually include ucrt (for Jamon's machine, oof)
jamonholmgren 59f7bdd
Update lock file
SeanBarker182 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { View, type ViewStyle } from "react-native" | ||
| import { useRef, useMemo, memo } from "react" | ||
| import { themed } from "../../theme/theme" | ||
| import { Portal } from "../Portal" | ||
| import { MenuDropdownItem } from "./MenuDropdownItem" | ||
| import { useSubmenuState } from "./useSubmenuState" | ||
| import { menuSettings } from "./menuSettings" | ||
| import { type Position, type DropdownMenuItem, type MenuItem, MENU_SEPARATOR } from "./types" | ||
| import { getUUID } from "../../utils/random/getUUID" | ||
| import { Separator } from "../Separator" | ||
|
|
||
| interface MenuDropdownProps { | ||
| items: (DropdownMenuItem | typeof MENU_SEPARATOR)[] | ||
| position: Position | ||
| onItemPress: (item: MenuItem) => void | ||
| isSubmenu?: boolean | ||
| } | ||
|
|
||
| const MenuDropdownComponent = ({ items, position, onItemPress, isSubmenu }: MenuDropdownProps) => { | ||
| const portalName = useRef(`${isSubmenu ? "submenu" : "dropdown"}-${getUUID()}`).current | ||
| const { openSubmenu, submenuPosition, handleItemHover } = useSubmenuState(position) | ||
|
|
||
| const isSeparator = (item: MenuItem | typeof MENU_SEPARATOR): item is typeof MENU_SEPARATOR => { | ||
| return item === MENU_SEPARATOR | ||
| } | ||
|
|
||
| // Find the submenu item if one is open | ||
| const submenuItem = openSubmenu | ||
| ? (items.find((item) => !isSeparator(item) && item.label === openSubmenu) as | ||
| | DropdownMenuItem | ||
| | undefined) | ||
| : undefined | ||
|
|
||
| const dropdownContent = useMemo( | ||
| () => ( | ||
| <View | ||
| style={[isSubmenu ? $submenuDropdown() : $dropdown(), $menuPosition(position, isSubmenu)]} | ||
| accessibilityRole="menu" | ||
| > | ||
| {items.map((item, index) => { | ||
| if (isSeparator(item)) return <Separator key={`separator-${index}`} /> | ||
|
|
||
| return ( | ||
| <MenuDropdownItem | ||
| key={item.label} | ||
| item={item as MenuItem} | ||
| index={index} | ||
| onItemPress={onItemPress} | ||
| onItemHover={handleItemHover} | ||
| /> | ||
| ) | ||
| })} | ||
| </View> | ||
| ), | ||
| [items, isSubmenu, position.x, position.y, onItemPress, handleItemHover], | ||
| ) | ||
|
|
||
| return ( | ||
| <> | ||
| <Portal name={portalName}>{dropdownContent}</Portal> | ||
| {/* Render submenu */} | ||
| {submenuItem?.submenu && ( | ||
| <MenuDropdown | ||
| items={submenuItem.submenu} | ||
| position={submenuPosition} | ||
| onItemPress={onItemPress} | ||
| isSubmenu={true} | ||
| /> | ||
| )} | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export const MenuDropdown = memo(MenuDropdownComponent) | ||
|
|
||
| const $dropdown = themed<ViewStyle>(({ colors, spacing }) => ({ | ||
| position: "absolute", | ||
| backgroundColor: colors.cardBackground, | ||
| borderColor: colors.keyline, | ||
| borderWidth: 1, | ||
| borderRadius: 4, | ||
| minWidth: menuSettings.dropdownMinWidth, | ||
| paddingVertical: spacing.xs, | ||
| zIndex: menuSettings.zIndex.dropdown, | ||
| })) | ||
|
|
||
| const $submenuDropdown = themed<ViewStyle>(({ colors, spacing }) => ({ | ||
| position: "absolute", | ||
| backgroundColor: colors.cardBackground, | ||
| borderColor: colors.keyline, | ||
| borderWidth: 1, | ||
| borderRadius: 4, | ||
| minWidth: menuSettings.submenuMinWidth, | ||
| paddingVertical: spacing.xs, | ||
| zIndex: menuSettings.zIndex.submenu, | ||
| })) | ||
|
|
||
| const $menuPosition = (position: Position, isSubmenu: boolean | undefined) => ({ | ||
| left: position.x, | ||
| top: position.y, | ||
| zIndex: isSubmenu ? 10001 : 10000, | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move this function out of the component, since it doesn't seem to rely on anything in scope here in the component. Could either move it below the component as a hoisted
function isSeparatoror into a util somewhere.