Skip to content

Commit a98229c

Browse files
committed
fix(mobile): scale swipe actions with system text
1 parent a1f0e63 commit a98229c

1 file changed

Lines changed: 28 additions & 16 deletions

File tree

‎apps/mobile/src/features/home/thread-swipe-actions.tsx‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type {
2121
StyleProp,
2222
ViewStyle,
2323
} from "react-native";
24-
import { Pressable, View } from "react-native";
24+
import { Pressable, useWindowDimensions, View } from "react-native";
2525
import ReanimatedSwipeable, {
2626
type SwipeableMethods,
2727
} from "react-native-gesture-handler/ReanimatedSwipeable";
@@ -50,7 +50,6 @@ const ACTION_ICON_SIZE = 15;
5050
const COMPACT_ACTION_CIRCLE_SIZE = 28;
5151
const COMPACT_ACTION_ICON_SIZE = 13;
5252

53-
const THREAD_SWIPE_ACTIONS_WIDTH = ACTION_ITEM_WIDTH * 2;
5453
const THREAD_SWIPE_SPRING = {
5554
damping: 26,
5655
mass: 0.7,
@@ -75,8 +74,8 @@ interface ThreadSwipeSecondaryAction extends ThreadSwipeAction {
7574
readonly tone: "primary" | "secondary" | "danger";
7675
}
7776

78-
function swipeActionsWidth(hasSecondaryAction: boolean) {
79-
return hasSecondaryAction ? THREAD_SWIPE_ACTIONS_WIDTH : ACTION_ITEM_WIDTH;
77+
function swipeActionsWidth(hasSecondaryAction: boolean, itemWidth: number) {
78+
return itemWidth * (hasSecondaryAction ? 2 : 1);
8079
}
8180

8281
function resolveSecondaryAction(input: {
@@ -237,9 +236,11 @@ interface ThreadSwipeableProps {
237236
}
238237

239238
export function ThreadSwipeable(props: ThreadSwipeableProps) {
239+
const { fontScale } = useWindowDimensions();
240+
const actionItemWidth = ACTION_ITEM_WIDTH * Math.max(1, fontScale);
240241
const swipeableRef = useRef<SwipeableMethods | null>(null);
241242
const hasSecondaryAction = props.secondaryAction !== null;
242-
const actionsWidth = swipeActionsWidth(hasSecondaryAction);
243+
const actionsWidth = swipeActionsWidth(hasSecondaryAction, actionItemWidth);
243244
const fullSwipeThreshold = Math.max(actionsWidth + 44, props.fullSwipeWidth * 0.58);
244245
const fullSwipeAction =
245246
props.fullSwipeAction ?? (props.secondaryAction === undefined ? "delete" : "primary");
@@ -430,6 +431,7 @@ export function ThreadSwipeable(props: ThreadSwipeableProps) {
430431
methods: SwipeableMethods,
431432
) => {
432433
const deps = [
434+
actionItemWidth,
433435
dormant,
434436
translation,
435437
methods,
@@ -458,6 +460,7 @@ export function ThreadSwipeable(props: ThreadSwipeableProps) {
458460
>
459461
<ThreadSwipeActions
460462
backgroundColor={backgroundColor}
463+
itemWidth={actionItemWidth}
461464
compact={compactActions}
462465
fullSwipeAction={fullSwipeAction}
463466
fullSwipeThreshold={fullSwipeThreshold}
@@ -476,7 +479,16 @@ export function ThreadSwipeable(props: ThreadSwipeableProps) {
476479
rightActions.current = { deps, element };
477480
return element;
478481
};
479-
const childrenContainerStyle = useMemo(() => ({ backgroundColor }), [backgroundColor]);
482+
const childrenContainerStyle = useMemo(
483+
() => ({
484+
backgroundColor,
485+
minHeight:
486+
(compactActions ? COMPACT_ACTION_CIRCLE_SIZE : ACTION_CIRCLE_SIZE) +
487+
14 * Math.max(1, fontScale) +
488+
(compactActions ? 8 : 10),
489+
}),
490+
[backgroundColor, compactActions, fontScale],
491+
);
480492
const swipeableContainerStyle = useMemo(
481493
() => [{ backgroundColor }, containerStyle],
482494
[backgroundColor, containerStyle],
@@ -525,6 +537,7 @@ export function ThreadSwipeable(props: ThreadSwipeableProps) {
525537
function SwipeActionButton(props: {
526538
readonly accessibilityLabel: string;
527539
readonly actionsWidth: number;
540+
readonly itemWidth: number;
528541
readonly tone: "primary" | "secondary" | "danger";
529542
readonly compact: boolean;
530543
readonly entryRange: readonly [number, number];
@@ -680,11 +693,7 @@ function SwipeActionButton(props: {
680693
labelStyle,
681694
]}
682695
>
683-
<Text
684-
adjustsFontSizeToFit
685-
className="text-3xs font-t3-medium text-foreground-muted"
686-
numberOfLines={1}
687-
>
696+
<Text className="text-3xs font-t3-medium text-foreground-muted" numberOfLines={1}>
688697
{props.label}
689698
</Text>
690699
</Animated.View>
@@ -698,7 +707,7 @@ function SwipeActionButton(props: {
698707
alignItems: "center",
699708
height: "100%",
700709
justifyContent: "center",
701-
width: ACTION_ITEM_WIDTH,
710+
width: props.itemWidth,
702711
zIndex: props.stretchesOnFullSwipe ? 2 : 1,
703712
},
704713
actionStyle,
@@ -722,6 +731,7 @@ function SwipeActionButton(props: {
722731

723732
function ThreadSwipeActions(props: {
724733
readonly backgroundColor: ColorValue;
734+
readonly itemWidth: number;
725735
readonly compact: boolean;
726736
readonly fullSwipeAction?: "delete" | "primary";
727737
readonly fullSwipeThreshold: number;
@@ -732,7 +742,7 @@ function ThreadSwipeActions(props: {
732742
}) {
733743
const { fullSwipeThreshold, onFullSwipeArmedChange, secondaryAction, translation } = props;
734744
const fullSwipeIsPrimary = props.fullSwipeAction === "primary" || secondaryAction === null;
735-
const actionsWidth = swipeActionsWidth(secondaryAction !== null);
745+
const actionsWidth = swipeActionsWidth(secondaryAction !== null, props.itemWidth);
736746
useAnimatedReaction(
737747
() => -translation.value >= fullSwipeThreshold,
738748
(armed, previous) => {
@@ -755,12 +765,13 @@ function ThreadSwipeActions(props: {
755765
<SwipeActionButton
756766
accessibilityLabel={props.primaryAction.accessibilityLabel}
757767
actionsWidth={actionsWidth}
768+
itemWidth={props.itemWidth}
758769
tone={props.primaryAction.destructive === true ? "danger" : "primary"}
759770
compact={props.compact}
760771
entryRange={
761772
secondaryAction === null
762-
? [8, ACTION_ITEM_WIDTH * 0.72]
763-
: [ACTION_ITEM_WIDTH * 0.55, THREAD_SWIPE_ACTIONS_WIDTH * 0.85]
773+
? [8, props.itemWidth * 0.72]
774+
: [props.itemWidth * 0.55, actionsWidth * 0.85]
764775
}
765776
fullSwipeThreshold={props.fullSwipeThreshold}
766777
icon={props.primaryAction.icon}
@@ -773,9 +784,10 @@ function ThreadSwipeActions(props: {
773784
<SwipeActionButton
774785
accessibilityLabel={secondaryAction.accessibilityLabel}
775786
actionsWidth={actionsWidth}
787+
itemWidth={props.itemWidth}
776788
tone={secondaryAction.tone}
777789
compact={props.compact}
778-
entryRange={[8, ACTION_ITEM_WIDTH * 0.72]}
790+
entryRange={[8, props.itemWidth * 0.72]}
779791
fullSwipeThreshold={props.fullSwipeThreshold}
780792
icon={secondaryAction.icon}
781793
label={secondaryAction.label}

0 commit comments

Comments
 (0)