react-native-toast-message 2.2.0 → 2.3.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 -2
- package/lib/src/components/AnimatedContainer.d.ts +2 -1
- package/lib/src/components/AnimatedContainer.js +3 -2
- package/lib/src/components/BaseToast.js +4 -5
- package/lib/src/hooks/useSlideAnimation.d.ts +3 -2
- package/lib/src/hooks/useSlideAnimation.js +10 -6
- package/lib/src/types/index.d.ts +17 -0
- package/lib/src/useToast.js +3 -1
- package/package.json +1 -1
- package/lib/src/components/Touchable.d.ts +0 -8
- package/lib/src/components/Touchable.js +0 -7
package/lib/src/ToastUI.js
CHANGED
|
@@ -35,8 +35,8 @@ function renderComponent({ data, options, config, isVisible, show, hide }) {
|
|
|
35
35
|
}
|
|
36
36
|
export function ToastUI(props) {
|
|
37
37
|
const { isVisible, options, hide } = props;
|
|
38
|
-
const { position, topOffset, bottomOffset, keyboardOffset, swipeable } = options;
|
|
39
|
-
return (<AnimatedContainer isVisible={isVisible} position={position} topOffset={topOffset} bottomOffset={bottomOffset} keyboardOffset={keyboardOffset} swipeable={swipeable} onHide={hide}>
|
|
38
|
+
const { position, topOffset, bottomOffset, keyboardOffset, avoidKeyboard, swipeable } = options;
|
|
39
|
+
return (<AnimatedContainer isVisible={isVisible} position={position} topOffset={topOffset} bottomOffset={bottomOffset} keyboardOffset={keyboardOffset} avoidKeyboard={avoidKeyboard} swipeable={swipeable} onHide={hide}>
|
|
40
40
|
{renderComponent(props)}
|
|
41
41
|
</AnimatedContainer>);
|
|
42
42
|
}
|
|
@@ -9,6 +9,7 @@ export declare type AnimatedContainerProps = {
|
|
|
9
9
|
swipeable: boolean;
|
|
10
10
|
bottomOffset: number;
|
|
11
11
|
keyboardOffset: number;
|
|
12
|
+
avoidKeyboard: boolean;
|
|
12
13
|
onHide: () => void;
|
|
13
14
|
onRestorePosition?: () => void;
|
|
14
15
|
};
|
|
@@ -20,4 +21,4 @@ export declare type AnimatedContainerProps = {
|
|
|
20
21
|
*/
|
|
21
22
|
export declare function dampingFor(gesture: PanResponderGestureState, position: ToastPosition): number;
|
|
22
23
|
export declare function animatedValueFor(gesture: PanResponderGestureState, position: ToastPosition, damping: number): number;
|
|
23
|
-
export declare function AnimatedContainer({ children, isVisible, position, topOffset, bottomOffset, keyboardOffset, onHide, onRestorePosition, swipeable }: AnimatedContainerProps): JSX.Element;
|
|
24
|
+
export declare function AnimatedContainer({ children, isVisible, position, topOffset, bottomOffset, keyboardOffset, avoidKeyboard, onHide, onRestorePosition, swipeable }: AnimatedContainerProps): JSX.Element;
|
|
@@ -37,7 +37,7 @@ export function animatedValueFor(gesture, position, damping) {
|
|
|
37
37
|
throw new Error(`Toast position: ${position} not implemented`);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
export function AnimatedContainer({ children, isVisible, position, topOffset, bottomOffset, keyboardOffset, onHide, onRestorePosition = noop, swipeable }) {
|
|
40
|
+
export function AnimatedContainer({ children, isVisible, position, topOffset, bottomOffset, keyboardOffset, avoidKeyboard, onHide, onRestorePosition = noop, swipeable }) {
|
|
41
41
|
const { log } = useLogger();
|
|
42
42
|
const { computeViewDimensions, height } = useViewDimensions();
|
|
43
43
|
const { animatedValue, animate, animationStyles } = useSlideAnimation({
|
|
@@ -45,7 +45,8 @@ export function AnimatedContainer({ children, isVisible, position, topOffset, bo
|
|
|
45
45
|
height,
|
|
46
46
|
topOffset,
|
|
47
47
|
bottomOffset,
|
|
48
|
-
keyboardOffset
|
|
48
|
+
keyboardOffset,
|
|
49
|
+
avoidKeyboard
|
|
49
50
|
});
|
|
50
51
|
const onDismiss = React.useCallback(() => {
|
|
51
52
|
log('Swipe, dismissing');
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Text, View } from 'react-native';
|
|
2
|
+
import { Text, View, TouchableOpacity } from 'react-native';
|
|
3
3
|
import { getTestId } from '../utils/test-id';
|
|
4
4
|
import { styles } from './BaseToast.styles';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return (<Touchable testID={getTestId('TouchableContainer')} onPress={onPress} activeOpacity={activeOpacity} style={[styles.base, styles.leadingBorder, style]} {...touchableContainerProps}>
|
|
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}>
|
|
8
7
|
{renderLeadingIcon && renderLeadingIcon()}
|
|
9
8
|
<View testID={getTestId('ContentContainer')} style={[styles.contentContainer, contentContainerStyle]} {...contentContainerProps}>
|
|
10
9
|
{(text1?.length ?? 0) > 0 && (<Text testID={getTestId('Text1')} style={[styles.text1, text1Style]} numberOfLines={text1NumberOfLines} ellipsizeMode='tail' {...text1Props}>
|
|
@@ -15,5 +14,5 @@ export function BaseToast({ text1, text2, onPress, activeOpacity, style, touchab
|
|
|
15
14
|
</Text>)}
|
|
16
15
|
</View>
|
|
17
16
|
{renderTrailingIcon && renderTrailingIcon()}
|
|
18
|
-
</
|
|
17
|
+
</TouchableOpacity>);
|
|
19
18
|
}
|
|
@@ -7,11 +7,12 @@ declare type UseSlideAnimationParams = {
|
|
|
7
7
|
topOffset: number;
|
|
8
8
|
bottomOffset: number;
|
|
9
9
|
keyboardOffset: number;
|
|
10
|
+
avoidKeyboard: boolean;
|
|
10
11
|
};
|
|
11
|
-
export declare function translateYOutputRangeFor({ position, height, topOffset, bottomOffset, keyboardHeight, keyboardOffset }: UseSlideAnimationParams & {
|
|
12
|
+
export declare function translateYOutputRangeFor({ position, height, topOffset, bottomOffset, keyboardHeight, keyboardOffset, avoidKeyboard }: UseSlideAnimationParams & {
|
|
12
13
|
keyboardHeight: number;
|
|
13
14
|
}): number[];
|
|
14
|
-
export declare function useSlideAnimation({ position, height, topOffset, bottomOffset, keyboardOffset }: UseSlideAnimationParams): {
|
|
15
|
+
export declare function useSlideAnimation({ position, height, topOffset, bottomOffset, keyboardOffset, avoidKeyboard }: UseSlideAnimationParams): {
|
|
15
16
|
animatedValue: React.MutableRefObject<Animated.Value>;
|
|
16
17
|
animate: (toValue: number) => void;
|
|
17
18
|
animationStyles: {
|
|
@@ -2,15 +2,18 @@ import React from 'react';
|
|
|
2
2
|
import { Animated, Platform } from 'react-native';
|
|
3
3
|
import { additiveInverseArray } from '../utils/array';
|
|
4
4
|
import { useKeyboard } from './useKeyboard';
|
|
5
|
-
export function translateYOutputRangeFor({ position, height, topOffset, bottomOffset, keyboardHeight, keyboardOffset }) {
|
|
5
|
+
export function translateYOutputRangeFor({ position, height, topOffset, bottomOffset, keyboardHeight, keyboardOffset, avoidKeyboard }) {
|
|
6
6
|
const offset = position === 'bottom' ? bottomOffset : topOffset;
|
|
7
|
-
const keyboardAwareOffset = position === 'bottom' ? keyboardHeight + keyboardOffset : 0;
|
|
7
|
+
const keyboardAwareOffset = position === 'bottom' && avoidKeyboard ? keyboardHeight + keyboardOffset : 0;
|
|
8
8
|
const range = [-(height * 2), Math.max(offset, keyboardAwareOffset)];
|
|
9
9
|
const outputRange = position === 'bottom' ? additiveInverseArray(range) : range;
|
|
10
10
|
return outputRange;
|
|
11
11
|
}
|
|
12
|
-
const useNativeDriver = Platform.select({
|
|
13
|
-
|
|
12
|
+
const useNativeDriver = Platform.select({
|
|
13
|
+
ios: true,
|
|
14
|
+
default: false
|
|
15
|
+
});
|
|
16
|
+
export function useSlideAnimation({ position, height, topOffset, bottomOffset, keyboardOffset, avoidKeyboard }) {
|
|
14
17
|
const animatedValue = React.useRef(new Animated.Value(0));
|
|
15
18
|
const { keyboardHeight } = useKeyboard();
|
|
16
19
|
const animate = React.useCallback((toValue) => {
|
|
@@ -28,9 +31,10 @@ export function useSlideAnimation({ position, height, topOffset, bottomOffset, k
|
|
|
28
31
|
topOffset,
|
|
29
32
|
bottomOffset,
|
|
30
33
|
keyboardHeight,
|
|
31
|
-
keyboardOffset
|
|
34
|
+
keyboardOffset,
|
|
35
|
+
avoidKeyboard
|
|
32
36
|
})
|
|
33
|
-
}), [position, height, topOffset, bottomOffset, keyboardHeight, keyboardOffset]);
|
|
37
|
+
}), [position, height, topOffset, bottomOffset, keyboardHeight, keyboardOffset, avoidKeyboard]);
|
|
34
38
|
const opacity = animatedValue.current.interpolate({
|
|
35
39
|
inputRange: [0, 0.7, 1],
|
|
36
40
|
outputRange: [0, 1, 1]
|
package/lib/src/types/index.d.ts
CHANGED
|
@@ -57,6 +57,12 @@ export declare type ToastOptions = {
|
|
|
57
57
|
* Default value: `10`
|
|
58
58
|
*/
|
|
59
59
|
keyboardOffset?: number;
|
|
60
|
+
/**
|
|
61
|
+
* When `true` offset calculation use KeyboardHeight in position calculation.
|
|
62
|
+
* If you put <Toast /> inside a keyboard aware component and position is 'bottom', you should set this to `false`.
|
|
63
|
+
* Default value: true
|
|
64
|
+
*/
|
|
65
|
+
avoidKeyboard?: boolean;
|
|
60
66
|
/**
|
|
61
67
|
* Called when Toast is shown
|
|
62
68
|
*/
|
|
@@ -145,6 +151,11 @@ export declare type ToastProps = {
|
|
|
145
151
|
* Default value: `4000`
|
|
146
152
|
*/
|
|
147
153
|
visibilityTime?: number;
|
|
154
|
+
/**
|
|
155
|
+
* When `true`, the Toast can be dismissed by a swipe gesture, specified by the `swipeable` prop.
|
|
156
|
+
* Default value: `true`
|
|
157
|
+
*/
|
|
158
|
+
swipeable?: boolean;
|
|
148
159
|
/**
|
|
149
160
|
* When `true`, the visible Toast automatically hides after a certain number of milliseconds,
|
|
150
161
|
* specified by the `visibilityTime` prop.
|
|
@@ -169,6 +180,12 @@ export declare type ToastProps = {
|
|
|
169
180
|
* Default value: `10`
|
|
170
181
|
*/
|
|
171
182
|
keyboardOffset?: number;
|
|
183
|
+
/**
|
|
184
|
+
* When `true` offset calculation use KeyboardHeight in position calculation.
|
|
185
|
+
* If you put <Toast /> inside a keyboard aware component and position is 'bottom', you should set this to `false`.
|
|
186
|
+
* Default value: true
|
|
187
|
+
*/
|
|
188
|
+
avoidKeyboard?: boolean;
|
|
172
189
|
/**
|
|
173
190
|
* Called when any Toast is shown
|
|
174
191
|
*/
|
package/lib/src/useToast.js
CHANGED
|
@@ -18,6 +18,7 @@ export const DEFAULT_OPTIONS = {
|
|
|
18
18
|
topOffset: 40,
|
|
19
19
|
bottomOffset: 40,
|
|
20
20
|
keyboardOffset: 10,
|
|
21
|
+
avoidKeyboard: true,
|
|
21
22
|
onShow: noop,
|
|
22
23
|
onHide: noop,
|
|
23
24
|
onPress: noop,
|
|
@@ -43,7 +44,7 @@ export function useToast({ defaultOptions }) {
|
|
|
43
44
|
}, [clearTimer, log, options]);
|
|
44
45
|
const show = React.useCallback((params) => {
|
|
45
46
|
log(`Showing with params: ${JSON.stringify(params)}`);
|
|
46
|
-
const { text1 = DEFAULT_DATA.text1, text2 = DEFAULT_DATA.text2, type = initialOptions.type, text1Style = initialOptions.text1Style, text2Style = initialOptions.text2Style, position = initialOptions.position, autoHide = initialOptions.autoHide, visibilityTime = initialOptions.visibilityTime, topOffset = initialOptions.topOffset, bottomOffset = initialOptions.bottomOffset, keyboardOffset = initialOptions.keyboardOffset, onShow = initialOptions.onShow, onHide = initialOptions.onHide, onPress = initialOptions.onPress, swipeable = initialOptions.swipeable, props = initialOptions.props } = params;
|
|
47
|
+
const { text1 = DEFAULT_DATA.text1, text2 = DEFAULT_DATA.text2, type = initialOptions.type, text1Style = initialOptions.text1Style, text2Style = initialOptions.text2Style, position = initialOptions.position, autoHide = initialOptions.autoHide, visibilityTime = initialOptions.visibilityTime, topOffset = initialOptions.topOffset, bottomOffset = initialOptions.bottomOffset, keyboardOffset = initialOptions.keyboardOffset, avoidKeyboard = initialOptions.avoidKeyboard, onShow = initialOptions.onShow, onHide = initialOptions.onHide, onPress = initialOptions.onPress, swipeable = initialOptions.swipeable, props = initialOptions.props } = params;
|
|
47
48
|
setData({
|
|
48
49
|
text1,
|
|
49
50
|
text2
|
|
@@ -58,6 +59,7 @@ export function useToast({ defaultOptions }) {
|
|
|
58
59
|
topOffset,
|
|
59
60
|
bottomOffset,
|
|
60
61
|
keyboardOffset,
|
|
62
|
+
avoidKeyboard,
|
|
61
63
|
onShow,
|
|
62
64
|
onHide,
|
|
63
65
|
onPress,
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { TouchableOpacityProps } from 'react-native';
|
|
3
|
-
import { ReactChildren } from '../types';
|
|
4
|
-
declare type TouchableProps = {
|
|
5
|
-
children: ReactChildren;
|
|
6
|
-
} & TouchableOpacityProps;
|
|
7
|
-
export declare function Touchable({ children, activeOpacity, ...rest }: TouchableProps): JSX.Element;
|
|
8
|
-
export {};
|