react-native - React Native 多行 Toast 消息

标签 react-native toast

美好的一天。

我想在 React Native APP 中添加多行 toast 消息。但是,它总是在第 2 行被切断。

这是我的代码:

let errString = errors.join("\n");
alerts(errString);

const alerts = (data) => {
  Toast.show({
    topOffset: 100,
    type: "error",
    text1: "ERROR",
    text2: `${data}`,
    visibilityTime: 500,
  });
};

在消息上它会像这样切断:

A long first message
Another long second message...

不显示我的第 3 条消息。

最佳答案

在你的 toast 配置中传递这些配置:

import Toast, {BaseToast, ErrorToast} from 'react-native-toast-message';

const toastConfig = {
  success: (props) => (
    <BaseToast
      {...props}
      style={styles.style}
      contentContainerStyle={styles.contentContainerStyle}
      text1Style={styles.text1Style}
      text1NumberOfLines={2}
      text2Style={styles.text2Style}
      text2NumberOfLines={2}
    />
  ),
  error: (props) => (
    <ErrorToast
      {...props}
      style={[styles.style, styles.errorStyle]}
      contentContainerStyle={styles.contentContainerStyle}
      text1Style={styles.text1Style}
      text1NumberOfLines={2}
      text2Style={styles.text2Style}
      text2NumberOfLines={2}
    />
  ),
};
<Toast config={toastConfig} ref={(ref) => Toast.setRef(ref)} />

检查 this link进行完全定制。

关于react-native - React Native 多行 Toast 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67294032/

相关文章:

jsp - Struts2 和 jsp 表单使用 jquery ajax post 提交并得到类似 toast 的消息,该消息来了又消失?

ios - 警告 - 未知调用 : "relay:check" in react-native iOS app

android - 单击小部件时如何呈现 toast ?

android - 显示 toast 时出错

c# - Toast 通知和地理围栏 Windows Phone 8.1

android - Toast 不显示字段值

reactjs - 为什么组件中的 React Native 函数没有 "function"关键字?

javascript - 带有选项列表的 OnLongPress 弹出窗口

javascript - 构建 JavaScript 包失败。无法读取 react native 模块 traverseDependencies.js 上未定义的属性 'reduce'

android - 单击登录按钮后 react native 发布签名的 apk 文件崩溃