Skip to main content

Notification Feed

Overview

The LMFeedNotificationFeedScreen is designed to present a list of notifications to the user. Users can pull to refresh the list of notifications, and the screen shows an empty state view when there are no notifications to display. It supports navigating to different parts of the app based on the notification's content.

GitHub Files:

LMFeedNotificationScreen

UI Components

Props

These props allow interaction handling and functional customization for the NotificationFeed component:

Interaction Callbacks

PropertyTypeDescription
onNotificationItemClickedPropFunctionTriggered when a notification item is clicked. Provides LMActivityViewData.

Styling Customizations

The STYLES class allows you to customize the appearance of the Notification Feed. You can set styles using notificationFeedStyle in STYLES.

Customization Table

Style PropTypeDescription
screenHeaderLMHeaderPropsCustomizes the screen header.
backgroundColorstringBackground color of the screen.
unreadBackgroundColorstringBackground color for unread notifications.
activityTextStylesTextStyleStyles for the activity text.
timestampTextStylesTextStyleStyles for the timestamp text.
userImageStylesUserImageStylesStyles for user image, including fallback and size.
activityAttachmentImageStyleLMIconPropsStyle for activity attachment image.
noActivityViewTextstringText displayed when there are no activities.
noActivityViewTextStyleTextStyleStyle for the no activity text.
noActivityViewImageReact.ReactNodeImage shown when there are no activities.
noActivityViewImageStyleImageStyleStyle for the no activity image.
customScreenHeaderReact.ReactNodeCustom component to replace the default screen header.
activityTextComponentFunctionCustom component for rendering activity text.

UserImageStyles

PropertyTypeDescription
fallbackTextStyleTextStyleStyles for fallback text if the image fails to load.
sizenumberSize of the user image.
onTapFunctionCallback when the user image is tapped.
fallbackTextBoxStyleViewStyleStyle for the fallback text container.
profilePictureStyleImageStyleStyle for the user profile picture.

Usage Example

Step 1: Create the Notification Screen Component

  • Define the CustomNotificationScreen component, where you customize callback behavior and apply styling.
import {
LMFeedNotificationFeedScreen,
useNotificationFeedContext,
} from "@likeminds.community/feed-rn-core";

const CustomNotificationScreen = () => {
const { handleActivityOnTap, handleScreenBackPress } =
useNotificationFeedContext();

// customised handleActivityOnTap callback
const customNotificationOnTap = (activity) => {
console.log("do something before notification tap", activity);
handleActivityOnTap(activity);
console.log("do something after notification tap");
};

const notificationFeedStyles = {
backgroundColor: "green",
unreadBackgroundColor: "red",
};

// notification feed screen customisation
if (notificationFeedStyles) {
STYLES.setNotificationFeedStyles(notificationFeedStyles);
}

return (
<LMFeedNotificationFeedScreen
onNotificationItemClickedProp={(activity) =>
customNotificationOnTap(activity)
}
/>
);
};

export default CustomNotificationScreen;

Step 2: Wrap the Screen with Context Provider

  • Create a NotificationScreenWrapper that wraps the CustomNotificationScreen with NotificationFeedContextProvider.
import { NotificationFeedContextProvider } from "@likeminds.community/feed-rn-core";
import CustomNotificationScreen from "<<path_to_NotificationScreen.tsx>>";

const NotificationScreenWrapper = ({ navigation, route }) => {
return (
<NotificationFeedContextProvider navigation={navigation} route={route}>
<CustomNotificationScreen />
</NotificationFeedContextProvider>
);
};

export default NotificationScreenWrapper;

Step 3: Add the Custom Screen in App.tsx

  • In your App.tsx, create a Stack.Navigatorin theNavigationContainerwrapped by LMOverlayProvider.
  • Add NotificationScreenWrapper as a Stack screen in your NavigationContainer.
import {
NOTIFICATION_FEED,
LMOverlayProvider,
STYLES,
} from "@likeminds.community/feed-rn-core";
import NotificationScreenWrapper from "<<path_to_NotificationScreenWrapper.tsx>>";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";

export const App = () => {
const Stack = createNativeStackNavigator();
return (
<LMOverlayProvider
myClient={myClient} // pass in the LMFeedClient created
apiKey={apiKey} // pass in the API Key generated
userName={userName} // pass in the logged-in user's name
userUniqueId={userUniqueID} // pass in the logged-in user's uuid
>
<NavigationContainer ref={navigationRef} independent={true}>
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen
name={NOTIFICATION_FEED}
component={NotificationScreenWrapper}
/>
</Stack.Navigator>
</NavigationContainer>
</LMOverlayProvider>
);
};