11import { MOBILE_SHAPE } from "../../lib/designTokens" ;
22import { useEffect } from "react" ;
3- import { AccessibilityInfo , Platform , View } from "react-native" ;
3+ import { AccessibilityInfo , Platform , View , useWindowDimensions } from "react-native" ;
44
55import { AppText } from "./AppText" ;
66import { Button } from "./Button" ;
@@ -20,6 +20,13 @@ export interface ToastProps {
2020
2121/** The owning screen places and dismisses feedback; actions are never implicit. */
2222export 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 ;
2330 useEffect ( ( ) => {
2431 if ( Platform . OS === "ios" ) AccessibilityInfo . announceForAccessibility ( props . message ) ;
2532 } , [ props . message ] ) ;
@@ -47,11 +54,12 @@ export function Toast(props: ToastProps) {
4754 </ AppText >
4855 ) : null }
4956 </ View >
50- { props . action ? < Button label = { props . action . label } onPress = { props . action . onPress } /> : null }
57+ { inlineAction ? action : null }
5158 { props . onDismiss ? (
5259 < IconButton accessibilityLabel = "Dismiss message" icon = "xmark" onPress = { props . onDismiss } />
5360 ) : null }
5461 </ View >
62+ { action && ! inlineAction ? < View className = "mt-2 self-end" > { action } </ View > : null }
5563 </ GlassSurface >
5664 ) ;
5765}
0 commit comments