@trycourier/courier-react-native
Version:
Inbox, Push Notifications, and Preferences for React Native
103 lines (102 loc) • 6.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.CourierInboxView = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _InboxAction = require("../models/InboxAction");
var _InboxMessage = require("../models/InboxMessage");
var _Modules = require("../Modules");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const CourierInbox = _Modules.Modules.getNativeComponent('CourierInboxView');
const CourierInboxView = props => {
let onClickInboxMessageAtIndexListener = undefined;
let onLongPressInboxMessageAtIndexListener = undefined;
let onClickInboxActionForMessageAtIndexListener = undefined;
let onScrollInboxListener = undefined;
(0, _react.useEffect)(() => {
return () => {
var _onClickInboxMessageA, _onLongPressInboxMess, _onClickInboxActionFo, _onScrollInboxListene;
(_onClickInboxMessageA = onClickInboxMessageAtIndexListener) === null || _onClickInboxMessageA === void 0 ? void 0 : _onClickInboxMessageA.remove();
(_onLongPressInboxMess = onLongPressInboxMessageAtIndexListener) === null || _onLongPressInboxMess === void 0 ? void 0 : _onLongPressInboxMess.remove();
(_onClickInboxActionFo = onClickInboxActionForMessageAtIndexListener) === null || _onClickInboxActionFo === void 0 ? void 0 : _onClickInboxActionFo.remove();
(_onScrollInboxListene = onScrollInboxListener) === null || _onScrollInboxListene === void 0 ? void 0 : _onScrollInboxListene.remove();
};
}, []);
(0, _react.useEffect)(() => {
var _onClickInboxMessageA2;
(_onClickInboxMessageA2 = onClickInboxMessageAtIndexListener) === null || _onClickInboxMessageA2 === void 0 ? void 0 : _onClickInboxMessageA2.remove();
if (_reactNative.Platform.OS === 'android' && props.onClickInboxMessageAtIndex) {
onClickInboxMessageAtIndexListener = _reactNative.DeviceEventEmitter.addListener('courierClickMessageAtIndex', onClickInboxMessageAtIndex);
}
}, [props.onClickInboxMessageAtIndex]);
const onClickInboxMessageAtIndex = event => {
// Parse the native event data
if (props.onClickInboxMessageAtIndex) {
const index = event["index"];
const message = _InboxMessage.InboxMessage.fromJson(event["message"]);
props.onClickInboxMessageAtIndex(message, index);
}
};
(0, _react.useEffect)(() => {
var _onLongPressInboxMess2;
(_onLongPressInboxMess2 = onLongPressInboxMessageAtIndexListener) === null || _onLongPressInboxMess2 === void 0 ? void 0 : _onLongPressInboxMess2.remove();
if (_reactNative.Platform.OS === 'android' && props.onLongPressInboxMessageAtIndex) {
onLongPressInboxMessageAtIndexListener = _reactNative.DeviceEventEmitter.addListener('courierLongPressMessageAtIndex', onLongPressInboxMessageAtIndex);
}
}, [props.onLongPressInboxMessageAtIndex]);
const onLongPressInboxMessageAtIndex = event => {
// Parse the native event data
if (props.onLongPressInboxMessageAtIndex) {
const index = event["index"];
const message = _InboxMessage.InboxMessage.fromJson(event["message"]);
props.onLongPressInboxMessageAtIndex(message, index);
}
};
(0, _react.useEffect)(() => {
var _onClickInboxActionFo2;
(_onClickInboxActionFo2 = onClickInboxActionForMessageAtIndexListener) === null || _onClickInboxActionFo2 === void 0 ? void 0 : _onClickInboxActionFo2.remove();
if (_reactNative.Platform.OS === 'android' && props.onClickInboxActionForMessageAtIndex) {
onClickInboxActionForMessageAtIndexListener = _reactNative.DeviceEventEmitter.addListener('courierClickActionAtIndex', onClickInboxActionForMessageAtIndex);
}
}, [props.onClickInboxActionForMessageAtIndex]);
const onClickInboxActionForMessageAtIndex = event => {
// Parse the native event data
if (props.onClickInboxActionForMessageAtIndex) {
const index = event["index"];
const action = _InboxAction.InboxAction.fromJson(event["action"]);
const message = _InboxMessage.InboxMessage.fromJson(event["message"]);
props.onClickInboxActionForMessageAtIndex(action, message, index);
}
};
(0, _react.useEffect)(() => {
var _onScrollInboxListene2;
(_onScrollInboxListene2 = onScrollInboxListener) === null || _onScrollInboxListene2 === void 0 ? void 0 : _onScrollInboxListene2.remove();
if (_reactNative.Platform.OS === 'android' && props.onScrollInbox) {
onScrollInboxListener = _reactNative.DeviceEventEmitter.addListener('courierScrollInbox', onScrollInbox);
}
}, [props.onScrollInbox]);
const onScrollInbox = event => {
// Parse the native event data
if (props.onScrollInbox) {
const contentOffset = event["contentOffset"];
props.onScrollInbox(contentOffset["y"], contentOffset["x"]);
}
};
return /*#__PURE__*/_react.default.createElement(CourierInbox, {
canSwipePages: props.canSwipePages ?? false,
theme: props.theme ?? {
light: undefined,
dark: undefined
},
onClickInboxMessageAtIndex: event => onClickInboxMessageAtIndex(event.nativeEvent),
onLongPressInboxMessageAtIndex: event => onLongPressInboxMessageAtIndex(event.nativeEvent),
onClickInboxActionForMessageAtIndex: event => onClickInboxActionForMessageAtIndex(event.nativeEvent),
onScrollInbox: event => onScrollInbox(event.nativeEvent),
style: props.style
});
};
exports.CourierInboxView = CourierInboxView;
//# sourceMappingURL=CourierInboxView.js.map