react-native-notificare-push
Version:
Notificare Push React Native module.
53 lines (52 loc) • 2.05 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.withNotificarePushAndroidURLSchemes = void 0;
const config_plugins_1 = require("expo/config-plugins");
const XML_1 = require("@expo/config-plugins/build/utils/XML");
const path_1 = require("path");
const plugin_1 = require("react-native-notificare/lib/plugin");
const NOTIFICATION_SCHEMES_RESOURCE = 'notificare_notification_url_schemes';
const withURLSchemes = (config, props) => {
const schemes = props?.android?.urlSchemes;
if (!schemes) {
return config;
}
return (0, config_plugins_1.withDangerousMod)(config, [
'android',
async (newConfig) => {
await createURLSchemesResource(schemes, newConfig.modRequest.projectRoot);
return newConfig;
},
]);
};
const withURLSchemesMetaData = (config, props) => {
const metaDataOptions = [
{
enabled: !!props?.android?.urlSchemes,
metaData: {
$: {
'android:name': 're.notifica.push.ui.notification_url_schemes',
'android:resource': `@array/${NOTIFICATION_SCHEMES_RESOURCE}`,
},
},
},
];
return (0, plugin_1.processManifestMetaDataOptions)(config, metaDataOptions);
};
async function createURLSchemesResource(schemes, projectRoot) {
const xml = await (0, XML_1.parseXMLAsync)(`
<resources>
<string-array name="${NOTIFICATION_SCHEMES_RESOURCE}">
${schemes.map((scheme) => `\n<item>${scheme}</item>`).join('')}
</string-array>
</resources>
`);
const path = (0, path_1.resolve)(projectRoot, plugin_1.RESOURCE_ROOT_PATH + '/values', NOTIFICATION_SCHEMES_RESOURCE + '.xml');
await (0, XML_1.writeXMLAsync)({ path, xml });
}
const withNotificarePushAndroidURLSchemes = (config, props) => {
config = withURLSchemes(config, props);
config = withURLSchemesMetaData(config, props);
return config;
};
exports.withNotificarePushAndroidURLSchemes = withNotificarePushAndroidURLSchemes;
;