react-native-toast-message 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/src/ToastUI.js +2 -1
- package/lib/src/components/AnimatedContainer.js +2 -2
- package/lib/src/components/BaseToast.d.ts +1 -1
- package/lib/src/components/BaseToast.js +6 -6
- package/lib/src/components/BaseToast.styles.d.ts +14 -6
- package/lib/src/components/BaseToast.styles.js +11 -4
- package/lib/src/hooks/index.d.ts +1 -0
- package/lib/src/hooks/index.js +1 -0
- package/lib/src/hooks/useIsomorphicLayoutEffect.d.ts +2 -0
- package/lib/src/hooks/useIsomorphicLayoutEffect.js +4 -0
- package/lib/src/hooks/usePanResponder.d.ts +1 -0
- package/lib/src/hooks/usePanResponder.js +10 -2
- package/lib/src/types/index.d.ts +2 -0
- package/lib/src/utils/test-id.d.ts +1 -1
- package/lib/src/utils/test-id.js +2 -2
- package/package.json +1 -1
package/lib/src/ToastUI.js
CHANGED
|
@@ -10,7 +10,7 @@ const defaultToastConfig = {
|
|
|
10
10
|
};
|
|
11
11
|
function renderComponent({ data, options, config, isVisible, show, hide }) {
|
|
12
12
|
const { text1, text2 } = data;
|
|
13
|
-
const { type, onPress, text1Style, text2Style, position, props } = options;
|
|
13
|
+
const { type, onPress, text1Style, text2Style, position, visibilityTime, props } = options;
|
|
14
14
|
const toastConfig = {
|
|
15
15
|
...defaultToastConfig,
|
|
16
16
|
...config
|
|
@@ -23,6 +23,7 @@ function renderComponent({ data, options, config, isVisible, show, hide }) {
|
|
|
23
23
|
position,
|
|
24
24
|
type,
|
|
25
25
|
isVisible,
|
|
26
|
+
visibilityTime,
|
|
26
27
|
text1,
|
|
27
28
|
text2,
|
|
28
29
|
text1Style,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Animated, Dimensions } from 'react-native';
|
|
3
3
|
import { useLogger, useGesture } from '../contexts';
|
|
4
|
-
import { usePanResponder, useSlideAnimation, useViewDimensions } from '../hooks';
|
|
4
|
+
import { useIsomorphicLayoutEffect, usePanResponder, useSlideAnimation, useViewDimensions } from '../hooks';
|
|
5
5
|
import { noop } from '../utils/func';
|
|
6
6
|
import { bound } from '../utils/number';
|
|
7
7
|
import { getTestId } from '../utils/test-id';
|
|
@@ -83,7 +83,7 @@ export function AnimatedContainer({ children, isVisible, position, topOffset, bo
|
|
|
83
83
|
onEnd,
|
|
84
84
|
disable,
|
|
85
85
|
});
|
|
86
|
-
|
|
86
|
+
useIsomorphicLayoutEffect(() => {
|
|
87
87
|
const newAnimationValue = isVisible ? 1 : 0;
|
|
88
88
|
animate(newAnimationValue);
|
|
89
89
|
}, [animate, isVisible]);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { BaseToastProps } from '../types';
|
|
3
|
-
export declare function BaseToast({ text1, text2, onPress, activeOpacity, style, touchableContainerProps, contentContainerStyle, contentContainerProps, text1Style, text1NumberOfLines, text1Props, text2Style, text2NumberOfLines, text2Props, renderLeadingIcon, renderTrailingIcon }: BaseToastProps): React.ReactElement;
|
|
3
|
+
export declare function BaseToast({ testID, text1, text2, onPress, activeOpacity, style, touchableContainerProps, contentContainerStyle, contentContainerProps, text1Style, text1NumberOfLines, text1Props, text2Style, text2NumberOfLines, text2Props, renderLeadingIcon, renderTrailingIcon }: BaseToastProps): React.ReactElement;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Text,
|
|
2
|
+
import { Text, TouchableOpacity, View } from 'react-native';
|
|
3
3
|
import { getTestId } from '../utils/test-id';
|
|
4
4
|
import { styles } from './BaseToast.styles';
|
|
5
|
-
export function BaseToast({ text1, text2, onPress, activeOpacity = 1, style, touchableContainerProps, contentContainerStyle, contentContainerProps, text1Style, text1NumberOfLines = 1, text1Props, text2Style, text2NumberOfLines = 1, text2Props, renderLeadingIcon, renderTrailingIcon }) {
|
|
6
|
-
return (<TouchableOpacity testID={getTestId('TouchableContainer')} onPress={onPress} activeOpacity={activeOpacity} style={[styles.base, styles.leadingBorder, style]} {...touchableContainerProps}>
|
|
5
|
+
export function BaseToast({ testID = 'toast', text1, text2, onPress, activeOpacity = 1, style, touchableContainerProps, contentContainerStyle, contentContainerProps, text1Style, text1NumberOfLines = 1, text1Props, text2Style, text2NumberOfLines = 1, text2Props, renderLeadingIcon, renderTrailingIcon }) {
|
|
6
|
+
return (<TouchableOpacity testID={getTestId('TouchableContainer', testID)} onPress={onPress} activeOpacity={activeOpacity} style={[styles.base, styles.leadingBorder, style]} {...touchableContainerProps}>
|
|
7
7
|
{renderLeadingIcon && renderLeadingIcon()}
|
|
8
|
-
<View testID={getTestId('ContentContainer')} style={[styles.contentContainer, contentContainerStyle]} {...contentContainerProps}>
|
|
9
|
-
{(text1?.length ?? 0) > 0 && (<Text testID={getTestId('Text1')} style={[styles.text1, text1Style]} numberOfLines={text1NumberOfLines} ellipsizeMode='tail' {...text1Props}>
|
|
8
|
+
<View testID={getTestId('ContentContainer', testID)} style={[styles.contentContainer, contentContainerStyle]} {...contentContainerProps}>
|
|
9
|
+
{(text1?.length ?? 0) > 0 && (<Text testID={getTestId('Text1', testID)} style={[styles.text1, text1Style]} numberOfLines={text1NumberOfLines} ellipsizeMode='tail' {...text1Props}>
|
|
10
10
|
{text1}
|
|
11
11
|
</Text>)}
|
|
12
|
-
{(text2?.length ?? 0) > 0 && (<Text testID={getTestId('Text2')} style={[styles.text2, text2Style]} numberOfLines={text2NumberOfLines} ellipsizeMode='tail' {...text2Props}>
|
|
12
|
+
{(text2?.length ?? 0) > 0 && (<Text testID={getTestId('Text2', testID)} style={[styles.text2, text2Style]} numberOfLines={text2NumberOfLines} ellipsizeMode='tail' {...text2Props}>
|
|
13
13
|
{text2}
|
|
14
14
|
</Text>)}
|
|
15
15
|
</View>
|
|
@@ -3,18 +3,26 @@ export declare const WIDTH = 340;
|
|
|
3
3
|
export declare const BORDER_RADIUS = 6;
|
|
4
4
|
export declare const styles: {
|
|
5
5
|
base: {
|
|
6
|
+
elevation: number;
|
|
7
|
+
backgroundColor: string;
|
|
8
|
+
boxShadow: string;
|
|
6
9
|
flexDirection: "row";
|
|
7
10
|
height: number;
|
|
8
11
|
width: number;
|
|
9
12
|
borderRadius: number;
|
|
10
|
-
|
|
11
|
-
width: number;
|
|
12
|
-
height: number;
|
|
13
|
-
};
|
|
14
|
-
shadowOpacity: number;
|
|
15
|
-
shadowRadius: number;
|
|
13
|
+
} | {
|
|
16
14
|
elevation: number;
|
|
17
15
|
backgroundColor: string;
|
|
16
|
+
shadowOffset?: {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
} | undefined;
|
|
20
|
+
shadowOpacity?: number | undefined;
|
|
21
|
+
shadowRadius?: number | undefined;
|
|
22
|
+
flexDirection: "row";
|
|
23
|
+
height: number;
|
|
24
|
+
width: number;
|
|
25
|
+
borderRadius: number;
|
|
18
26
|
};
|
|
19
27
|
leadingBorder: {
|
|
20
28
|
borderLeftWidth: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StyleSheet } from 'react-native';
|
|
1
|
+
import { Platform, StyleSheet } from 'react-native';
|
|
2
2
|
export const HEIGHT = 60;
|
|
3
3
|
export const WIDTH = 340;
|
|
4
4
|
export const BORDER_RADIUS = 6;
|
|
@@ -8,9 +8,16 @@ export const styles = StyleSheet.create({
|
|
|
8
8
|
height: HEIGHT,
|
|
9
9
|
width: WIDTH,
|
|
10
10
|
borderRadius: BORDER_RADIUS,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
...Platform.select({
|
|
12
|
+
web: {
|
|
13
|
+
boxShadow: `0px 0px ${BORDER_RADIUS}px rgba(0, 0, 0, 0.1)`
|
|
14
|
+
},
|
|
15
|
+
default: {
|
|
16
|
+
shadowOffset: { width: 0, height: 0 },
|
|
17
|
+
shadowOpacity: 0.1,
|
|
18
|
+
shadowRadius: BORDER_RADIUS
|
|
19
|
+
}
|
|
20
|
+
}),
|
|
14
21
|
elevation: 2,
|
|
15
22
|
backgroundColor: '#FFF'
|
|
16
23
|
},
|
package/lib/src/hooks/index.d.ts
CHANGED
package/lib/src/hooks/index.js
CHANGED
|
@@ -17,4 +17,5 @@ export declare function usePanResponder({ animatedValue, computeNewAnimatedValue
|
|
|
17
17
|
onGrant: () => void;
|
|
18
18
|
onMove: (_event: GestureResponderEvent, gesture: PanResponderGestureState) => void;
|
|
19
19
|
onRelease: (_event: GestureResponderEvent, gesture: PanResponderGestureState) => void;
|
|
20
|
+
onTerminate: () => void;
|
|
20
21
|
};
|
|
@@ -40,18 +40,26 @@ export function usePanResponder({ animatedValue, computeNewAnimatedValueForGestu
|
|
|
40
40
|
onRestore();
|
|
41
41
|
}
|
|
42
42
|
}, [computeNewAnimatedValueForGesture, onEnd, onDismiss, onRestore, disable]);
|
|
43
|
+
const onTerminate = React.useCallback(() => {
|
|
44
|
+
onEnd();
|
|
45
|
+
if (disable)
|
|
46
|
+
return;
|
|
47
|
+
onRestore();
|
|
48
|
+
}, [onEnd, onRestore, disable]);
|
|
43
49
|
const panResponder = React.useMemo(() => PanResponder.create({
|
|
44
50
|
onStartShouldSetPanResponder: startShouldSetPanResponder,
|
|
45
51
|
onPanResponderGrant: onGrant,
|
|
46
52
|
onMoveShouldSetPanResponder: moveShouldSetPanResponder,
|
|
47
53
|
onMoveShouldSetPanResponderCapture: moveShouldSetPanResponder,
|
|
48
54
|
onPanResponderMove: onMove,
|
|
49
|
-
onPanResponderRelease: onRelease
|
|
50
|
-
|
|
55
|
+
onPanResponderRelease: onRelease,
|
|
56
|
+
onPanResponderTerminate: onTerminate
|
|
57
|
+
}), [onMove, onRelease, onTerminate, onGrant]);
|
|
51
58
|
return {
|
|
52
59
|
panResponder,
|
|
53
60
|
onGrant,
|
|
54
61
|
onMove,
|
|
55
62
|
onRelease,
|
|
63
|
+
onTerminate
|
|
56
64
|
};
|
|
57
65
|
}
|
package/lib/src/types/index.d.ts
CHANGED
|
@@ -109,6 +109,7 @@ export declare type ToastData = {
|
|
|
109
109
|
export declare type ToastShowParams = ToastData & ToastOptions;
|
|
110
110
|
export declare type ToastHideParams = void;
|
|
111
111
|
export declare type BaseToastProps = {
|
|
112
|
+
testID?: string;
|
|
112
113
|
text1?: string;
|
|
113
114
|
text2?: string;
|
|
114
115
|
onPress?: () => void;
|
|
@@ -130,6 +131,7 @@ export declare type ToastConfigParams<Props> = {
|
|
|
130
131
|
position: ToastPosition;
|
|
131
132
|
type: ToastType;
|
|
132
133
|
isVisible: boolean;
|
|
134
|
+
visibilityTime: number;
|
|
133
135
|
text1?: string;
|
|
134
136
|
text2?: string;
|
|
135
137
|
text1Style?: StyleProp<TextStyle>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function getTestId(elementName: string): string;
|
|
1
|
+
export declare function getTestId(elementName: string, prefix?: string): string;
|
package/lib/src/utils/test-id.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export function getTestId(elementName) {
|
|
2
|
-
return
|
|
1
|
+
export function getTestId(elementName, prefix = 'toast') {
|
|
2
|
+
return `${prefix}${elementName}`;
|
|
3
3
|
}
|