Skip to content

Commit

Permalink
feat: add new "translucentStatusBar" param
Browse files Browse the repository at this point in the history
  • Loading branch information
seniv committed Aug 9, 2021
1 parent 78ec6c2 commit be7498a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ hideOnPress | Boolean | true | Should noti
swipePixelsToClose | Number | 20 | How many pixels user should swipe-up notification to dismiss it
swipeEasing | Easing | null | Animation easing after user finished swiping
swipeAnimationDuration| Number | 200 | How fast should be animation after user finished swiping
translucentStatusBar | Boolean | false | Add additional top padding that equals to `StatusBar.currentHeight`. Android Only.
### `hideNotification`
Expand Down
2 changes: 1 addition & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default function App() {
<Button title="Hide modal" onPress={() => setModalVisible(false)} />
</View>
</Modal>
<NotifierRoot ref={notifierRef} />
<NotifierRoot ref={notifierRef} translucentStatusBar={statusBarTranslucent} />
</>
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Notifier.styles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StyleSheet, Platform } from 'react-native';
import { StyleSheet, Platform, StatusBar } from 'react-native';

export default StyleSheet.create({
container: {
Expand All @@ -12,4 +12,7 @@ export default StyleSheet.create({
top: 0,
left: 0,
},
translucentStatusBarPadding: {
paddingTop: StatusBar.currentHeight ?? 0,
},
});
41 changes: 35 additions & 6 deletions src/Notifier.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import React from 'react';
import { Animated, View, TouchableWithoutFeedback, LayoutChangeEvent } from 'react-native';
import {
Animated,
View,
TouchableWithoutFeedback,
LayoutChangeEvent,
Platform,
} from 'react-native';
import {
PanGestureHandler,
State,
PanGestureHandlerStateChangeEvent,
} from 'react-native-gesture-handler';

import s from './Notifier.styles';
import styles from './Notifier.styles';
import { Notification as NotificationComponent } from './components';
import {
DEFAULT_ANIMATION_DURATION,
Expand Down Expand Up @@ -138,14 +144,23 @@ export class NotifierRoot extends React.PureComponent<ShowNotificationParams, St
return;
}

const { title, description, swipeEnabled, Component, componentProps, ...restParams } = params;
const {
title,
description,
swipeEnabled,
Component,
componentProps,
translucentStatusBar,
...restParams
} = params;

this.setState({
title,
description,
Component: Component ?? NotificationComponent,
swipeEnabled: swipeEnabled ?? DEFAULT_SWIPE_ENABLED,
componentProps: componentProps,
translucentStatusBar,
});

this.showParams = restParams;
Expand Down Expand Up @@ -241,7 +256,14 @@ export class NotifierRoot extends React.PureComponent<ShowNotificationParams, St
}

render() {
const { title, description, swipeEnabled, Component, componentProps } = this.state;
const {
title,
description,
swipeEnabled,
Component,
componentProps,
translucentStatusBar,
} = this.state;

return (
<PanGestureHandler
Expand All @@ -251,14 +273,21 @@ export class NotifierRoot extends React.PureComponent<ShowNotificationParams, St
>
<Animated.View
style={[
s.container,
styles.container,
{
transform: [{ translateY: this.translateYInterpolated }],
},
]}
>
<TouchableWithoutFeedback onPress={this.onPress}>
<View onLayout={this.onLayout}>
<View
onLayout={this.onLayout}
style={
Platform.OS === 'android' && translucentStatusBar
? styles.translucentStatusBarPadding
: undefined
}
>
<Component title={title} description={description} {...componentProps} />
</View>
</TouchableWithoutFeedback>
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ export interface ShowNotificationParams<ComponentType extends ElementType = Elem
/** Determines the order in which notifications are shown. Read more in the [Queue Mode](https://github.com/seniv/react-native-notifier#queue-mode) section.
* @default 'reset' */
queueMode?: QueueMode;

/** Add top padding that equals to `StatusBar.currentHeight` to correctly display notification when status bar is translucent. Android Only.
* @platform Android
* @default false
*/
translucentStatusBar?: boolean;
}

export interface StateInterface {
Expand All @@ -95,6 +101,7 @@ export interface StateInterface {
swipeEnabled: boolean;
Component: ElementType;
componentProps: Record<string, any>;
translucentStatusBar?: boolean;
}

export interface NotifierInterface {
Expand Down

0 comments on commit be7498a

Please sign in to comment.