Repository navigation
fix(mobile): use a native split button for Android merges #26373
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
Merged
juliusmarminge
merged 3 commits into
pingdotgg:main
from
PixPMusic:fix/android-merge-split-button
Oct 28, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24"> | ||
| <path android:fillColor="#FFFFFFFF" android:pathData="M7.41,8.59L12,13.17l4.59,-4.58L18,10l-6,6 -6,-6z" /> | ||
| </vector> |
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,145 @@ | ||
| import { | ||
| Box, | ||
| DropdownMenu, | ||
| Icon, | ||
| LoadingIndicator, | ||
| RNHostView, | ||
| Row, | ||
| SplitButtonLayout, | ||
| Text, | ||
| } from "@expo/ui/jetpack-compose"; | ||
| import { | ||
| defaultMinSize, | ||
| fillMaxWidth, | ||
| rotate, | ||
| semantics, | ||
| size, | ||
| } from "@expo/ui/jetpack-compose/modifiers"; | ||
| import { useState } from "react"; | ||
| import { Pressable } from "react-native"; | ||
|
|
||
| import { useScaledTextRole } from "../../features/settings/appearance/useScaledTextRole"; | ||
| import { SymbolView } from "./AppSymbol"; | ||
| import { Button } from "./Button"; | ||
| import { MenuPopupItems } from "./MenuPopup.android"; | ||
| import { NativeThemeHost } from "./NativeThemeHost.android"; | ||
| import type { SplitButtonProps } from "./SplitButton.types"; | ||
| import { useAndroidControlSizing } from "./useAndroidControlSizing"; | ||
| import { useControlTheme } from "./useControlTheme"; | ||
|
|
||
| export function SplitButton(props: SplitButtonProps) { | ||
| const { colors } = useControlTheme(); | ||
| const typography = useScaledTextRole("footnote"); | ||
| const { scale, iconSize, mediumIconSize, menuWidth } = useAndroidControlSizing(); | ||
| const [expanded, setExpanded] = useState(false); | ||
| if (props.actions.length === 0) return <Button {...props} tone="primary" fullWidth />; | ||
| const enabled = !props.disabled && !props.loading; | ||
| const menuEnabled = props.actions.some((action) => !action.attributes?.disabled); | ||
| const buttonColors = { | ||
| containerColor: colors["--color-primary"], | ||
| contentColor: colors["--color-primary-foreground"], | ||
| disabledContainerColor: colors["--color-subtle-strong"], | ||
| disabledContentColor: colors["--color-foreground-muted"], | ||
| }; | ||
| // A usable menu beside a disabled action still takes the disabled palette, so the pair reads as one control. | ||
| const trailingColors = enabled | ||
| ? buttonColors | ||
| : { | ||
| ...buttonColors, | ||
| containerColor: buttonColors.disabledContainerColor, | ||
| contentColor: buttonColors.disabledContentColor, | ||
| }; | ||
| const label = ( | ||
| <Row verticalAlignment="center"> | ||
| {props.loading ? ( | ||
| <> | ||
| <LoadingIndicator | ||
| modifiers={[size(mediumIconSize, mediumIconSize)]} | ||
| color={colors["--color-foreground-muted"]} | ||
| /> | ||
| <Box modifiers={[size(8 * scale, 1)]} /> | ||
| </> | ||
| ) : props.icon ? ( | ||
| <> | ||
| {/* The glyph host consumes touches, so it runs the action itself. */} | ||
| <RNHostView matchContents modifiers={[size(mediumIconSize, mediumIconSize)]}> | ||
| <Pressable | ||
| accessible={false} | ||
| disabled={!enabled} | ||
| onPress={props.onPress} | ||
| importantForAccessibility="no-hide-descendants" | ||
| style={{ width: mediumIconSize, height: mediumIconSize }} | ||
| > | ||
| <SymbolView | ||
| name={props.icon} | ||
| size={mediumIconSize} | ||
| tintColor={enabled ? buttonColors.contentColor : buttonColors.disabledContentColor} | ||
| /> | ||
| </Pressable> | ||
| </RNHostView> | ||
| <Box modifiers={[size(8 * scale, 1)]} /> | ||
| </> | ||
| ) : null} | ||
| <Text style={{ ...typography, fontWeight: "500" }}>{props.label}</Text> | ||
| </Row> | ||
| ); | ||
| return ( | ||
| <NativeThemeHost | ||
| matchContents={{ vertical: true }} | ||
| ignoreSafeAreaKeyboardInsets | ||
| style={{ width: "100%" }} | ||
| > | ||
| <SplitButtonLayout modifiers={[fillMaxWidth()]}> | ||
| <SplitButtonLayout.LeadingButton | ||
| enabled={enabled} | ||
| onClick={props.onPress} | ||
| colors={buttonColors} | ||
| modifiers={[ | ||
| fillMaxWidth(), | ||
| defaultMinSize({ minHeight: 48 }), | ||
| semantics({ contentDescription: props.accessibilityLabel ?? props.label }), | ||
| ]} | ||
| > | ||
| {label} | ||
| </SplitButtonLayout.LeadingButton> | ||
| <SplitButtonLayout.TrailingButton | ||
| checked={expanded} | ||
| onCheckedChange={setExpanded} | ||
| enabled={menuEnabled} | ||
| colors={trailingColors} | ||
| modifiers={[ | ||
| defaultMinSize({ minWidth: 48, minHeight: 48 }), | ||
| semantics({ contentDescription: props.menuTitle }), | ||
| ]} | ||
| > | ||
| <DropdownMenu | ||
| expanded={expanded && menuEnabled} | ||
| onDismissRequest={() => setExpanded(false)} | ||
| color={colors["--color-card-alt"]} | ||
| > | ||
| <DropdownMenu.Trigger> | ||
| <Icon | ||
| source={require("../../../assets/icons/chevron-down.xml")} | ||
| size={iconSize} | ||
| modifiers={[rotate(expanded ? 180 : 0)]} | ||
| /> | ||
| </DropdownMenu.Trigger> | ||
| <DropdownMenu.Items> | ||
| <MenuPopupItems | ||
| menuWidth={menuWidth} | ||
| actions={props.actions} | ||
| title={props.menuTitle} | ||
| parent={null} | ||
| onPress={(action) => { | ||
| setExpanded(false); | ||
| if (action.id !== undefined) props.onPressAction(action.id); | ||
| }} | ||
| onBack={() => {}} | ||
| /> | ||
| </DropdownMenu.Items> | ||
| </DropdownMenu> | ||
| </SplitButtonLayout.TrailingButton> | ||
| </SplitButtonLayout> | ||
| </NativeThemeHost> | ||
| ); | ||
| } |
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,65 @@ | ||
| import { Pressable, View } from "react-native"; | ||
| import { AppActivityIndicator } from "./AppActivityIndicator"; | ||
| import { AppText } from "./AppText"; | ||
| import { SymbolView } from "./AppSymbol"; | ||
| import { Menu } from "./Menu"; | ||
| import type { SplitButtonProps } from "./SplitButton.types"; | ||
|
|
||
| export function SplitButton(props: SplitButtonProps) { | ||
| const active = !props.disabled; | ||
| const menuEnabled = props.actions.some((action) => !action.attributes?.disabled); | ||
| return ( | ||
| <View | ||
| className={`flex-row overflow-hidden rounded-xl border-continuous ${active ? "bg-prominent-action" : "bg-subtle-strong"}`} | ||
| > | ||
| <Pressable | ||
| accessibilityRole="button" | ||
| accessibilityLabel={props.accessibilityLabel ?? props.label} | ||
| accessibilityState={{ disabled: Boolean(props.disabled), busy: Boolean(props.loading) }} | ||
| disabled={props.disabled} | ||
| onPress={props.onPress} | ||
| className="min-h-11 min-w-0 flex-1 flex-row items-center justify-center gap-2 px-3 py-2 active:opacity-70" | ||
| > | ||
| {props.loading ? ( | ||
| <AppActivityIndicator size="small" colorClassName="accent-icon-muted" /> | ||
| ) : props.icon ? ( | ||
| <SymbolView | ||
| name={props.icon} | ||
| size={16} | ||
| tintColorClassName={active ? "accent-prominent-action-foreground" : "accent-icon-muted"} | ||
| /> | ||
| ) : null} | ||
| <AppText | ||
| className={`shrink text-center text-sm font-t3-semibold ${active ? "text-prominent-action-foreground" : "text-foreground-muted"}`} | ||
| > | ||
| {props.label} | ||
| </AppText> | ||
| </Pressable> | ||
| {props.actions.length > 0 ? ( | ||
| <View pointerEvents={menuEnabled ? "auto" : "none"}> | ||
| <Menu | ||
| title={props.menuTitle} | ||
| actions={props.actions} | ||
| onPressAction={({ nativeEvent }) => props.onPressAction(nativeEvent.event)} | ||
| > | ||
| <Pressable | ||
| accessibilityRole="button" | ||
| accessibilityLabel={props.menuTitle} | ||
| accessibilityState={{ disabled: !menuEnabled }} | ||
| disabled={!menuEnabled} | ||
| className="min-h-11 w-11 items-center justify-center border-l border-border-subtle" | ||
| > | ||
| <SymbolView | ||
| name="chevron.down" | ||
| size={13} | ||
| tintColorClassName={ | ||
| active ? "accent-prominent-action-foreground" : "accent-icon-muted" | ||
| } | ||
| /> | ||
| </Pressable> | ||
| </Menu> | ||
| </View> | ||
| ) : null} | ||
| </View> | ||
| ); | ||
| } | ||
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,14 @@ | ||
| import type { MenuAction } from "@react-native-menu/menu"; | ||
| import type { AppSymbolName } from "./AppSymbol"; | ||
|
|
||
| export interface SplitButtonProps { | ||
| readonly label: string; | ||
| readonly accessibilityLabel?: string; | ||
| readonly icon?: AppSymbolName; | ||
| readonly disabled?: boolean; | ||
| readonly loading?: boolean; | ||
| readonly onPress: () => void; | ||
| readonly menuTitle: string; | ||
| readonly actions: MenuAction[]; | ||
| readonly onPressAction: (id: string) => void; | ||
| } |
Oops, something went wrong.
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.
Disable the primary action while loading.
If a caller sets
loadingwithoutdisabled, this control reports a busy state but still acceptsonPress. Repeated presses can start the action again. Derive the primary control’s visual, accessibility, andPressabledisabled states fromprops.disabled || props.loading, as the Android implementation andButtondo. The current merge-controls caller sets both states while busy, so this affects other uses of the shared component. (raw.githubusercontent.com)