|
16 | 16 | *
|
17 | 17 | * There is also a function `showWithGravity` to specify the layout gravity. May be
|
18 | 18 | * 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) |
19 | 26 | */
|
20 | 27 | export interface ToastAndroidStatic {
|
21 | 28 | /**
|
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 |
25 | 33 | */
|
26 | 34 | 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 | + */ |
28 | 48 | showWithGravity(message: string, duration: number, gravity: number): void;
|
29 | 49 |
|
| 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 | + */ |
30 | 64 | showWithGravityAndOffset(
|
31 | 65 | message: string,
|
32 | 66 | duration: number,
|
33 | 67 | gravity: number,
|
34 | 68 | xOffset: number,
|
35 | 69 | yOffset: number,
|
36 | 70 | ): void;
|
37 |
| - // Toast duration constants |
| 71 | + |
| 72 | + /** |
| 73 | + * Indicates a short duration on the screen. |
| 74 | + * |
| 75 | + * Value: 2000 milliseconds (2 seconds). |
| 76 | + */ |
38 | 77 | SHORT: number;
|
| 78 | + |
| 79 | + /** |
| 80 | + * Indicates a long duration on the screen. |
| 81 | + * |
| 82 | + * Value: 3500 milliseconds (3.5 seconds). |
| 83 | + */ |
39 | 84 | 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 | + */ |
41 | 91 | 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 | + */ |
42 | 98 | 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 | + */ |
43 | 105 | CENTER: number;
|
44 | 106 | }
|
45 | 107 |
|
|
0 commit comments