Skip to content

Commit

Permalink
feat: ability to set containerStyle for Notification component
Browse files Browse the repository at this point in the history
  • Loading branch information
seniv committed Feb 18, 2021
1 parent dabab93 commit c8f4ec1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ componentProps.titleStyle | TextStyle | null | The style to us
componentProps.descriptionStyle | TextStyle | null | The style to use for rendering description.
componentProps.imageSource | Object | null | Passed to `<Image />` as `source` param.
componentProps.imageStyle | ImageStyle | null | The style to use for rendering image.
componentProps.containerStyle | ViewStyle | null | The style to use for notification container.
componentProps.ContainerComponent | Component | SafeAreaView | A container of the component. Set it in case you use different SafeAreaView than the standard
componentProps.maxTitleLines | number | null | The maximum number of lines to use for rendering title.
componentProps.maxDescriptionLines | number | null | The maximum number of lines to use for rendering description.
Expand Down
20 changes: 20 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ export default function App() {
})
}
/>
<Button
title="Styled Notification"
onPress={() =>
notifierRef.current?.showNotification({
title: 'Styled Notification',
description: 'Background should be green and title is white!',
componentProps: {
containerStyle: {
backgroundColor: 'green',
},
titleStyle: {
color: 'white',
},
descriptionStyle: {
color: '#fafafa',
},
},
})
}
/>
<Button title="Hide" onPress={() => Notifier.hideNotification()} />
<Button title="Open react-native-modal" onPress={() => setModalVisible(true)} />
{isAndroid && (
Expand Down
6 changes: 3 additions & 3 deletions src/components/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { StyleSheet, View, Text, TextStyle } from 'react-native';
import { StyleSheet, View, Text, TextStyle, StyleProp } from 'react-native';

import SafeContainer from './SafeContainer';

Expand Down Expand Up @@ -58,11 +58,11 @@ export interface AlertComponentProps {

/** The style to use for rendering title
* @default null */
titleStyle?: TextStyle;
titleStyle?: StyleProp<TextStyle>;

/** The style to use for rendering description
* @default null */
descriptionStyle?: TextStyle;
descriptionStyle?: StyleProp<TextStyle>;
}

interface AlertComponentAllProps extends AlertComponentProps {
Expand Down
16 changes: 12 additions & 4 deletions src/components/Notification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
Image,
TextStyle,
ImageStyle,
ViewStyle,
StyleProp,
} from 'react-native';

import SafeContainer from './SafeContainer';
Expand Down Expand Up @@ -75,15 +77,20 @@ export interface NotificationComponentProps {

/** The style to use for rendering title
* @default null */
titleStyle?: TextStyle;
titleStyle?: StyleProp<TextStyle>;

/** The style to use for rendering description
* @default null */
descriptionStyle?: TextStyle;
descriptionStyle?: StyleProp<TextStyle>;

/** The style to use for notification container.
* Might be useful to change background color, shadows, paddings or margins
* @default null */
containerStyle?: StyleProp<ViewStyle>;

/** The style to use for rendering image
* @default null */
imageStyle?: ImageStyle;
imageStyle?: StyleProp<ImageStyle>;
}

interface NotificationComponentAllProps extends NotificationComponentProps {
Expand All @@ -101,11 +108,12 @@ const NotificationComponent: React.FunctionComponent<NotificationComponentAllPro
ContainerComponent,
maxTitleLines,
maxDescriptionLines,
containerStyle,
}) => {
const Container = ContainerComponent ?? SafeContainer;
return (
<Container>
<View style={s.container}>
<View style={[s.container, containerStyle]}>
{!!imageSource && <Image style={[s.image, imageStyle]} source={imageSource} />}
<View style={s.content}>
{!!title && (
Expand Down

0 comments on commit c8f4ec1

Please sign in to comment.