美好的一天。
我想在 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/