ToastAndroid.android.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. * @flow strict-local
  9. */
  10. 'use strict';
  11. import NativeToastAndroid from './NativeToastAndroid';
  12. /**
  13. * This exposes the native ToastAndroid module as a JS module. This has a function 'show'
  14. * which takes the following parameters:
  15. *
  16. * 1. String message: A string with the text to toast
  17. * 2. int duration: The duration of the toast. May be ToastAndroid.SHORT or ToastAndroid.LONG
  18. *
  19. * There is also a function `showWithGravity` to specify the layout gravity. May be
  20. * ToastAndroid.TOP, ToastAndroid.BOTTOM, ToastAndroid.CENTER.
  21. *
  22. * The 'showWithGravityAndOffset' function adds on the ability to specify offset
  23. * These offset values will translate to pixels.
  24. *
  25. * Basic usage:
  26. * ```javascript
  27. * ToastAndroid.show('A pikachu appeared nearby !', ToastAndroid.SHORT);
  28. * ToastAndroid.showWithGravity('All Your Base Are Belong To Us', ToastAndroid.SHORT, ToastAndroid.CENTER);
  29. * ToastAndroid.showWithGravityAndOffset('A wild toast appeared!', ToastAndroid.LONG, ToastAndroid.BOTTOM, 25, 50);
  30. * ```
  31. */
  32. const ToastAndroid = {
  33. // Toast duration constants
  34. SHORT: (NativeToastAndroid.getConstants().SHORT: number),
  35. LONG: (NativeToastAndroid.getConstants().LONG: number),
  36. // Toast gravity constants
  37. TOP: (NativeToastAndroid.getConstants().TOP: number),
  38. BOTTOM: (NativeToastAndroid.getConstants().BOTTOM: number),
  39. CENTER: (NativeToastAndroid.getConstants().CENTER: number),
  40. show: function(message: string, duration: number): void {
  41. NativeToastAndroid.show(message, duration);
  42. },
  43. showWithGravity: function(
  44. message: string,
  45. duration: number,
  46. gravity: number,
  47. ): void {
  48. NativeToastAndroid.showWithGravity(message, duration, gravity);
  49. },
  50. showWithGravityAndOffset: function(
  51. message: string,
  52. duration: number,
  53. gravity: number,
  54. xOffset: number,
  55. yOffset: number,
  56. ): void {
  57. NativeToastAndroid.showWithGravityAndOffset(
  58. message,
  59. duration,
  60. gravity,
  61. xOffset,
  62. yOffset,
  63. );
  64. },
  65. };
  66. module.exports = ToastAndroid;