Skip to content

Commit 65e861f

Browse files
committed
fix: conditionally import RN schedule exact alarm
1 parent d85698d commit 65e861f

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

configs/jsactions/rollup-plugin-collect-dependencies.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ async function getTransitiveDependencies(packagePath, isExternal) {
166166
return Array.from(result);
167167
}
168168

169-
async function copyJsModule(moduleSourcePath, to) {
169+
export async function copyJsModule(moduleSourcePath, to) {
170170
if (existsSync(to)) {
171171
return;
172172
}

configs/jsactions/rollup.config.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import command from "rollup-plugin-command";
1010
import { promisify } from "util";
1111
import { nodeResolve } from "@rollup/plugin-node-resolve";
1212
import typescript from "@rollup/plugin-typescript";
13-
import { collectDependencies } from "./rollup-plugin-collect-dependencies";
13+
import { collectDependencies, copyJsModule } from "./rollup-plugin-collect-dependencies";
1414
import { licenseCustomTemplate, copyLicenseFile } from "./rollup-helper";
1515
import { bigJsImportReplacer } from "./rollup-plugin-bigjs-import-replacer";
1616

@@ -90,6 +90,18 @@ export default async args => {
9090
overwrite: true
9191
}
9292
);
93+
94+
// We dynamically import react-native-schedule-exact-alarm-permission as it works only on Android
95+
// so we need to copy it here as collectDependencies won't detect it.
96+
await copyJsModule(
97+
// require returns a path to commonjs index.js file
98+
join(
99+
dirname(require.resolve("react-native-schedule-exact-alarm-permission")),
100+
"../",
101+
"../"
102+
),
103+
join(outDir, "node_modules", "react-native-schedule-exact-alarm-permission")
104+
);
93105
} else if (args.configProject === "nanoflowcommons") {
94106
// `invariant` is being used silently by @react-native-community/geolocation; it is not listed as a dependency nor peerDependency.
95107
// https://github.dev/react-native-geolocation/react-native-geolocation/blob/1786929f2be581da91082ff857c2393da5e597b3/js/implementation.native.js#L13

packages/jsActions/mobile-resources-native/src/permissions/RequestGenericPermission.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ const PERMISSIONS = {
2626
IOS: RNPermissions.IOS
2727
};
2828

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

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

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

0 commit comments

Comments
 (0)