【问题标题】:Toast React Native from 'react-native-toast-notifications'来自 \'react-native-toast-notifications\' 的 Toast React Native
【发布时间】:2022-11-30 21:48:06
【问题描述】:

我使用来自 https://github.com/arnnis/react-native-toast-notifications#readme 的 react-native-toast-notification

我想要定制吐司,如果成功显示绿色吐司,而失败则显示照片上的红色吐司。

我在应用程序中的代码:

import { ToastProvider } from 'react-native-toast-notifications'
<ToastProvider
  placement="bottom"
  duration={5000}
  animationType='slide-in'
  animationDuration={250}
  textStyle={{ fontSize: 20 }}
  offset={50}
  successColor="green"
  normalColor="red"
  offsetTop={30}
  offsetBottom={40}
  swipeEnabled={true}
  renderType={{
    custom_type: (toast) => (
      <View style={{ padding: 15 }}>
        <Text>{toast.message}</Text>
      </View>
    )
  }}>

我在屏幕上的代码:

import { useToast } from "react-native-toast-notifications";

 const onSubmit = (data: IEventPasscode) => {
dispatch(
  eventEnterPasscode({
    body: data,
    onSuccess: () => { 
    toast.show("Hello World"), {
        type: "success",
      },
    onFailure: () => {
      return;
    },
  }),
);

};

这是结果。

【问题讨论】:

    标签: reactjs react-native toast react-native-tools


    【解决方案1】:

    我在你的代码中发现了一个错误,你应该通过 type:success 这样:

    toast.show("Hello World",{type:"success"})
    

    【讨论】:

    • 谢谢,不过颜色还是深灰色。。。
    猜你喜欢
    • 1970-01-01
    • 2019-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多