ToastAndroid
React Native's ToastAndroid API exposes the Android platform's ToastAndroid module as a JS module. It provides the method show(message, duration)
which takes the following parameters:
- message A string with the text to toast
- duration The duration of the toastβeither
ToastAndroid.SHORT
orToastAndroid.LONG
You can alternatively use showWithGravity(message, duration, gravity)
to specify where the toast appears in the screen's layout. May be ToastAndroid.TOP
, ToastAndroid.BOTTOM
or ToastAndroid.CENTER
.
The 'showWithGravityAndOffset(message, duration, gravity, xOffset, yOffset)' method adds the ability to specify an offset with in pixels.
Imperative hackβ
The ToastAndroid API is imperative, but there is a way to expose a declarative component from it as in this example:
Reference
Methodsβ
show()
β
static show(message, duration)
showWithGravity()
β
static showWithGravity(message, duration, gravity)
showWithGravityAndOffset()
β
static showWithGravityAndOffset(message, duration, gravity, xOffset, yOffset)
Propertiesβ
SHORT
β
Indicates the duration on the screen.
ToastAndroid.SHORT;
LONG
β
Indicates the duration on the screen.
ToastAndroid.LONG;
TOP
β
Indicates the position on the screen.
ToastAndroid.TOP;
BOTTOM
β
Indicates the position on the screen.
ToastAndroid.BOTTOM;
CENTER
β
Indicates the position on the screen.
ToastAndroid.CENTER;