Taro 解决微信提供的toast 只能显示两行的问题

通常在Taro中我们提示语基本都采用

showToast({ title: '提示语', icon: 'none' });

但在开发微信小程序中,避免不了一些功能提示语过长
再使用showToast,就会出现只展示出前两行的问题,展示不完整,
所以最后自己写了一个toast

import React from 'react';
import Modal from '@/components/Modal/Modal';
import { ModalLevel } from '@/components/Modal/types';
import { Text, View } from '@tarojs/components';
import './index.scss';

const prefix = 'toast';
/**
 * 自定义 - 解决微信提供的toast 只能显示两行的问题
 */
export const Toast = {
  renderToast: (title: string) => {
    const innerClassNames = {
      text: `${prefix}__text`
    };
    return (
      <View className={prefix}>
        <Text className={innerClassNames.text}>{title}</Text>
      </View>
    );
  },
  // FIXME: Toast应与Modal用不同的Sibling,不应该使用Modal直接实现
  show(title: string, duration = 2000) {
    Modal.modal({
      node: this.renderToast(title),
      level: ModalLevel.Market,
      options: {
        maskBgColor: 'transParent'
      }
    });
    setTimeout(() => {
      Modal.destroy();
    }, duration);
  }
};

样式,和微信提示语一致

.toast{
  padding: 20px 20px;
  max-width: 450px;
  background: rgba(0, 0, 0, 0.7);
  border-radius: 20px;
  &__text{
    font-size: 13px * 2;
    color: $line-color;
  }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值