From d167117963dc2e2ef20e74354601ba13851ed780 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Fri, 15 Dec 2023 17:25:41 -0300 Subject: [PATCH] feat: add vibration when receive in-app notifications --- .../InAppNotification/NotifierComponent.tsx | 13 ++++++++++-- app/i18n/locales/en.json | 4 +++- app/lib/constants/notifications.ts | 1 + app/lib/methods/userPreferences.ts | 1 - .../UserNotificationPreferencesView/index.tsx | 20 +++++++++++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/app/containers/InAppNotification/NotifierComponent.tsx b/app/containers/InAppNotification/NotifierComponent.tsx index 8aa4b351a..4f02bca8a 100644 --- a/app/containers/InAppNotification/NotifierComponent.tsx +++ b/app/containers/InAppNotification/NotifierComponent.tsx @@ -1,18 +1,20 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { StyleSheet, Text, View } from 'react-native'; import Touchable from 'react-native-platform-touchable'; import { connect } from 'react-redux'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; +import * as Haptics from 'expo-haptics'; import Avatar from '../Avatar'; import { CustomIcon } from '../CustomIcon'; import sharedStyles from '../../views/Styles'; -import { themes } from '../../lib/constants'; +import { NOTIFICATION_IN_APP_VIBRATION, themes } from '../../lib/constants'; import { useTheme } from '../../theme'; import { ROW_HEIGHT } from '../RoomItem'; import { goRoom } from '../../lib/methods/helpers/goRoom'; import { IApplicationState, ISubscription, SubscriptionType } from '../../definitions'; import { hideNotification } from '../../lib/methods/helpers/notifications'; +import userPreferences from '../../lib/methods/userPreferences'; export interface INotifierComponent { notification: { @@ -97,6 +99,13 @@ const NotifierComponent = React.memo(({ notification, isMasterDetail }: INotifie hideNotification(); }; + useEffect(() => { + const notificationInAppVibration = userPreferences.getBool(NOTIFICATION_IN_APP_VIBRATION); + if (notificationInAppVibration || notificationInAppVibration === null) { + Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success); + } + }, []); + return ( { + const [inAppVibration, setInAppVibration] = useUserPreferences(NOTIFICATION_IN_APP_VIBRATION, true); const [preferences, setPreferences] = useState({} as INotificationPreferences); const [loading, setLoading] = useState(true); @@ -58,6 +62,10 @@ const UserNotificationPreferencesView = () => { } }; + const toggleInAppVibration = () => { + setInAppVibration(!inAppVibration); + }; + return ( @@ -92,6 +100,18 @@ const UserNotificationPreferencesView = () => { + + + ( + + )} + /> + + +