react-native-toast-message 2.2.1 → 2.3.1

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.
@@ -1,6 +1,6 @@
1
- /// <reference types="react" />
1
+ import React from 'react';
2
2
  import { ToastProps, ToastShowParams } from './types';
3
- export declare function Toast(props: ToastProps): JSX.Element;
3
+ export declare function Toast(props: ToastProps): React.ReactElement;
4
4
  export declare namespace Toast {
5
5
  var show: (params: ToastShowParams) => void;
6
6
  var hide: (params?: void | undefined) => void;
@@ -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');
@@ -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,9 +2,9 @@ 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;
@@ -13,7 +13,7 @@ const useNativeDriver = Platform.select({
13
13
  ios: true,
14
14
  default: false
15
15
  });
16
- export function useSlideAnimation({ position, height, topOffset, bottomOffset, keyboardOffset }) {
16
+ export function useSlideAnimation({ position, height, topOffset, bottomOffset, keyboardOffset, avoidKeyboard }) {
17
17
  const animatedValue = React.useRef(new Animated.Value(0));
18
18
  const { keyboardHeight } = useKeyboard();
19
19
  const animate = React.useCallback((toValue) => {
@@ -31,9 +31,10 @@ export function useSlideAnimation({ position, height, topOffset, bottomOffset, k
31
31
  topOffset,
32
32
  bottomOffset,
33
33
  keyboardHeight,
34
- keyboardOffset
34
+ keyboardOffset,
35
+ avoidKeyboard
35
36
  })
36
- }), [position, height, topOffset, bottomOffset, keyboardHeight, keyboardOffset]);
37
+ }), [position, height, topOffset, bottomOffset, keyboardHeight, keyboardOffset, avoidKeyboard]);
37
38
  const opacity = animatedValue.current.interpolate({
38
39
  inputRange: [0, 0.7, 1],
39
40
  outputRange: [0, 1, 1]
@@ -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
  */
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-toast-message",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "description": "Toast message component for React Native",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",