import React, { useContext } from 'react';
import { Pressable, ScrollView } from 'react-native';
import { PushTriggerOption } from '@sendbird/chat';
import {
Box,
Divider,
Icon,
Switch,
Text,
createStyleSheet,
useUIKitTheme,
} from '@sendbird/uikit-react-native-foundation';
import { useForceUpdate } from '@sendbird/uikit-utils';
import { useLocalization } from '../../../hooks/useContext';
import { GroupChannelNotificationsContexts } from '../module/moduleContext';
const GroupChannelNotificationsView = () => {
const { channel } = useContext(GroupChannelNotificationsContexts.Fragment);
const { STRINGS } = useLocalization();
const { colors } = useUIKitTheme();
const forceUpdate = useForceUpdate();
const turnedOnNotifications = channel.myPushTriggerOption !== PushTriggerOption.OFF;
const turnedOnNotificationsOptionAll = [PushTriggerOption.ALL, PushTriggerOption.DEFAULT].some(
(it) => it === channel.myPushTriggerOption,
);
const turnedOnNotificationsOptionMentionsOnly = channel.myPushTriggerOption === PushTriggerOption.MENTION_ONLY;
const toggleNotificationSwitch = async (val: boolean) => {
if (val) {
await channel.setMyPushTriggerOption(PushTriggerOption.ALL);
} else {
await channel.setMyPushTriggerOption(PushTriggerOption.OFF);
}
forceUpdate();
};
const onPressNotificationsOption = async (option: PushTriggerOption.ALL | PushTriggerOption.MENTION_ONLY) => {
await channel.setMyPushTriggerOption(option);
forceUpdate();
};
return (
}
/>
{turnedOnNotifications && (
<>
onPressNotificationsOption(PushTriggerOption.ALL)}
title={STRINGS.GROUP_CHANNEL_NOTIFICATIONS.MENU_NOTIFICATIONS_OPTION_ALL}
component={
}
/>
onPressNotificationsOption(PushTriggerOption.MENTION_ONLY)}
title={STRINGS.GROUP_CHANNEL_NOTIFICATIONS.MENU_NOTIFICATIONS_OPTION_MENTION_ONLY}
component={
}
/>
>
)}
);
};
type BarProps = {
title: string;
onPress?: () => void;
description?: string;
component: React.ReactNode;
subtitle2?: boolean;
body3?: boolean;
};
const Bar = ({ title, onPress, description, component, subtitle2, body3 }: BarProps) => {
const { colors } = useUIKitTheme();
return (
{title}
{component}
{Boolean(description) && (
{description}
)}
);
};
const styles = createStyleSheet({
container: {
paddingHorizontal: 16,
},
barContainer: {
paddingVertical: 16,
},
titleContainer: {
flexDirection: 'row',
alignItems: 'center',
},
title: {
marginEnd: 8,
},
desc: {
marginTop: 8,
flex: 1,
},
});
export default GroupChannelNotificationsView;