|
1 | 1 | import { MOBILE_SHAPE } from "../../lib/designTokens"; |
2 | 2 | import { useEffect } from "react"; |
3 | | -import { AccessibilityInfo, Platform, View } from "react-native"; |
| 3 | +import { AccessibilityInfo, Platform, View, useWindowDimensions } from "react-native"; |
4 | 4 |
|
5 | 5 | import { AppText } from "./AppText"; |
6 | 6 | import { Button } from "./Button"; |
@@ -20,6 +20,13 @@ export interface ToastProps { |
20 | 20 |
|
21 | 21 | /** The owning screen places and dismisses feedback; actions are never implicit. */ |
22 | 22 | export function Toast(props: ToastProps) { |
| 23 | + const { fontScale } = useWindowDimensions(); |
| 24 | + // A one-line message keeps its action on the same row. Descriptions and |
| 25 | + // accessibility text sizes need the full width, so the action moves below. |
| 26 | + const inlineAction = !props.description && fontScale < 1.5; |
| 27 | + const action = props.action ? ( |
| 28 | + <Button label={props.action.label} onPress={props.action.onPress} /> |
| 29 | + ) : null; |
23 | 30 | useEffect(() => { |
24 | 31 | if (Platform.OS === "ios") AccessibilityInfo.announceForAccessibility(props.message); |
25 | 32 | }, [props.message]); |
@@ -47,15 +54,12 @@ export function Toast(props: ToastProps) { |
47 | 54 | </AppText> |
48 | 55 | ) : null} |
49 | 56 | </View> |
| 57 | + {inlineAction ? action : null} |
50 | 58 | {props.onDismiss ? ( |
51 | 59 | <IconButton accessibilityLabel="Dismiss message" icon="xmark" onPress={props.onDismiss} /> |
52 | 60 | ) : null} |
53 | 61 | </View> |
54 | | - {props.action ? ( |
55 | | - <View className="mt-2 self-end"> |
56 | | - <Button label={props.action.label} onPress={props.action.onPress} /> |
57 | | - </View> |
58 | | - ) : null} |
| 62 | + {action && !inlineAction ? <View className="mt-2 self-end">{action}</View> : null} |
59 | 63 | </GlassSurface> |
60 | 64 | ); |
61 | 65 | } |