Skip to main content

🌍 Global Styles Settings

🎨 Default styles settings​

In the default styles settings, we can pass the config that affects all the notifications used in the app. We divide them into:

NameTypeDefaultDescription
darkModeBooleanfalseIf set to true, it enables the dark mode for the notification layout
globalConfigObject-Inside this object, you can pass the configuration for all notifications used in the app (or the parts wrapped with the NotificationProvider)
successConfigObject-Inside this object, you can pass the configuration for all success type notifications used in the app (or parts wrapped with the NotificationProvider). Here, all params set for the success notifications overwrite the same params set in globalConfig
errorConfigObject-Inside this object, you can pass the configuration for all error type notifications used in the app (or parts wrapped with the NotificationProvider). Here, all params set for the error notifications here overwrite the same params set in globalConfig
warningConfigObject-Inside this object, you can pass the configuration for all warning type notifications used in the app (or parts wrapped with the NotificationProvider). Here, all params set for the warning notifications here overwrite the same params set in globalConfig
infoConfigObject-Inside this object, you can pass the configuration for all info type notifications used in the app (or parts wrapped with the NotificationProvider). Here, all params set for the info notifications here overwrites the same params set in globalConfig

const { useNotifications, NotificationsProvider } = createNotifications({
defaultStylesSettings: {
darkMode: true,
globalConfig: {},
successConfig: {},
errorConfig: {},
warningConfig: {},
infoConfig: {},
},
})

Like we said above - in the config descriptions, globalConfig even if is set can be overwritten by the config of the different notifications types (successConfig / errorConfig / warningConfig / infoConfig). You can find examples explaining it below, but first, let's find out what exactly, can we set in config objects.


⚙ī¸ Style config object​

All five configs:

  • globalConfig
  • successConfig
  • errorConfig
  • warningConfig
  • infoConfig

are the objects with the same properties.

We can set there:

NameTypeDefaultDescription
titleSizeNumber16Set font size for the notification
titleFamilyNumberios: 'San Francisco', android: 'Roboto'Set font family for the notification title
titleWeightNumber600Set font weight for the notification title
titleColorString'#505050' (darkMode - false) / '#FAFAFA' (darkMode - true)Set font color for the notification title
descriptionSizeNumber14Set font size for the notification description
descriptionFamilyNumberios: 'San Francisco', android: 'Roboto'Set font family for the notification description
descriptionWeightNumber400Set font weight for the notification description
descriptionColorString'#505050' (darkMode - false) / '#FAFAFA' (darkMode - true)Set font color for the notification description
bgColorString'#FFFFFF' (darkMode - false) / '#2D2D2D' (darkMode - true)Set background color for the notification
borderType'border' / 'accent' / 'no-border''border'Set type of border for the notification (EXAMPLES)
accentColorString'#00EA33' (success type) / '#FC6060' (error type) / '#8CACFF' (warning type) / '#FFD37D' (info type)Set accent color for the notification. The color of the border or the left side accent line
borderRadiusNumber14Set border radius for the notification container
borderWidthNumber1Set border width for the notification container
multilineNumber1Set number of visible lines for the notification description
defaultIconType'color' / 'monochromatic' / 'no-icon''color'This props works only with default icons. If you set your own icon it has no effect. (EXAMPLES)
leftIconSourceImageSourcePropType / JSX.Element-Set custom left icon for the notification (in png) or as custom component. For example. require(../assets/icon.png) / <CustomIcon name="cross"/>

​

đŸ”ŗ Border types examples​

  • 'border'

Border

  • 'accent'

Accent

  • 'no-border'

No-border

​

đŸĩī¸ Default icon type examples​

  • 'color'

Color

  • 'monochromatic'

Monochromatic

  • 'monochromatic' (dark mode)

Monochromatic-darkMode

  • 'no-icon'

No-border

​

🏞ī¸ Global styles setting examples​

Let's start with the basic notification settings with some global style.


🌐 globalConfig​

import React from 'react'
import { SafeAreaView, Text } from 'react-native'
import { createNotifications } from 'react-native-notificated'
import { styles } from './styles'

const { useNotifications, NotificationsProvider } = createNotifications({
defaultStylesSettings: {
globalConfig: {
titleSize: 20,
titleColor: '#4B0082',
descriptionSize: 12,
descriptionColor: '#4B0082',
bgColor: '#FFFFF0',
borderType: 'accent',
borderRadius: 25,
accentColor: '#B0E0E6',
borderWidth: 3,
multiline: 5,
leftIconSource: require('../assets/custom-icon.png'),
},
},
})

export const GlobalConfigExamples = () => {
const { notify } = useNotifications()

return (
<SafeAreaView style={styles.container}>
<NotificationsProvider />
<Text
onPress={() =>
notify('error', {
params: {
description: 'This is where the toast text goes. ',
title: 'Error',
},
})
}>
Emit error
</Text>
</SafeAreaView>
)
}

The effect is visible below:

No-border

In globalConfig above, we have overwritten all the default values.

That means that doesn't matter now if we use error or info notification. All will now look the same. That is what globalConfig does. It overwrites properties for all notifications. If we set there only borderRadius property for some value, then only borderRadius would be set globally. Default values of all other properties would stay untouched:

import React from 'react'
import { SafeAreaView, Text } from 'react-native'
import { createNotifications } from 'react-native-notificated'
import { styles } from './styles'

const { useNotifications, NotificationsProvider } = createNotifications({
defaultStylesSettings: {
globalConfig: {
borderRadius: 50,
},
},
})

export const GlobalConfigExamples = () => {
const { notify } = useNotifications()

return (
<SafeAreaView style={styles.container}>
<NotificationsProvider />
<Text
onPress={() =>
notify('error', {
params: {
description: 'This is where the toast text goes. ',
title: 'Error',
},
})
}>
Emit error
</Text>
<Text
onPress={() =>
notify('success', {
params: {
description: 'This is where the toast text goes. ',
title: 'Success',
},
})
}>
Emit success
</Text>
</SafeAreaView>
)
}

No-border No-border

Both notifications - error and success - have their default settings. Only borderRadius has been changed for both of them because we did it in globalConfig.

​

ℹī¸ successConfig / errorConfig / warningConfig / infoConfig​

Those settings work the same as globalConfig but for different notification types.
In other words, we can set configuration for ALL errors, ALL info, etc.

In addition successConfig / errorConfig / warningConfig / infoConfig are overwriting properties set in globalConfig.
So if we set borderRadius in globalConfig for 50 as we did in the example above, and we will overwrite it in the successConfig for 10, then borderRadius for ALL the SUCCESS notifications will be set for 10, but for ALL OTHER it will be still 50.

import React from 'react'
import { SafeAreaView, Text } from 'react-native'
import { createNotifications } from 'react-native-notificated'
import { styles } from './styles'

const { useNotifications, NotificationsProvider } = createNotifications({
defaultStylesSettings: {
globalConfig: {
borderRadius: 50,
},
successConfig: {
borderRadius: 10,
},
},
})

export const GlobalConfigExamples = () => {
const { notify } = useNotifications()

return (
<SafeAreaView style={styles.container}>
<NotificationsProvider />
<Text
onPress={() =>
notify('error', {
params: {
description: 'This is where the toast text goes. ',
title: 'Error',
},
})
}>
Emit error
</Text>
<Text
onPress={() =>
notify('success', {
params: {
description: 'This is where the toast text goes. ',
title: 'Success',
},
})
}>
Emit success
</Text>
</SafeAreaView>
)
}

No-border No-border

​

So in conclusion -

successConfig / errorConfig / warningConfig / infoConfig overwrites globalConfig, and DEFAULT SETTINGS

globalConfig overwrites DEFAULT SETTINGS

​