11import * as React from 'react' ;
2- import { Animated , Image , Pressable , StyleSheet , Text , View } from 'react-native' ;
2+ import { Animated , Image , Pressable , StyleProp , StyleSheet , Text , TextStyle , View } from 'react-native' ;
33import { SafeAreaInsetsContext } from 'react-native-safe-area-context' ;
44import ENV , { ACTION , ALERT_TYPE } from '../config/ENV' ;
55import { getImage } from '../service' ;
@@ -10,6 +10,8 @@ export type IConfig = {
1010 // position?: TOAST_POSITION;
1111 title ?: string ;
1212 textBody ?: string ;
13+ titleStyle ?: StyleProp < TextStyle > ;
14+ textBodyStyle ?: StyleProp < TextStyle > ;
1315 autoClose ?: number | boolean ;
1416 onPress ?: ( ) => void ;
1517 onLongPress ?: ( ) => void ;
@@ -19,7 +21,7 @@ export type IConfig = {
1921
2022type IProps = {
2123 isDark : boolean ;
22- config ?: Pick < IConfig , 'autoClose' > ;
24+ config ?: Pick < IConfig , 'autoClose' | 'titleStyle' | 'textBodyStyle' > ;
2325} ;
2426
2527type IState = {
@@ -57,7 +59,8 @@ class Toast extends React.Component<IProps, IState> {
5759 /**
5860 * @type {React.ContextType<typeof SafeAreaInsetsContext> }
5961 */
60- public context ! : React . ContextType < typeof SafeAreaInsetsContext > ;
62+ //@ts -ignore
63+ public context : React . ContextType < typeof SafeAreaInsetsContext > ;
6164
6265 /**
6366 * @type {Animated.Value }
@@ -157,8 +160,13 @@ class Toast extends React.Component<IProps, IState> {
157160 */
158161 private _CardRender = ( ) : JSX . Element => {
159162 const { styles } = this . state ;
163+ const { config } = this . props ;
164+
160165 if ( this . state . config ) {
161- const { type, title, textBody, onPress, onLongPress } = this . state . config ;
166+ const { type, title, textBody, onPress, onLongPress, titleStyle : titleCustomStyle , textBodyStyle : textBodyCustomStyle } = this . state . config ;
167+
168+ const titleStyle = titleCustomStyle || config ?. titleStyle ;
169+ const textBodyStyle = textBodyCustomStyle || config ?. textBodyStyle ;
162170 return (
163171 < Animated . View
164172 onLayout = { ( {
@@ -177,8 +185,8 @@ class Toast extends React.Component<IProps, IState> {
177185 ) }
178186 { /* eslint-disable-next-line react-native/no-inline-styles */ }
179187 < View style = { { overflow : 'hidden' , flex : 1 } } >
180- { title && < Text style = { styles . titleLabel } > { title } </ Text > }
181- { textBody && < Text style = { styles . descLabel } > { textBody } </ Text > }
188+ { title && < Text style = { StyleSheet . flatten ( [ styles . titleLabel , titleStyle ] ) } > { title } </ Text > }
189+ { textBody && < Text style = { StyleSheet . flatten ( [ styles . descLabel , textBodyStyle ] ) } > { textBody } </ Text > }
182190 </ View >
183191 </ Pressable >
184192 </ Animated . View >
0 commit comments