Skip to content

Commit

Permalink
stickColor prop added to dynamicly update
Browse files Browse the repository at this point in the history
  • Loading branch information
kurucaner committed Jan 31, 2025
1 parent afa51e9 commit b7fce56
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ You can customize the toast notifications in two ways:
| onPress | () => void | undefined | Callback when toast is pressed |
| onClose | () => void | undefined | Callback when toast is dismissed |
| swipeThreshold | number | -55 | Threshold for swipe to dismiss |
| stickColor | string | "#ffcad4" | Color of the bottom indicator stick |

## Types

Expand All @@ -136,6 +137,7 @@ interface NotificationConfig {
onPress?: () => void;
onClose?: () => void;
swipeThreshold?: number;
stickColor?: string;
}

interface ShowNotification {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smooth-push",
"version": "1.4.1",
"version": "1.5.0",
"author": "CK",
"repository": {
"type": "git",
Expand Down
14 changes: 8 additions & 6 deletions src/notification-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface NotificationConfig {
onPress?: () => void;
onClose?: () => void;
swipeThreshold?: number;
stickColor?: string;
}

export interface SmoothPushNotification {
Expand All @@ -31,9 +32,7 @@ export interface SmoothPushNotification {
config?: NotificationConfig;
}

export type ShowNotification = SmoothPushNotification;

let showNotification: (params: ShowNotification) => void;
let showNotification: (params: SmoothPushNotification) => void;
let timeoutId: ReturnType<typeof setTimeout> | null = null;

const INITIAL_POSITION = -180;
Expand Down Expand Up @@ -147,6 +146,7 @@ export const SmoothPushProvider = memo(({ defaultConfig }: SmoothPushProviderPro
offset = 60,
maxWidth = 400,
swipeThreshold = SWIPE_THRESHOLD,
stickColor = "#ffcad4",
onPress,
onClose
} = currentConfig;
Expand Down Expand Up @@ -197,7 +197,7 @@ export const SmoothPushProvider = memo(({ defaultConfig }: SmoothPushProviderPro
onClose?.();
};

showNotification = (params: ShowNotification) => {
showNotification = (params: SmoothPushNotification) => {
isFinished.value = false;

if (timeoutId) {
Expand Down Expand Up @@ -236,6 +236,8 @@ export const SmoothPushProvider = memo(({ defaultConfig }: SmoothPushProviderPro
[position, offset, maxWidth, currentConfig.containerStyle, animatedStyle]
);

const stickStyle = useMemo(() => [styles.stick, { backgroundColor: stickColor }], [stickColor]);

return (
<GestureDetector gesture={gestureHandler}>
<Animated.View style={containerStyle}>
Expand All @@ -244,7 +246,7 @@ export const SmoothPushProvider = memo(({ defaultConfig }: SmoothPushProviderPro
<SmoothPush type={toastType} message={data} textStyle={currentConfig.textStyle} />
</Pressable>
</Animated.View>
<View style={styles.stick} />
<View style={stickStyle} />
</Animated.View>
</GestureDetector>
);
Expand Down Expand Up @@ -335,7 +337,7 @@ const styles = StyleSheet.create({
}
});

export const show = (params: ShowNotification) => {
export const show = (params: SmoothPushNotification) => {
if (showNotification) {
showNotification(params);
}
Expand Down

0 comments on commit b7fce56

Please sign in to comment.