ToastAndroid

它揭示了如何将本地 ToastAndroid 模块作为一个 JS 模块。它有一个名为 showText 的函数,其拥有的参数如下所示:

  1. 字符串消息:将文本传递给 toast 的字符串
  2. int 持续期:toast 的持续期。可能是 ToastAndroid.SHORTToastAndroid.LONG

方法

static show(message: string, duration: number)

性质

SHORT: MemberExpression

LONG: MemberExpression

示例

  1. 'use strict';
  2. var React = require('react-native');
  3. var {
  4. StyleSheet,
  5. Text,
  6. ToastAndroid,
  7. TouchableWithoutFeedback
  8. } = React;
  9. var UIExplorerBlock = require('UIExplorerBlock');
  10. var UIExplorerPage = require('UIExplorerPage');
  11. var ToastExample = React.createClass({
  12. statics: {
  13. title: 'Toast Example',
  14. description: 'Toast Example',
  15. },
  16. getInitialState: function() {
  17. return {};
  18. },
  19. render: function() {
  20. return (
  21. <UIExplorerPage title="ToastAndroid">
  22. <UIExplorerBlock title="Simple toast">
  23. <TouchableWithoutFeedback
  24. onPress={() =>
  25. ToastAndroid.show('This is a toast with short duration', ToastAndroid.SHORT)}>
  26. <Text style={styles.text}>Click me.</Text>
  27. </TouchableWithoutFeedback>
  28. </UIExplorerBlock>
  29. <UIExplorerBlock title="Toast with long duration">
  30. <TouchableWithoutFeedback
  31. onPress={() =>
  32. ToastAndroid.show('This is a toast with long duration', ToastAndroid.LONG)}>
  33. <Text style={styles.text}>Click me too.</Text>
  34. </TouchableWithoutFeedback>
  35. </UIExplorerBlock>
  36. </UIExplorerPage>
  37. );
  38. },
  39. });
  40. var styles = StyleSheet.create({
  41. text: {
  42. color: 'black',
  43. },
  44. });
  45. module.exports = ToastExample;