Categories: React Native 教程

React Native:ToastAndroid

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

  1. 字符串消息:将文本传递给 toast 的字符串

  2. int 持续期:toast 的持续期。可能是 ToastAndroid.SHORT  ToastAndroid.LONG

方法

static show(message: string, duration: number)

性质

SHORT: MemberExpression

LONG: MemberExpression

示例

use strict;

var React = require(react-native);
var {
  StyleSheet,
  Text,
  ToastAndroid,
  TouchableWithoutFeedback
} = React;

var UIExplorerBlock = require(UIExplorerBlock);
var UIExplorerPage = require(UIExplorerPage);

var ToastExample = React.createClass({

  statics: {
    title: Toast Example,
    description: Toast Example,
  },

  getInitialState: function() {    return {};
  },

  render: function() {    return (
      <UIExplorerPage title="ToastAndroid">
        <UIExplorerBlock title="Simple toast">
          <TouchableWithoutFeedback
            onPress={() =>
              ToastAndroid.show(This is a toast with short duration, ToastAndroid.SHORT)}>
            <Text style={styles.text}>Click me.</Text>
          </TouchableWithoutFeedback>
        </UIExplorerBlock>
        <UIExplorerBlock title="Toast with long duration">
          <TouchableWithoutFeedback
            onPress={() =>
              ToastAndroid.show(This is a toast with long duration, ToastAndroid.LONG)}>
            <Text style={styles.text}>Click me too.</Text>
          </TouchableWithoutFeedback>
        </UIExplorerBlock>
      </UIExplorerPage>
    );
  },
});

var styles = StyleSheet.create({
  text: {
    color: black,
  },
});

module.exports = ToastExample;

terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

聊聊vue3中的defineProps

在Vue 3中,defineP…

1 周 ago

在 Chrome 中删除、允许和管理 Cookie

您可以选择删除现有 Cooki…

2 周 ago

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

3 周 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

4 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

4 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

1 月 ago