Skip to content

Commit

Permalink
[MOO-1492] Conditionally import RN schedule exact alarm permission (#143
Browse files Browse the repository at this point in the history
)
  • Loading branch information
vadymv-mendix authored Jun 27, 2024
2 parents 5914337 + d3205b4 commit d63c590
Show file tree
Hide file tree
Showing 5 changed files with 20 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
2 changes: 2 additions & 0 deletions packages/jsActions/mobile-resources-native/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

- We have fixed an issue with checking blocked permissions on iOS

## [6.1.0] Native Mobile Resources - 2024-05-28

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
Permission,
PERMISSIONS as RNPermissions
} from "react-native-permissions";
import { getPermission } from "react-native-schedule-exact-alarm-permission";
import { ANDROIDPermissionName, IOSPermissionName } from "../../typings/RequestGenericPermission";

// BEGIN EXTRA CODE
Expand All @@ -31,8 +30,10 @@ function handleBlockedPermission(permission: string): void {
const permissionName = permission.replace(/_IOS|_ANDROID/, "");

if (permissionName === "SCHEDULE_EXACT_ALARM") {
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: () => getPermission(), isPreferred: true },
{ text: "Go to alarm settings", onPress: () => RNExactAlarmPermission.getPermission(), isPreferred: true },
{ text: "Cancel", style: "cancel" }
]);
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/jsActions/nanoflow-actions-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
"eslint": "^7.20.0",
"rollup": "^2.68.0"
}
}
}

0 comments on commit d63c590

Please sign in to comment.