Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(mobile): undo toasts keep their action on one row #23910

Mergedsaphid(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/23910/headmerged by juliusmarminge View on GitHub

Showing 1 changed file with 10 additions and 6 deletions.

x
0 of 1 viewed, 1 left
10 additions and 6 deletionsapps/mobile/src/components/ui/Toast.tsxModified
View file
@@ -1,6 +1,6 @@
import { MOBILE_SHAPE } from "../../lib/designTokens";
import { useEffect } from "react";
-import { AccessibilityInfo, Platform, View } from "react-native";
+import { AccessibilityInfo, Platform, View, useWindowDimensions } from "react-native";
​
import { AppText } from "./AppText";
import { Button } from "./Button";
@@ -20,6 +20,13 @@
​
/** The owning screen places and dismisses feedback; actions are never implicit. */
export function Toast(props: ToastProps) {
+ const { fontScale } = useWindowDimensions();
+ // A one-line message keeps its action on the same row. Descriptions and
+ // accessibility text sizes need the full width, so the action moves below.
+ const inlineAction = !props.description && fontScale < 1.5;
+ const action = props.action ? (
+ <Button label={props.action.label} onPress={props.action.onPress} />
+ ) : null;
useEffect(() => {
if (Platform.OS === "ios") AccessibilityInfo.announceForAccessibility(props.message);
}, [props.message]);
@@ -47,15 +54,12 @@
</AppText>
) : null}
</View>
+ {inlineAction ? action : null}
{props.onDismiss ? (
<IconButton accessibilityLabel="Dismiss message" icon="xmark" onPress={props.onDismiss} />