UNPKG

@sendbird/uikit-react-native

Version:

Sendbird UIKit for React Native: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.

125 lines (124 loc) 5.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _reactNative = require("react-native"); var _chat = require("@sendbird/chat"); var _uikitReactNativeFoundation = require("@sendbird/uikit-react-native-foundation"); var _uikitUtils = require("@sendbird/uikit-utils"); var _useContext = require("../../../hooks/useContext"); var _moduleContext = require("../module/moduleContext"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const GroupChannelNotificationsView = () => { const { channel } = (0, _react.useContext)(_moduleContext.GroupChannelNotificationsContexts.Fragment); const { STRINGS } = (0, _useContext.useLocalization)(); const { colors } = (0, _uikitReactNativeFoundation.useUIKitTheme)(); const forceUpdate = (0, _uikitUtils.useForceUpdate)(); const turnedOnNotifications = channel.myPushTriggerOption !== _chat.PushTriggerOption.OFF; const turnedOnNotificationsOptionAll = [_chat.PushTriggerOption.ALL, _chat.PushTriggerOption.DEFAULT].some(it => it === channel.myPushTriggerOption); const turnedOnNotificationsOptionMentionsOnly = channel.myPushTriggerOption === _chat.PushTriggerOption.MENTION_ONLY; const toggleNotificationSwitch = async val => { if (val) { await channel.setMyPushTriggerOption(_chat.PushTriggerOption.ALL); } else { await channel.setMyPushTriggerOption(_chat.PushTriggerOption.OFF); } forceUpdate(); }; const onPressNotificationsOption = async option => { await channel.setMyPushTriggerOption(option); forceUpdate(); }; return /*#__PURE__*/_react.default.createElement(_reactNative.ScrollView, { bounces: false, contentContainerStyle: styles.container }, /*#__PURE__*/_react.default.createElement(Bar, { subtitle2: true, title: STRINGS.GROUP_CHANNEL_NOTIFICATIONS.MENU_NOTIFICATIONS, description: STRINGS.GROUP_CHANNEL_NOTIFICATIONS.MENU_NOTIFICATIONS_DESC, component: /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Switch, { value: turnedOnNotifications, onChangeValue: toggleNotificationSwitch }) }), /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Divider, null), turnedOnNotifications && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(Bar, { body3: true, onPress: () => onPressNotificationsOption(_chat.PushTriggerOption.ALL), title: STRINGS.GROUP_CHANNEL_NOTIFICATIONS.MENU_NOTIFICATIONS_OPTION_ALL, component: /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Icon, { color: turnedOnNotificationsOptionAll ? colors.primary : colors.onBackground03, icon: turnedOnNotificationsOptionAll ? 'radio-on' : 'radio-off', size: 24 }) }), /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Divider, null), /*#__PURE__*/_react.default.createElement(Bar, { body3: true, onPress: () => onPressNotificationsOption(_chat.PushTriggerOption.MENTION_ONLY), title: STRINGS.GROUP_CHANNEL_NOTIFICATIONS.MENU_NOTIFICATIONS_OPTION_MENTION_ONLY, component: /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Icon, { color: turnedOnNotificationsOptionMentionsOnly ? colors.primary : colors.onBackground03, icon: turnedOnNotificationsOptionMentionsOnly ? 'radio-on' : 'radio-off', size: 24 }) }), /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Divider, null))); }; const Bar = ({ title, onPress, description, component, subtitle2, body3 }) => { const { colors } = (0, _uikitReactNativeFoundation.useUIKitTheme)(); return /*#__PURE__*/_react.default.createElement(_reactNative.Pressable, { onPress: onPress, style: styles.barContainer }, /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Box, { style: styles.titleContainer }, /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Box, { flex: 1, alignItems: 'flex-start' }, /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Text, { body3: body3, subtitle2: subtitle2, numberOfLines: 1, color: colors.onBackground01, style: styles.title }, title)), /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Box, null, component)), Boolean(description) && /*#__PURE__*/_react.default.createElement(_uikitReactNativeFoundation.Text, { body3: true, color: colors.onBackground02, style: styles.desc, supportRTLAlign: true }, description)); }; const styles = (0, _uikitReactNativeFoundation.createStyleSheet)({ container: { paddingHorizontal: 16 }, barContainer: { paddingVertical: 16 }, titleContainer: { flexDirection: 'row', alignItems: 'center' }, title: { marginEnd: 8 }, desc: { marginTop: 8, flex: 1 } }); var _default = exports.default = GroupChannelNotificationsView; //# sourceMappingURL=GroupChannelNotificationsView.js.map