Skip to content

Commit

Permalink
fix: conditionally import RN schedule exact alarm
Browse files Browse the repository at this point in the history
  • Loading branch information
vadymv-mendix committed Jun 26, 2024
1 parent d85698d commit 65e861f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion configs/jsactions/rollup-plugin-collect-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async function getTransitiveDependencies(packagePath, isExternal) {
return Array.from(result);
}

async function copyJsModule(moduleSourcePath, to) {
export async function copyJsModule(moduleSourcePath, to) {
if (existsSync(to)) {
return;
}
Expand Down
14 changes: 13 additions & 1 deletion configs/jsactions/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import command from "rollup-plugin-command";
import { promisify } from "util";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import typescript from "@rollup/plugin-typescript";
import { collectDependencies } from "./rollup-plugin-collect-dependencies";
import { collectDependencies, copyJsModule } from "./rollup-plugin-collect-dependencies";
import { licenseCustomTemplate, copyLicenseFile } from "./rollup-helper";
import { bigJsImportReplacer } from "./rollup-plugin-bigjs-import-replacer";

Expand Down Expand Up @@ -90,6 +90,18 @@ export default async args => {
overwrite: true
}
);

// We dynamically import react-native-schedule-exact-alarm-permission as it works only on Android
// so we need to copy it here as collectDependencies won't detect it.
await copyJsModule(
// require returns a path to commonjs index.js file
join(
dirname(require.resolve("react-native-schedule-exact-alarm-permission")),
"../",
"../"
),
join(outDir, "node_modules", "react-native-schedule-exact-alarm-permission")
);
} else if (args.configProject === "nanoflowcommons") {
// `invariant` is being used silently by @react-native-community/geolocation; it is not listed as a dependency nor peerDependency.
// https://github.dev/react-native-geolocation/react-native-geolocation/blob/1786929f2be581da91082ff857c2393da5e597b3/js/implementation.native.js#L13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ const PERMISSIONS = {
IOS: RNPermissions.IOS
};

async function handleBlockedPermission(permission: string): Promise<void> {
function handleBlockedPermission(permission: string): void {
const permissionName = permission.replace(/_IOS|_ANDROID/, "");

if (permissionName === "SCHEDULE_EXACT_ALARM") {
const RNExactAlarmPermission = await import("react-native-schedule-exact-alarm-permission");
const RNExactAlarmPermission = require("react-native-schedule-exact-alarm-permission");

Check warning on line 33 in packages/jsActions/mobile-resources-native/src/permissions/RequestGenericPermission.ts

View workflow job for this annotation

GitHub Actions / Unit tests

Require statement not part of import statement

Alert.alert("", "Please allow setting alarms and reminders", [
{ text: "Go to alarm settings", onPress: () => RNExactAlarmPermission.getPermission(), isPreferred: true },
Expand Down Expand Up @@ -107,7 +107,7 @@ export async function RequestGenericPermission(
case RESULTS.LIMITED:
return permissionStatus;
case RESULTS.BLOCKED:
await handleBlockedPermission(permission);
handleBlockedPermission(permission);
return RESULTS.BLOCKED;
case RESULTS.DENIED:
return request(mappedPermissionName as Permission);
Expand Down

0 comments on commit 65e861f

Please sign in to comment.