Skip to content

Commit 299a7a9

Browse files
mateoguzmanafacebook-github-bot
authored andcommitted
Improve ToastAndroid jsdocs (#48779)
Summary: Was looking into improving some of the type definitions for the `ToastAndroid` component and found out also that some of the options don't work anymore from API 30 – I revamped a bit these definitions to reflect that as I saw questions about it online. These updates could also be added to the website later. ## Changelog: [GENERAL][CHANGED] - Improve ToastAndroid jsdocs Pull Request resolved: #48779 Test Plan: Check the jsdocs look good when using the `ToastAndroid` component in the code. Reviewed By: cortinico Differential Revision: D68393949 Pulled By: Abbondanzo fbshipit-source-id: 4be318062483db5be3825b7b21f540030f6c5b10
1 parent 44d84f2 commit 299a7a9

File tree

1 file changed

+68
-6
lines changed

1 file changed

+68
-6
lines changed

packages/react-native/Libraries/Components/ToastAndroid/ToastAndroid.d.ts

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,92 @@
1616
*
1717
* There is also a function `showWithGravity` to specify the layout gravity. May be
1818
* ToastAndroid.TOP, ToastAndroid.BOTTOM, ToastAndroid.CENTER
19+
*
20+
* **Note**: Starting from Android API level 30 (Android R) or higher, for apps targeting
21+
* that API level, setting toast gravity is a no-op for text toasts.
22+
* This means that in many cases `TOP`, `BOTTOM`, `CENTER`, or offsets may not have
23+
* any visible effect on actual toast positioning.
24+
*
25+
* Reference: https://developer.android.com/reference/android/widget/Toast#setGravity(int,%20int,%20int)
1926
*/
2027
export interface ToastAndroidStatic {
2128
/**
22-
* String message: A string with the text to toast
23-
* int duration: The duration of the toast.
24-
* May be ToastAndroid.SHORT or ToastAndroid.LONG
29+
* Display a toast message for a specified duration.
30+
*
31+
* @param message A string with the text to toast.
32+
* @param duration The duration of the toast–either ToastAndroid.SHORT or ToastAndroid.LONG
2533
*/
2634
show(message: string, duration: number): void;
27-
/** `gravity` may be ToastAndroid.TOP, ToastAndroid.BOTTOM, ToastAndroid.CENTER */
35+
36+
/**
37+
* Display a toast message for a specified duration with a given gravity.
38+
*
39+
* @param message A string with the text to display in the toast.
40+
* @param duration The duration of the toast.
41+
* May be `ToastAndroid.SHORT` or `ToastAndroid.LONG`.
42+
* @param gravity Positioning on the screen, e.g.,
43+
* `ToastAndroid.TOP`, `ToastAndroid.BOTTOM`, or `ToastAndroid.CENTER`.
44+
*
45+
* **Note**: On Android R (API 30) or later (when targeting API 30+), this setting may
46+
* not have any effect on text toast placement due to `setGravity` becoming a no-op.
47+
*/
2848
showWithGravity(message: string, duration: number, gravity: number): void;
2949

50+
/**
51+
* Display a toast message for a specified duration with a given gravity and custom offsets.
52+
*
53+
* @param message A string with the text to display in the toast.
54+
* @param duration The duration of the toast.
55+
* May be `ToastAndroid.SHORT` or `ToastAndroid.LONG`.
56+
* @param gravity Positioning on the screen, e.g.,
57+
* `ToastAndroid.TOP`, `ToastAndroid.BOTTOM`, or `ToastAndroid.CENTER`.
58+
* @param xOffset Horizontal offset from the given gravity.
59+
* @param yOffset Vertical offset from the given gravity.
60+
*
61+
* **Note**: On Android R (API 30) or later (when targeting API 30+), setting gravity
62+
* and offsets may not visibly affect the placement of text toasts.
63+
*/
3064
showWithGravityAndOffset(
3165
message: string,
3266
duration: number,
3367
gravity: number,
3468
xOffset: number,
3569
yOffset: number,
3670
): void;
37-
// Toast duration constants
71+
72+
/**
73+
* Indicates a short duration on the screen.
74+
*
75+
* Value: 2000 milliseconds (2 seconds).
76+
*/
3877
SHORT: number;
78+
79+
/**
80+
* Indicates a long duration on the screen.
81+
*
82+
* Value: 3500 milliseconds (3.5 seconds).
83+
*/
3984
LONG: number;
40-
// Toast gravity constants
85+
86+
/**
87+
* Indicates that the toast message should appear at the top of the screen.
88+
*
89+
* **Note**: On Android R or later, this may not have any visible effect.
90+
*/
4191
TOP: number;
92+
93+
/**
94+
* Indicates that the toast message should appear at the bottom of the screen.
95+
*
96+
* **Note**: On Android R or later, this may not have any visible effect.
97+
*/
4298
BOTTOM: number;
99+
100+
/**
101+
* Indicates that the toast message should appear at the center of the screen.
102+
*
103+
* **Note**: On Android R or later, this may not have any visible effect.
104+
*/
43105
CENTER: number;
44106
}
45107

0 commit comments

Comments
 (0)