在我的例子中,我试图改变"toast“的风格,但由于某种原因,它对我不起作用,我不明白为什么,因为这完全是根据他们的例子。
import Toast, { BaseToast } from 'react-native-toast-message';
export default function FOAM (props) {
const toastConfig = {
success: ({ text1, ...rest }) => (
<BaseToast
{...rest}
style={{ borderLeftColor: 'pink' }}
contentContainerStyle={{ paddingHorizontal: 15 }}
text1Style={{
fontSize: 15,
fontWeight: 'semibold'
}}
text1={'TIME UPDATE'}
text2={null}
/>
)
};
return (
<TouchableOpacity
onPress={() => {
<Toast config={toastConfig} ref={(ref) => Toast.setRef(ref)} />
}
</TouchableOpacity>
);
}发布于 2021-05-17 13:44:56
下面是我如何在typescript中为react-native-toast-message定制字体大小:
toastConfig.tsx
import React from 'react';
import theme from 'assets/styles/theme';
import Toast, {AnyObject, BaseToastProps} from 'react-native-toast-message';
import SuccessToast from 'react-native-toast-message/src/components/success';
import ErrorToast from 'react-native-toast-message/src/components/error';
import InfoToast from 'react-native-toast-message/src/components/info';
const renderToast = (Component: React.FC<BaseToastProps>) => (
props: BaseToastProps,
) => (
<Component
text1Style={{fontSize: theme.font.size.md}}
text2Style={{fontSize: theme.font.size.sm}}
onTrailingIconPress={() => Toast.hide()}
{...props}
/>
);
const toastConfig: AnyObject = {
success: renderToast(SuccessToast as React.FC<BaseToastProps>),
error: renderToast(ErrorToast as React.FC<BaseToastProps>),
info: renderToast(InfoToast as React.FC<BaseToastProps>),
};
export default toastConfig;react-native-toast-message.d.ts
declare module 'react-native-toast-message/src/components/success' {}
declare module 'react-native-toast-message/src/components/info' {}
declare module 'react-native-toast-message/src/components/error' {}Root.tsx
const Root = () => (
<>
<Toast config={toastConfig} ref={ref => Toast.setConfig(ref)} />
</>
);https://stackoverflow.com/questions/66795419
复制相似问题