1
1
import * 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' ;
3
3
import { SafeAreaInsetsContext } from 'react-native-safe-area-context' ;
4
4
import ENV , { ACTION , ALERT_TYPE } from '../config/ENV' ;
5
5
import { getImage } from '../service' ;
@@ -10,6 +10,8 @@ export type IConfig = {
10
10
// position?: TOAST_POSITION;
11
11
title ?: string ;
12
12
textBody ?: string ;
13
+ titleStyle ?: StyleProp < TextStyle > ;
14
+ textBodyStyle ?: StyleProp < TextStyle > ;
13
15
autoClose ?: number | boolean ;
14
16
onPress ?: ( ) => void ;
15
17
onLongPress ?: ( ) => void ;
@@ -19,7 +21,7 @@ export type IConfig = {
19
21
20
22
type IProps = {
21
23
isDark : boolean ;
22
- config ?: Pick < IConfig , 'autoClose' > ;
24
+ config ?: Pick < IConfig , 'autoClose' | 'titleStyle' | 'textBodyStyle' > ;
23
25
} ;
24
26
25
27
type IState = {
@@ -57,7 +59,8 @@ class Toast extends React.Component<IProps, IState> {
57
59
/**
58
60
* @type {React.ContextType<typeof SafeAreaInsetsContext> }
59
61
*/
60
- public context ! : React . ContextType < typeof SafeAreaInsetsContext > ;
62
+ //@ts -ignore
63
+ public context : React . ContextType < typeof SafeAreaInsetsContext > ;
61
64
62
65
/**
63
66
* @type {Animated.Value }
@@ -157,8 +160,13 @@ class Toast extends React.Component<IProps, IState> {
157
160
*/
158
161
private _CardRender = ( ) : JSX . Element => {
159
162
const { styles } = this . state ;
163
+ const { config } = this . props ;
164
+
160
165
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 ;
162
170
return (
163
171
< Animated . View
164
172
onLayout = { ( {
@@ -177,8 +185,8 @@ class Toast extends React.Component<IProps, IState> {
177
185
) }
178
186
{ /* eslint-disable-next-line react-native/no-inline-styles */ }
179
187
< 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 > }
182
190
</ View >
183
191
</ Pressable >
184
192
</ Animated . View >
0 commit comments