Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ToastUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function renderComponent({

export function ToastUI(props: ToastUIProps) {
const { isVisible, options, hide } = props;
const { position, topOffset, bottomOffset, keyboardOffset, avoidKeyboard, swipeable } = options;
const { position, topOffset, bottomOffset, keyboardOffset, avoidKeyboard, swipeable, containerStyle } = options;

return (
<AnimatedContainer
Expand All @@ -78,7 +78,8 @@ export function ToastUI(props: ToastUIProps) {
keyboardOffset={keyboardOffset}
avoidKeyboard={avoidKeyboard}
swipeable={swipeable}
onHide={hide}>
onHide={hide}
containerStyle={containerStyle}>
{renderComponent(props)}
</AnimatedContainer>
);
Expand Down
12 changes: 8 additions & 4 deletions src/components/AnimatedContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Animated, Dimensions, PanResponderGestureState } from 'react-native';
import React, { useEffect } from 'react';
import { Animated, Dimensions, PanResponderGestureState, StyleProp, ViewStyle } from 'react-native';

import { useLogger, useGesture } from '../contexts';
import {
Expand All @@ -24,6 +24,7 @@ export type AnimatedContainerProps = {
avoidKeyboard: boolean;
onHide: () => void;
onRestorePosition?: () => void;
containerStyle?: StyleProp<ViewStyle>;
};

/**
Expand Down Expand Up @@ -78,7 +79,8 @@ export function AnimatedContainer({
avoidKeyboard,
onHide,
onRestorePosition = noop,
swipeable
swipeable,
containerStyle
}: AnimatedContainerProps) {
const { log } = useLogger();
const { panning } = useGesture();
Expand Down Expand Up @@ -136,6 +138,8 @@ export function AnimatedContainer({
disable,
});

useEffect(() => { console.log("CUSTOM TOAST LIBRARY LOADED");}, []);

React.useLayoutEffect(() => {
const newAnimationValue = isVisible ? 1 : 0;
animate(newAnimationValue);
Expand All @@ -145,7 +149,7 @@ export function AnimatedContainer({
<Animated.View
testID={getTestId('AnimatedContainer')}
onLayout={computeViewDimensions}
style={[styles.base, styles[position], animationStyles]}
style={[styles.base, styles[position], animationStyles, containerStyle]}
// This container View is never the target of touch events but its subviews can be.
// By doing this, tapping buttons behind the Toast is allowed
pointerEvents='box-none'
Expand Down
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export type ToastOptions = {
* on the Toast instance) that uses the `props` parameter
*/
props?: any;
containerStyle?: StyleProp<ViewStyle>;
};

export type ToastData = {
Expand Down Expand Up @@ -216,4 +217,5 @@ export type ToastProps = {
* Called on any Toast press
*/
onPress?: () => void;
containerStyle?: StyleProp<ViewStyle>;
};
9 changes: 6 additions & 3 deletions src/useToast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export const DEFAULT_OPTIONS: Required<ToastOptions> = {
onShow: noop,
onHide: noop,
onPress: noop,
props: {}
props: {},
containerStyle: null,
};

export type UseToastParams = {
Expand Down Expand Up @@ -88,7 +89,8 @@ export function useToast({ defaultOptions }: UseToastParams) {
onHide = initialOptions.onHide,
onPress = initialOptions.onPress,
swipeable = initialOptions.swipeable,
props = initialOptions.props
props = initialOptions.props,
containerStyle = initialOptions.containerStyle,
} = params;
setData({
text1,
Expand All @@ -110,7 +112,8 @@ export function useToast({ defaultOptions }: UseToastParams) {
onHide,
onPress,
swipeable,
props
props,
containerStyle,
}) as Required<ToastOptions>
);
// TODO: validate input
Expand Down