Skip to content

Commit 4fcd727

Browse files
committed
feat: 🎸 custome style for text toast
1 parent d9b1556 commit 4fcd727

File tree

6 files changed

+2745
-2670
lines changed

6 files changed

+2745
-2670
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ expo install react-native-safe-area-context
3838

3939
## Usage
4040

41-
```js
41+
```tsx
4242
import { ALERT_TYPE, Dialog, Root, Toast } from 'react-native-alert-notification';
4343

4444
<Root>
@@ -76,17 +76,17 @@ import { ALERT_TYPE, Dialog, Root, Toast } from 'react-native-alert-notification
7676

7777
A React node that will be most likely wrapping your whole app.
7878

79-
| Name | Description | Require | Default | Type |
80-
| ------------ | -------------------------------------------- | ------- | ------- | ------------------------------------------------- |
81-
| theme | select theme light dark (by default is auto) | | auto | 'light','dark' |
82-
| colors | custom colors | | | [IColors<light>, IColors<dark>] |
83-
| dialogConfig | config dialog box global | | | {closeOnOverlayTap:bool, autoClose:bool / number} |
84-
| toastConfig | config toast global | | | {autoClose:bool / number} |
79+
| Name | Description | Require | Default | Type |
80+
| ------------ | -------------------------------------------- | ------- | ------- | --------------------------------------------------------------------------------------------------- |
81+
| theme | select theme light dark (by default is auto) | | auto | 'light','dark' |
82+
| colors | custom colors | | | [IColors<light>, IColors<dark>] |
83+
| dialogConfig | config dialog box global | | | {closeOnOverlayTap:bool, autoClose:bool / number} |
84+
| toastConfig | config toast global | | | {autoClose:bool / number, titleStyle?: StyleProp<TextStyle> , textBodyStyle?: StyleProp<TextStyle>} |
8585

8686
```ts
8787
type IProps = {
8888
dialogConfig?: Pick<IConfigDialog, 'closeOnOverlayTap' | 'autoClose'>;
89-
toastConfig?: Pick<IConfigToast, 'autoClose'>;
89+
toastConfig?: Pick<IConfigToast, 'autoClose' | 'titleStyle' | 'textBodyStyle'>;
9090
theme?: 'light' | 'dark';
9191
colors?: [IColors, IColors] /** ['light_colors' , 'dark_colors'] */;
9292
};
@@ -147,6 +147,8 @@ type IConfig = {
147147
title?: string;
148148
textBody?: string;
149149
autoClose?: number | boolean;
150+
titleStyle?: StyleProp<TextStyle>;
151+
textBodyStyle?: StyleProp<TextStyle>;
150152
onPress?: () => void;
151153
onLongPress?: () => void;
152154
onShow?: () => void;

example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,4 @@ SPEC CHECKSUMS:
372372

373373
PODFILE CHECKSUM: 738a37364b7402676aa6420460ef88e4c599916d
374374

375-
COCOAPODS: 1.10.1
375+
COCOAPODS: 1.11.3

src/containers/Root.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as React from 'react';
2-
import { useContext, ReactElement } from 'react';
2+
import { ReactElement, useContext } from 'react';
33
import { useColorScheme, View } from 'react-native';
44
import { SafeAreaInsetsContext, SafeAreaProvider } from 'react-native-safe-area-context';
55
import { Dialog, IConfigDialog, IConfigToast, Toast } from '../index';
66
import { Color, IColors } from '../service';
77

88
type IProps = {
99
dialogConfig?: Pick<IConfigDialog, 'closeOnOverlayTap' | 'autoClose'>;
10-
toastConfig?: Pick<IConfigToast, 'autoClose'>;
10+
toastConfig?: Pick<IConfigToast, 'autoClose' | 'titleStyle' | 'textBodyStyle'>;
1111
theme?: 'light' | 'dark';
1212
colors?: [IColors, IColors] /** ['light_colors' , 'dark_colors'] */;
1313
children: ReactElement | ReactElement[];

src/containers/Toast.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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';
33
import { SafeAreaInsetsContext } from 'react-native-safe-area-context';
44
import ENV, { ACTION, ALERT_TYPE } from '../config/ENV';
55
import { 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

2022
type IProps = {
2123
isDark: boolean;
22-
config?: Pick<IConfig, 'autoClose'>;
24+
config?: Pick<IConfig, 'autoClose' | 'titleStyle' | 'textBodyStyle'>;
2325
};
2426

2527
type 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>

src/service/color.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ReactNative, { Platform } from 'react-native';
22
import ENV from '../config/ENV';
33

4-
type IGet = (key: keyof IColors, isDark: boolean) => string | undefined | typeof ReactNative.OpaqueColorValue;
4+
type IGet = (key: keyof IColors, isDark: boolean) => string | undefined | ReactNative.OpaqueColorValue;
55
export type IColors = {
66
label: string;
77
card: string;
@@ -22,7 +22,7 @@ class Color {
2222

2323
const color = ENV.COLORS[key];
2424
const index = !isDark ? 0 : 1;
25-
const i_a = Platform.select<string | undefined | typeof ReactNative.OpaqueColorValue>({
25+
const i_a = Platform.select<string | undefined | ReactNative.OpaqueColorValue>({
2626
ios: ReactNative?.PlatformColor(color.ios) ?? color.default[index],
2727
android: ReactNative?.PlatformColor(color.android[index]) ?? color.default[index],
2828
});

0 commit comments

Comments
 (0)