@@ -4,15 +4,9 @@ sidebar_position: 13
44title : Channel Background Customization
55---
66
7- You can implement this customization in your existing app or create a new one by running the following
8-
9- ``` shell
10- npx react-native init MyApp --template stream-chat-react-native-template
11- ```
12-
137## Basic Custom Background
148
15- You can change the background statically by simply wrapping ` MessageList ` and ` MessageInput ` by using the ` ImageBackground ` component.
9+ You can change the background statically by wrapping ` MessageList ` and ` MessageInput ` by using the ` ImageBackground ` component.
1610
1711<img
1812 src = ' https://user-images.githubusercontent.com/25864161/167857632-c0bc9d67-0a84-4cf5-9d75-305e3bcd1f3d.png'
@@ -25,6 +19,14 @@ Also make sure you adjust the `theme` correctly.
2519import { Channel , MessageInput , MessageList , ThemeProvider } from ' stream-chat-react-native' ;
2620import { ImageBackground } from ' react-native' ;
2721
22+ export const theme = {
23+ messageList: {
24+ container: {
25+ backgroundColor: ' transparent' ,
26+ },
27+ },
28+ };
29+
2830const IMAGE_URI =
2931 ' https://images.unsplash.com/photo-1549125764-91425ca48850?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxleHBsb3JlLWZlZWR8NjF8fHxlbnwwfHx8fA%3D%3D&auto=format&fit=crop&w=800&q=60' ;
3032
@@ -43,21 +45,13 @@ const ChannelScreen = ({ channel }) => (
4345 </Channel >
4446 </ThemeProvider >
4547);
46-
47- export const theme = {
48- messageList: {
49- container: {
50- backgroundColor: ' transparent' ,
51- },
52- },
53- };
5448```
5549
5650---
5751
5852## Custom Background With Selection Screen
5953
60- In this step, we will add a button that will navigate to a separate screen, where the user will be able to select his
54+ In this step, we will add a button that will navigate to a separate screen, where the user will be able to select their
6155favorite background image for a specific channel.
6256
6357<table >
@@ -90,7 +84,7 @@ Follow the [installation steps](https://github.com/mrousavy/react-native-mmkv#in
9084We will start by creating our ` ChannelBackgroundView ` component.
9185This component will be in charge of rendering the custom background by retrieving it from our key-value store.
9286We save an object to a key-value store to be scalable and future-proof.
93- You'd might want to add other preferences later, such as dimming value, background color, etc.
87+ You might want to add other preferences later, such as dimming value, background color, etc.
9488
9589``` tsx
9690import type { ViewProps } from ' react-native' ;
@@ -109,14 +103,14 @@ const ChannelBackgroundView = ({
109103 channelId: string ;
110104} & ViewProps ) => {
111105 const [channelPreferences] = useMMKVObject <ChannelPreferences >(channelId );
112- let uri: string | undefined = channelPreferences ?.imageUri || DEFAULT_BACKGROUND_URI ;
106+ const uri = channelPreferences ?.imageUri || DEFAULT_BACKGROUND_URI ;
113107
114108 return <ImageBackground { ... props } source = { { uri }} />;
115109};
116110```
117111
118112We will then use it in our previously built ` ChannelScreen ` .
119- Replace the static ` ImageBackground ` with ` ChannelBackgroundView ` and pass the ` channelId `
113+ Replace the static ` ImageBackground ` with ` ChannelBackgroundView ` and pass the ` channelId ` .
120114
121115``` tsx
122116const ChannelScreen = ({ channel }) => {
@@ -240,7 +234,7 @@ There are alternative approaches to achieve the same goal, for example by saving
240234
241235### Add a configuration button
242236
243- We will add now a button that will take the user from the Channel screen to our new WallpaperOverview screen
237+ We will now add a button that will take the user from the Channel screen to our new WallpaperOverview screen.
244238
245239``` tsx
246240import { useNavigation } from ' @react-navigation/native' ;
@@ -293,7 +287,7 @@ export const theme = {
293287
294288### Optional: Connect all screens by navigation
295289
296- If applicable to your use case, add our screens to a Navigation Stack by doing the following.
290+ If applicable to your use case, add our screens to a Navigation Stack by doing the following:
297291
298292``` tsx
299293import { createNativeStackNavigator } from ' react-native-screens/native-stack' ;
0 commit comments